Skip to content

Commit 7552d3d

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 a9eb492 commit 7552d3d

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
@@ -6508,11 +6508,15 @@ StartupXLOG(void)
65086508

65096509
/*
65106510
* Initialize shared variables for tracking progress of WAL replay,
6511-
* as if we had just replayed the record before the REDO location.
6511+
* as if we had just replayed the record before the REDO location
6512+
* (or the checkpoint record itself, if it's a shutdown checkpoint).
65126513
*/
65136514
SpinLockAcquire(&xlogctl->info_lck);
6514-
xlogctl->replayEndRecPtr = checkPoint.redo;
6515-
xlogctl->lastReplayedEndRecPtr = checkPoint.redo;
6515+
if (XLByteLT(checkPoint.redo, RecPtr))
6516+
xlogctl->replayEndRecPtr = checkPoint.redo;
6517+
else
6518+
xlogctl->replayEndRecPtr = EndRecPtr;
6519+
xlogctl->lastReplayedEndRecPtr = xlogctl->replayEndRecPtr;
65166520
xlogctl->recoveryLastXTime = 0;
65176521
xlogctl->recoveryPause = false;
65186522
SpinLockRelease(&xlogctl->info_lck);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy