Skip to content

Commit 4521cc8

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 43af0e8 commit 4521cc8

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

61806180
/*
61816181
* Initialize shared variables for tracking progress of WAL replay,
6182-
* as if we had just replayed the record before the REDO location.
6182+
* as if we had just replayed the record before the REDO location
6183+
* (or the checkpoint record itself, if it's a shutdown checkpoint).
61836184
*/
61846185
SpinLockAcquire(&xlogctl->info_lck);
6185-
xlogctl->replayEndRecPtr = checkPoint.redo;
6186-
xlogctl->lastReplayedEndRecPtr = checkPoint.redo;
6186+
if (XLByteLT(checkPoint.redo, RecPtr))
6187+
xlogctl->replayEndRecPtr = checkPoint.redo;
6188+
else
6189+
xlogctl->replayEndRecPtr = EndRecPtr;
6190+
xlogctl->lastReplayedEndRecPtr = xlogctl->replayEndRecPtr;
61876191
xlogctl->recoveryLastXTime = 0;
61886192
SpinLockRelease(&xlogctl->info_lck);
61896193

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