/*
* PostmasterMain -- Initialize process environment, fork child processes, etc.
*
* argc/argv are the usual main() arguments. Note these are NOT necessarily
* passed directly by the user's shell, they might be from a wrapper script
* created by the makefiles. Use the originalArgs variable if you need to
* find out what the shell command was.
*/
int
PostmasterMain(int argc, char *argv[])
{
// ... 省略前面的代码 ...
/*
* Main loop for postmaster
*/
for (;;)
{
int delay;
if (IsUnderPostmaster)
SendPostmasterSignal(PMSIGNAL_STATE_CHANGE);
/*
* Examine the shared memory exit status, if any. This will cause us
* to exit if we're supposed to shut down.
*/
if (Shutdown)
{
/*
* Note: if we are here, the postmaster didn't start up successfully
* and needs to exit. But check for a pending signal before we
* do so. This might be a SIGQUIT due to a client-side timeout, so
* be careful not to throw away a real signal intent.
*/
if (pending_signals)
sigprocmask(SIG_DISPATCH, NULL, NULL);
/*
* If we are shutting down, but still have a PGDATA directory,
* perform a checkpoint to ensure that all WAL segments are marked
* as saved before we continue to remove data directories and files.
*
* Note: If there is a shutdown in progress, Recovery.c will not
* recognize as a crash, and will not enter recovery when restarting.
* This means that the checkpoint is only performed when the postmaster
* is not running, or the database is running without recovery.
*/
if (FindMyDatabase() >= 0 && !ShutdownWAL())
elog(WARNING, "WAL checkpoint failed during shutdown");
exit(1);
}
/*
* Sleep until something happens. Note we don't wait for the full
* delay time, because a signal or SIGQUIT may interrupt the sleep.
* (Note also that signals interrupt the sleep() call on some
* platforms but not all. Therefore, do not rely on this as the
* sole means of responding to signals in a timely manner.)
*/
delay = PG_SLEEP_DELAY_MS * 1000;
评论已关闭