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

Commit af246c3

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 eb93316 commit af246c3

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -6846,13 +6846,17 @@ StartupXLOG(void)
68466846

68476847
/*
68486848
* Initialize shared variables for tracking progress of WAL replay,
6849-
* as if we had just replayed the record before the REDO location.
6849+
* as if we had just replayed the record before the REDO location
6850+
* (or the checkpoint record itself, if it's a shutdown checkpoint).
68506851
*/
68516852
SpinLockAcquire(&xlogctl->info_lck);
6852-
xlogctl->replayEndRecPtr = checkPoint.redo;
6853+
if (checkPoint.redo < RecPtr)
6854+
xlogctl->replayEndRecPtr = checkPoint.redo;
6855+
else
6856+
xlogctl->replayEndRecPtr = EndRecPtr;
68536857
xlogctl->replayEndTLI = ThisTimeLineID;
6854-
xlogctl->lastReplayedEndRecPtr = checkPoint.redo;
6855-
xlogctl->lastReplayedTLI = ThisTimeLineID;
6858+
xlogctl->lastReplayedEndRecPtr = xlogctl->replayEndRecPtr;
6859+
xlogctl->lastReplayedTLI = xlogctl->replayEndTLI;
68566860
xlogctl->recoveryLastXTime = 0;
68576861
xlogctl->currentChunkStartTime = 0;
68586862
xlogctl->recoveryPause = false;

0 commit comments

Comments
 (0)