Skip to content

Commit 94b18c6

Browse files
committed
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.
1 parent ec21805 commit 94b18c6

File tree

1 file changed

+17
-4
lines changed
  • src/backend/access/transam

1 file changed

+17
-4
lines changed

src/backend/access/transam/xlog.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,13 @@ static TimeLineID lastPageTLI = 0;
514514
static XLogRecPtr minRecoveryPoint; /* local copy of
515515
* ControlFile->minRecoveryPoint */
516516
static bool updateMinRecoveryPoint = true;
517-
static bool reachedMinRecoveryPoint = false;
517+
518+
/*
519+
* Have we reached a consistent database state? In crash recovery, we have
520+
* to replay all the WAL, so reachedConsistency is never set. During archive
521+
* recovery, the database is consistent once minRecoveryPoint is reached.
522+
*/
523+
static bool reachedConsistency = false;
518524

519525
static bool InRedo = false;
520526

@@ -6608,14 +6614,21 @@ CheckRecoveryConsistency(void)
66086614
{
66096615
static bool backendsAllowed = false;
66106616

6617+
/*
6618+
* During crash recovery, we don't reach a consistent state until we've
6619+
* replayed all the WAL.
6620+
*/
6621+
if (XLogRecPtrIsInvalid(minRecoveryPoint))
6622+
return;
6623+
66116624
/*
66126625
* Have we passed our safe starting point?
66136626
*/
6614-
if (!reachedMinRecoveryPoint &&
6627+
if (!reachedConsistency &&
66156628
XLByteLE(minRecoveryPoint, EndRecPtr) &&
66166629
XLogRecPtrIsInvalid(ControlFile->backupStartPoint))
66176630
{
6618-
reachedMinRecoveryPoint = true;
6631+
reachedConsistency = true;
66196632
ereport(LOG,
66206633
(errmsg("consistent recovery state reached at %X/%X",
66216634
EndRecPtr.xlogid, EndRecPtr.xrecoff)));
@@ -6628,7 +6641,7 @@ CheckRecoveryConsistency(void)
66286641
*/
66296642
if (standbyState == STANDBY_SNAPSHOT_READY &&
66306643
!backendsAllowed &&
6631-
reachedMinRecoveryPoint &&
6644+
reachedConsistency &&
66326645
IsUnderPostmaster)
66336646
{
66346647
backendsAllowed = true;

0 commit comments

Comments
 (0)