Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2cd72ba

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 38587d7 commit 2cd72ba

File tree

1 file changed

+8
-4
lines changed
  • src/backend/access/transam

1 file changed

+8
-4
lines changed

src/backend/access/transam/xlog.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5457,13 +5457,17 @@ StartupXLOG(void)
54575457

54585458
/*
54595459
* Initialize shared variables for tracking progress of WAL replay,
5460-
* as if we had just replayed the record before the REDO location.
5460+
* as if we had just replayed the record before the REDO location
5461+
* (or the checkpoint record itself, if it's a shutdown checkpoint).
54615462
*/
54625463
SpinLockAcquire(&xlogctl->info_lck);
5463-
xlogctl->replayEndRecPtr = checkPoint.redo;
5464+
if (checkPoint.redo < RecPtr)
5465+
xlogctl->replayEndRecPtr = checkPoint.redo;
5466+
else
5467+
xlogctl->replayEndRecPtr = EndRecPtr;
54645468
xlogctl->replayEndTLI = ThisTimeLineID;
5465-
xlogctl->lastReplayedEndRecPtr = checkPoint.redo;
5466-
xlogctl->lastReplayedTLI = ThisTimeLineID;
5469+
xlogctl->lastReplayedEndRecPtr = xlogctl->replayEndRecPtr;
5470+
xlogctl->lastReplayedTLI = xlogctl->replayEndTLI;
54675471
xlogctl->recoveryLastXTime = 0;
54685472
xlogctl->currentChunkStartTime = 0;
54695473
xlogctl->recoveryPause = false;

0 commit comments

Comments
 (0)