Move the check for whether we've reached a safe starting point *before*
authorHeikki Linnakangas <heikki@enterprisedb.com>
Thu, 29 Jan 2009 19:46:43 +0000 (21:46 +0200)
committerHeikki Linnakangas <heikki@enterprisedb.com>
Thu, 29 Jan 2009 19:46:43 +0000 (21:46 +0200)
checking if we've reached the recovery target. Otherwise, if the first safe
starting point is at the exact same record as the recovery target, we'd
fail to start up.

src/backend/access/transam/xlog.c

index 4b3337797c4373d3abc50617e52a928b5222cb36..87770c16c640773b0fab0756e7d583c2733d8c46 100644 (file)
@@ -5257,6 +5257,32 @@ StartupXLOG(void)
                                }
 #endif
 
+                               /*
+                                * Have we reached our safe starting point? If so, we can
+                                * signal postmaster to enter consistent recovery mode.
+                                *
+                                * There are two points in the log we must pass. The first is
+                                * the minRecoveryPoint, which is the LSN at the time the
+                                * base backup was taken that we are about to rollfoward from.
+                                * If recovery has ever crashed or was stopped there is 
+                                * another point also: minSafeStartPoint, which is the
+                                * latest LSN that recovery could have reached prior to crash.
+                                */
+                               if (!reachedSafeStartPoint && 
+                                        XLByteLE(minSafeStartPoint, EndRecPtr) && 
+                                        XLByteLE(ControlFile->minRecoveryPoint, EndRecPtr))
+                               {
+                                       reachedSafeStartPoint = true;
+                                       if (InArchiveRecovery)
+                                       {
+                                               ereport(LOG,
+                                                       (errmsg("consistent recovery state reached at %X/%X",
+                                                               EndRecPtr.xlogid, EndRecPtr.xrecoff)));
+                                               if (IsUnderPostmaster)
+                                                       SendPostmasterSignal(PMSIGNAL_RECOVERY_START);
+                                       }
+                               }
+
                                /*
                                 * Have we reached our recovery target?
                                 */
@@ -5289,32 +5315,6 @@ StartupXLOG(void)
 
                                LastRec = ReadRecPtr;
 
-                               /*
-                                * Have we reached our safe starting point? If so, we can
-                                * signal postmaster to enter consistent recovery mode.
-                                *
-                                * There are two points in the log we must pass. The first is
-                                * the minRecoveryPoint, which is the LSN at the time the
-                                * base backup was taken that we are about to rollfoward from.
-                                * If recovery has ever crashed or was stopped there is 
-                                * another point also: minSafeStartPoint, which is the
-                                * latest LSN that recovery could have reached prior to crash.
-                                */
-                               if (!reachedSafeStartPoint && 
-                                        XLByteLE(minSafeStartPoint, EndRecPtr) && 
-                                        XLByteLE(ControlFile->minRecoveryPoint, EndRecPtr))
-                               {
-                                       reachedSafeStartPoint = true;
-                                       if (InArchiveRecovery)
-                                       {
-                                               ereport(LOG,
-                                                       (errmsg("consistent recovery state reached at %X/%X",
-                                                               EndRecPtr.xlogid, EndRecPtr.xrecoff)));
-                                               if (IsUnderPostmaster)
-                                                       SendPostmasterSignal(PMSIGNAL_RECOVERY_START);
-                                       }
-                               }
-
                                record = ReadRecord(NULL, LOG);
                        } while (record != NULL && recoveryContinue);