aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2014-03-05 13:27:18 +0200
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2014-03-05 13:58:14 +0200
commit7552d3d1aba33198141f4953379f819df23988cf (patch)
treeeb0c74945054e2fccbc7ca19addbea41d8b63c97
parenta9eb4924a581282abbb80b26396db08f9fb15f57 (diff)
downloadpostgresql-7552d3d1aba33198141f4953379f819df23988cf.tar.gz
postgresql-7552d3d1aba33198141f4953379f819df23988cf.zip
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.
-rw-r--r--src/backend/access/transam/xlog.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 32e208c7c72..4041ab4051e 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -6508,11 +6508,15 @@ StartupXLOG(void)
/*
* Initialize shared variables for tracking progress of WAL replay,
- * as if we had just replayed the record before the REDO location.
+ * as if we had just replayed the record before the REDO location
+ * (or the checkpoint record itself, if it's a shutdown checkpoint).
*/
SpinLockAcquire(&xlogctl->info_lck);
- xlogctl->replayEndRecPtr = checkPoint.redo;
- xlogctl->lastReplayedEndRecPtr = checkPoint.redo;
+ if (XLByteLT(checkPoint.redo, RecPtr))
+ xlogctl->replayEndRecPtr = checkPoint.redo;
+ else
+ xlogctl->replayEndRecPtr = EndRecPtr;
+ xlogctl->lastReplayedEndRecPtr = xlogctl->replayEndRecPtr;
xlogctl->recoveryLastXTime = 0;
xlogctl->recoveryPause = false;
SpinLockRelease(&xlogctl->info_lck);