]> granicus.if.org Git - postgresql/commitdiff
Don't set reachedMinRecoveryPoint during crash recovery. In crash recovery,
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 9 Dec 2011 12:32:42 +0000 (14:32 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 9 Dec 2011 13:50:19 +0000 (15:50 +0200)
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.

src/backend/access/transam/xlog.c

index 1612acd1409564dbd1ecf5ece5889e55b92ef7e7..d2c5841d741868c041dde737d4a6b4f2acda4699 100644 (file)
@@ -514,7 +514,13 @@ static TimeLineID lastPageTLI = 0;
 static XLogRecPtr minRecoveryPoint;            /* local copy of
                                                                                 * ControlFile->minRecoveryPoint */
 static bool updateMinRecoveryPoint = true;
-static 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.
+ */
+static bool reachedConsistency = false;
 
 static bool InRedo = false;
 
@@ -6608,14 +6614,21 @@ CheckRecoveryConsistency(void)
 {
        static bool backendsAllowed = false;
 
+       /*
+        * 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))
        {
-               reachedMinRecoveryPoint = true;
+               reachedConsistency = true;
                ereport(LOG,
                                (errmsg("consistent recovery state reached at %X/%X",
                                                EndRecPtr.xlogid, EndRecPtr.xrecoff)));
@@ -6628,7 +6641,7 @@ CheckRecoveryConsistency(void)
         */
        if (standbyState == STANDBY_SNAPSHOT_READY &&
                !backendsAllowed &&
-               reachedMinRecoveryPoint &&
+               reachedConsistency &&
                IsUnderPostmaster)
        {
                backendsAllowed = true;