Fix crash handling, so that we don't try to reinitialize after startup
authorHeikki Linnakangas <[email protected]>
Thu, 5 Feb 2009 16:21:47 +0000 (18:21 +0200)
committerHeikki Linnakangas <[email protected]>
Thu, 5 Feb 2009 16:21:47 +0000 (18:21 +0200)
process crash.

src/backend/postmaster/postmaster.c

index 12e74ab3661fe64fc01fa03b27ed6afcd2005bcf..721d8eae3f9cc57267fea6d2c61e3e9346e44b35 100644 (file)
@@ -225,6 +225,7 @@ static pid_t StartupPID = 0,
 static int     Shutdown = NoShutdown;
 
 static bool FatalError = false; /* T if recovering from backend crash */
+static bool RecoveryError = false; /* T if recovery failed */
 
 /* State of WAL redo */
 #define                        NoRecovery                      0
@@ -2182,10 +2183,12 @@ reaper(SIGNAL_ARGS)
                        }
                        /*
                         * Any unexpected exit (including FATAL exit) of the startup
-                        * process is treated as a crash.
+                        * process is treated as a crash, except that we don't want
+                        * to reinitialize.
                         */
                        if (!EXIT_STATUS_0(exitstatus))
                        {
+                               RecoveryError = true;
                                HandleChildCrash(pid, exitstatus,
                                                                 _("startup process"));
                                continue;
@@ -2197,6 +2200,7 @@ reaper(SIGNAL_ARGS)
                         */
                        if (pmState == PM_RECOVERY || pmState == PM_RECOVERY_CONSISTENT)
                        {
+                               RecoveryError = true;
                                HandleChildCrash(pid, exitstatus,
                                                                 _("startup process"));
                                continue;
@@ -2660,7 +2664,6 @@ PostmasterStateMachine(void)
                         * enough to reset FatalError.
                         */
                        pmState = PM_RECOVERY_CONSISTENT;
-                       FatalError = false;
 
                        /*
                         * Load the flat authorization file into postmaster's cache. The
@@ -2680,15 +2683,14 @@ PostmasterStateMachine(void)
                                 (errmsg("database system is in consistent recovery mode")));
                }
        }
-       if ((pmState == PM_RECOVERY || pmState == PM_RECOVERY_CONSISTENT || pmState == PM_STARTUP) && RecoveryStatus == RecoveryCompleted)
+       if ((pmState == PM_RECOVERY || 
+                pmState == PM_RECOVERY_CONSISTENT ||
+                pmState == PM_STARTUP) &&
+               RecoveryStatus == RecoveryCompleted)
        {
                /*
-                * Startup succeeded - we are done with system startup or
-                * recovery.
-                */
-               FatalError = false;
-
-               /*
+                * Startup succeeded.
+                *
                 * Go to shutdown mode if a shutdown request was pending.
                 */
                if (Shutdown > NoShutdown)
@@ -2879,6 +2881,15 @@ PostmasterStateMachine(void)
                }
        }
 
+       /*
+        * If recovery failed, wait for all non-syslogger children to exit,
+        * and then exit postmaster. We don't try to reinitialize when recovery
+        * fails, because more than likely it will just fail again and we will
+        * keep trying forever.
+        */
+       if (RecoveryError && pmState == PM_NO_CHILDREN)
+               ExitPostmaster(1);              
+
        /*
         * If we need to recover from a crash, wait for all non-syslogger
         * children to exit, then reset shmem and StartupDataBase.