#include "postgres.h"
/*
* Main entry point for postmaster process.
*
* argc/argv are the command line arguments, already processed by the
* shell script that starts the postmaster.
*
* You can spin off other threads after this, but the postmaster's main
* processing happens here.
*/
int
PostmasterMain(int argc, char *argv[])
{
// ... 省略其他代码 ...
/*
* Initialize semaphores.
*/
if (InitializeSemaphores(numSemas, semSizes, semaphoreNames) != STATUS_OK)
ereport(FATAL,
(errcode(ERRCODE_INTERNAL_ERROR),
errmsg("could not initialize semaphores")));
/*
* Initialize other subsystems that need to be running before we start
* accepting connections.
*/
// ... 省略其他代码 ...
/*
* Set up signal handlers.
*/
// ... 省略其他代码 ...
/*
* If no data directory was specified, we're done. We didn't want to start
* up, anyway.
*/
if (!data_directory)
return 0;
// ... 省略其他代码 ...
/*
* Main loop:
*/
for (;;)
{
// ... 省略其他代码 ...
}
/*
* Shouldn't get here.
*/
return 0;
}
这个代码实例省略了PostmasterMain函数中的大部分细节,主要展示了信号处理函数的设置和主循环的开始。在实际的PostgreSQL源代码中,会有更多的初始化工作和错误处理。