Wait for bgwriter to die after startup process ends in PM_RECOVERY. More
authorHeikki Linnakangas <heikki@enterprisedb.com>
Thu, 29 Jan 2009 18:16:00 +0000 (20:16 +0200)
committerHeikki Linnakangas <heikki@enterprisedb.com>
Thu, 29 Jan 2009 18:16:00 +0000 (20:16 +0200)
needs to be done, but it's a start.

src/backend/postmaster/postmaster.c

index 221c9b2aac39ae20497b43a5ac057fa8110a7eac..127f0f01e028e6babe472313ee0ee63d07276fe7 100644 (file)
@@ -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