Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Boot

函数名核心功能关键细节
exec_simple_query执行简单 SQL(单命令)执行 SQL:解析 → 重写 → 优化 → 执行
PostgresMain后端主函数循环处理多命令,关联 MessageContext/row_description_context
BackendRun运行后端逻辑切换内存上下文至 TopMemoryContext
BackendStartup创建后端进程fork_process 创建子进程,失败返回-1
ServerLoop服务器事件循环等待并处理客户端连接
PostmasterMain主进程主循环读取配置,监听连接,管理子进程,PostmasterContext=TopMemoryContext
main程序入口初始化环境,分配 TopMemoryContext,调用 PostmasterMain
main
    PostmasterMain
        InitProcessGlobals()
        CreateDataDirLockFile()   // create postmaster.pid
        ServerLoop
            BackendStartup
                fork_process
                BackendRun
                    PostgresMain(port->database_name, port->user_name);
                        exec_simple_query(query_string);