1. 程式人生 > >Postgresql - 原始碼 - 資料庫啟動 -StartChildProcess

Postgresql - 原始碼 - 資料庫啟動 -StartChildProcess

啟動其他子程序。such as the bgwriter, walwriter, walreceiver, bootstrapper and the shared memory checker code.

 

包括 src/backend/postmaster/postmaster.c 中的

#define StartupDataBase()       StartChildProcess(StartupProcess)

#define StartBackgroundWriter() StartChildProcess(BgWriterProcess)

#define StartCheckpointer()     StartChildProcess(CheckpointerProcess)

#define StartWalWriter()        StartChildProcess(WalWriterProcess)

#define StartWalReceiver()      StartChildProcess(WalReceiverProcess)

 

1. 在資料庫進行檢查(許可權,檔案,資料夾等)之後,會先進行 StartupDataBase(),啟動資料庫程序。

 

2. 隨後,執行ServerLoop() 函式, 其他的子程序會被啟動。(ServerLoop函式具體位置請參考資料庫啟動-backend啟動)

 

函式位置

src/backend/postmaster/postmaster.c StartChildProcess(AuxProcType type) --> AuxiliaryProcessMain

backend/bootstrap/bootstrap.c AuxiliaryProcessMain(int argc, char *argv[]) --> StartupProcessMain

src/backend/postmaster/startup.c StartupProcessMain(void)

 

    if (IsUnderPostmaster)

    {

        const char *statmsg;

 

        switch (MyAuxProcType)

        {

            case StartupProcess:

                statmsg = pgstat_get_backend_desc(B_STARTUP);

                break;

            case BgWriterProcess:

                statmsg = pgstat_get_backend_desc(B_BG_WRITER);

                break;

            case CheckpointerProcess:

                statmsg = pgstat_get_backend_desc(B_CHECKPOINTER);

                break;

            case WalWriterProcess:

                statmsg = pgstat_get_backend_desc(B_WAL_WRITER);

                break;

            case WalReceiverProcess:

                statmsg = pgstat_get_backend_desc(B_WAL_RECEIVER);

                break;

            default:

                statmsg = "??? process";

                break;

        }

 

所有程序啟動完成。