From 8d912e1bddeee43bbe657ca7ab7ae6154a8ed93b Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Thu, 29 Jan 2009 20:16:00 +0200 Subject: [PATCH] Wait for bgwriter to die after startup process ends in PM_RECOVERY. More needs to be done, but it's a start. --- src/backend/postmaster/postmaster.c | 39 +++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 221c9b2aac..127f0f01e0 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -2128,10 +2128,13 @@ reaper(SIGNAL_ARGS) if (pid == StartupPID) { StartupPID = 0; - Assert(pmState == PM_STARTUP || pmState == PM_RECOVERY); + Assert(pmState != PM_RUN); - /* FATAL exit of startup is treated as catastrophic */ - if (!EXIT_STATUS_0(exitstatus)) + /* + * FATAL exit of startup during PM_STARTUP is treated as + * catastrophic. There is no other processes running yet. + */ + if (!EXIT_STATUS_0(exitstatus) && pmState == PM_STARTUP) { LogChildExit(LOG, _("startup process"), pid, exitstatus); @@ -2139,12 +2142,23 @@ reaper(SIGNAL_ARGS) (errmsg("aborting startup due to startup process failure"))); ExitPostmaster(1); } + /* + * Any other unexpected exit of the startup process (including + * FATAL exit) is treated as a crash. + */ + if (!EXIT_STATUS_0(exitstatus)) + { + HandleChildCrash(pid, exitstatus, + _("startup process")); + continue; + } /* * Startup succeeded - we are done with system startup or * recovery. */ - FatalError = false; + if (pmState == PM_STARTUP) + FatalError = false; /* * Go to shutdown mode if a shutdown request was pending. @@ -2456,6 +2470,18 @@ HandleChildCrash(int pid, int exitstatus, const char *procname) } } + /* Take care of the startup process too */ + if (pid == StartupPID) + StartupPID = 0; + else if (StartupPID != 0 && !FatalError) + { + ereport(DEBUG2, + (errmsg_internal("sending %s to process %d", + (SendStop ? "SIGSTOP" : "SIGQUIT"), + (int) StartupPID))); + signal_child(BgWriterPID, (SendStop ? SIGSTOP : SIGQUIT)); + } + /* Take care of the bgwriter too */ if (pid == BgWriterPID) BgWriterPID = 0; @@ -2528,6 +2554,7 @@ HandleChildCrash(int pid, int exitstatus, const char *procname) FatalError = true; /* We now transit into a state of waiting for children to die */ if (pmState == PM_RUN || + pmState == PM_RECOVERY || pmState == PM_WAIT_BACKUP || pmState == PM_SHUTDOWN) pmState = PM_WAIT_BACKENDS; @@ -3875,9 +3902,11 @@ sigusr1_handler(SIGNAL_ARGS) else { /* - * Startup process has entered recovery + * Startup process has entered recovery. We consider that good + * enough to reset FatalError. */ pmState = PM_RECOVERY; + FatalError = false; /* * Load the flat authorization file into postmaster's cache. The -- 2.39.5