]> granicus.if.org Git - postgresql/commitdiff
Fix lastReplayedEndRecPtr calculation when starting from shutdown checkpoint.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 5 Mar 2014 11:27:18 +0000 (13:27 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Wed, 5 Mar 2014 11:57:32 +0000 (13:57 +0200)
When entering crash recovery followed by archive recovery, and the latest
checkpoint is a shutdown checkpoint, and there are no more WAL records to
replay before transitioning from crash to archive recovery, we would not
immediately allow read-only connections in hot standby mode even if we
could. That's because when starting from a shutdown checkpoint, we set
lastReplayedEndRecPtr incorrectly to the record before the checkpoint
record, instead of the checkpoint record itself. We don't run the redo
routine of the shutdown checkpoint record, but starting recovery from it
goes through the same motions, so it should be considered as replayed.

Reported by Kyotaro HORIGUCHI. All versions with hot standby are affected,
so backpatch to 9.0.

src/backend/access/transam/xlog.c

index fa79b502e1e845e966ab83ebb6c788aa91055ee6..9f34f1ec7cf40d7b38e7d60a95aa63b03883eec8 100644 (file)
@@ -6751,11 +6751,15 @@ StartupXLOG(void)
 
                /*
                 * Initialize shared variables for tracking progress of WAL replay,
-                * as if we had just replayed the record before the REDO location.
+                * as if we had just replayed the record before the REDO location
+                * (or the checkpoint record itself, if it's a shutdown checkpoint).
                 */
                SpinLockAcquire(&xlogctl->info_lck);
-               xlogctl->replayEndRecPtr = checkPoint.redo;
-               xlogctl->lastReplayedEndRecPtr = checkPoint.redo;
+               if (XLByteLT(checkPoint.redo, RecPtr))
+                       xlogctl->replayEndRecPtr = checkPoint.redo;
+               else
+                       xlogctl->replayEndRecPtr = EndRecPtr;
+               xlogctl->lastReplayedEndRecPtr = xlogctl->replayEndRecPtr;
                xlogctl->recoveryLastXTime = 0;
                xlogctl->currentChunkStartTime = 0;
                xlogctl->recoveryPause = false;