Fix FatalError handling. Bug pointed out by Fujii-san.
authorHeikki Linnakangas <[email protected]>
Wed, 4 Feb 2009 12:33:28 +0000 (14:33 +0200)
committerHeikki Linnakangas <[email protected]>
Wed, 4 Feb 2009 12:33:28 +0000 (14:33 +0200)
src/backend/access/transam/xlog.c
src/backend/postmaster/postmaster.c

index c01aa9f7fbd05328096f9810756f5ca175eff6e5..7143bf9dee90d68c89c9d56977299ee9c81c9b39 100644 (file)
@@ -6433,7 +6433,8 @@ CreateRestartPoint(int flags)
         * If the last checkpoint record we've replayed is already our last
         * restartpoint, we're done.
         */
-       if (XLByteLE(lastCheckPoint.redo, ControlFile->checkPointCopy.redo))
+       if (XLogRecPtrIsInvalid(lastCheckPointRecPtr) ||
+               XLByteLE(lastCheckPoint.redo, ControlFile->checkPointCopy.redo))
        {
                ereport(DEBUG2,
                                (errmsg("skipping restartpoint, already performed at %X/%X",
index 15fc7ad3d666b16197fd5142d6aca5cb5bc0fd01..12e74ab3661fe64fc01fa03b27ed6afcd2005bcf 100644 (file)
@@ -271,10 +271,10 @@ static int        RecoveryStatus = NoRecovery;
  *
  * Notice that this state variable does not distinguish *why* we entered
  * states later than PM_RUN --- Shutdown and FatalError must be consulted
- * to find that out.  FatalError is never true in PM_RUN state, nor in
- * PM_SHUTDOWN states (because we don't enter those states when trying to
- * recover from a crash).  It can be true in PM_STARTUP state, because we
- * don't clear it until we've successfully recovered.
+ * to find that out.  FatalError is never true in PM_RECOVERY_* or PM_RUN
+ * states, nor in PM_SHUTDOWN states (because we don't enter those states
+ * when trying to recover from a crash).  It can be true in PM_STARTUP state,
+ * because we don't clear it until we've successfully started WAL redo.
  */
 typedef enum
 {
@@ -1783,7 +1783,10 @@ canAcceptConnections(void)
                        return CAC_WAITBACKUP;  /* allow superusers only */
                if (Shutdown > NoShutdown)
                        return CAC_SHUTDOWN;    /* shutdown is pending */
-               if (pmState == PM_STARTUP && !FatalError)
+               if (!FatalError &&
+                       (pmState == PM_STARTUP ||
+                        pmState == PM_RECOVERY ||
+                        pmState == PM_RECOVERY_CONSISTENT))
                        return CAC_STARTUP; /* normal startup */
                return CAC_RECOVERY;    /* else must be crash recovery */
        }
@@ -2617,7 +2620,8 @@ PostmasterStateMachine(void)
 
        if (pmState == PM_STARTUP && RecoveryStatus > NoRecovery)
        {
-               /* Recovery has started */
+               /* WAL redo has started. We're out of reinitialization. */
+               FatalError = false;
 
                /*
                 * Go to shutdown mode if a shutdown request was pending.