Skip to content

Commit 931dc26

Browse files
committed
Fix lastReplayedEndRecPtr calculation when starting from shutdown checkpoint.
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.
1 parent 03e6423 commit 931dc26

File tree

1 file changed

+7
-3
lines changed
  • src/backend/access/transam

1 file changed

+7
-3
lines changed

src/backend/access/transam/xlog.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6751,11 +6751,15 @@ StartupXLOG(void)
67516751

67526752
/*
67536753
* Initialize shared variables for tracking progress of WAL replay,
6754-
* as if we had just replayed the record before the REDO location.
6754+
* as if we had just replayed the record before the REDO location
6755+
* (or the checkpoint record itself, if it's a shutdown checkpoint).
67556756
*/
67566757
SpinLockAcquire(&xlogctl->info_lck);
6757-
xlogctl->replayEndRecPtr = checkPoint.redo;
6758-
xlogctl->lastReplayedEndRecPtr = checkPoint.redo;
6758+
if (XLByteLT(checkPoint.redo, RecPtr))
6759+
xlogctl->replayEndRecPtr = checkPoint.redo;
6760+
else
6761+
xlogctl->replayEndRecPtr = EndRecPtr;
6762+
xlogctl->lastReplayedEndRecPtr = xlogctl->replayEndRecPtr;
67596763
xlogctl->recoveryLastXTime = 0;
67606764
xlogctl->currentChunkStartTime = 0;
67616765
xlogctl->recoveryPause = false;

0 commit comments

Comments
 (0)