diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2011-12-09 14:32:42 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2011-12-09 15:21:12 +0200 |
commit | 9f0d2bdc88630781485a17178e2b50e49ce70040 (patch) | |
tree | b8a85a2c176d85190c67b6533ab750fb0cd57ada | |
parent | 5d8a894e3095b2f602e901c19689f3176bf20543 (diff) | |
download | postgresql-9f0d2bdc88630781485a17178e2b50e49ce70040.tar.gz postgresql-9f0d2bdc88630781485a17178e2b50e49ce70040.zip |
Don't set reachedMinRecoveryPoint during crash recovery. In crash recovery,
we don't reach consistency before replaying all of the WAL. Rename the
variable to reachedConsistency, to make its intention clearer.
In master, that was an active bug because of the recent patch to
immediately PANIC if a reference to a missing page is found in WAL after
reaching consistency, as Tom Lane's test case demonstrated. In 9.1 and 9.0,
the only consequence was a misleading "consistent recovery state reached at
%X/%X" message in the log at the beginning of crash recovery (the database
is not consistent at that point yet). In 8.4, the log message was not
printed in crash recovery, even though there was a similar
reachedMinRecoveryPoint local variable that was also set early. So,
backpatch to 9.1 and 9.0.
-rw-r--r-- | src/backend/access/transam/xlog.c | 21 | ||||
-rw-r--r-- | src/backend/access/transam/xlogutils.c | 2 | ||||
-rw-r--r-- | src/include/access/xlog.h | 2 |
3 files changed, 19 insertions, 6 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 9bec6609921..9d96044cbdc 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -562,7 +562,13 @@ static TimeLineID lastPageTLI = 0; static XLogRecPtr minRecoveryPoint; /* local copy of * ControlFile->minRecoveryPoint */ static bool updateMinRecoveryPoint = true; -bool reachedMinRecoveryPoint = false; + +/* + * Have we reached a consistent database state? In crash recovery, we have + * to replay all the WAL, so reachedConsistency is never set. During archive + * recovery, the database is consistent once minRecoveryPoint is reached. + */ +bool reachedConsistency = false; static bool InRedo = false; @@ -6894,9 +6900,16 @@ static void CheckRecoveryConsistency(void) { /* + * During crash recovery, we don't reach a consistent state until we've + * replayed all the WAL. + */ + if (XLogRecPtrIsInvalid(minRecoveryPoint)) + return; + + /* * Have we passed our safe starting point? */ - if (!reachedMinRecoveryPoint && + if (!reachedConsistency && XLByteLE(minRecoveryPoint, EndRecPtr) && XLogRecPtrIsInvalid(ControlFile->backupStartPoint)) { @@ -6906,7 +6919,7 @@ CheckRecoveryConsistency(void) */ XLogCheckInvalidPages(); - reachedMinRecoveryPoint = true; + reachedConsistency = true; ereport(LOG, (errmsg("consistent recovery state reached at %X/%X", EndRecPtr.xlogid, EndRecPtr.xrecoff))); @@ -6919,7 +6932,7 @@ CheckRecoveryConsistency(void) */ if (standbyState == STANDBY_SNAPSHOT_READY && !LocalHotStandbyActive && - reachedMinRecoveryPoint && + reachedConsistency && IsUnderPostmaster) { /* use volatile pointer to prevent code rearrangement */ diff --git a/src/backend/access/transam/xlogutils.c b/src/backend/access/transam/xlogutils.c index 350d434562a..b280434a829 100644 --- a/src/backend/access/transam/xlogutils.c +++ b/src/backend/access/transam/xlogutils.c @@ -85,7 +85,7 @@ log_invalid_page(RelFileNode node, ForkNumber forkno, BlockNumber blkno, * linger in the hash table until the end of recovery and PANIC there, * which might come only much later if this is a standby server. */ - if (reachedMinRecoveryPoint) + if (reachedConsistency) { report_invalid_page(WARNING, node, forkno, blkno, present); elog(PANIC, "WAL contains references to invalid pages"); diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h index 1fb56cdfd54..1b31414060d 100644 --- a/src/include/access/xlog.h +++ b/src/include/access/xlog.h @@ -190,7 +190,7 @@ typedef enum extern XLogRecPtr XactLastRecEnd; -extern bool reachedMinRecoveryPoint; +extern bool reachedConsistency; /* these variables are GUC parameters related to XLOG */ extern int CheckPointSegments; |