]> granicus.if.org Git - postgresql/commitdiff
Before removing backup_label and irrevocably changing pg_control file, check
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 26 Oct 2010 18:15:42 +0000 (21:15 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 26 Oct 2010 18:41:21 +0000 (21:41 +0300)
that WAL file containing the checkpoint redo-location can be found. This
avoids making the cluster irrecoverable if the redo location is in an earlie
WAL file than the checkpoint record.

Report, analysis and patch by Jeff Davis, with small changes by me.

src/backend/access/transam/xlog.c

index 45e9b74bd1768680dabf37b7c6c490f8ddd56413..794c0b5422fae9ab568161a7d2714d7592f06f9e 100644 (file)
@@ -4423,14 +4423,29 @@ StartupXLOG(void)
                record = ReadCheckpointRecord(checkPointLoc, 0);
                if (record != NULL)
                {
+                       memcpy(&checkPoint, XLogRecGetData(record), sizeof(CheckPoint));
                        ereport(LOG,
                                        (errmsg("checkpoint record is at %X/%X",
                                                        checkPointLoc.xlogid, checkPointLoc.xrecoff)));
                        InRecovery = true;      /* force recovery even if SHUTDOWNED */
+
+                       /*
+                        * Make sure that REDO location exists. This may not be
+                        * the case if there was a crash during an online backup,
+                        * which left a backup_label around that references a WAL
+                        * segment that's already been archived.
+                        */
+                       if (XLByteLT(checkPoint.redo, checkPointLoc))
+                       {
+                               if (!ReadRecord(&(checkPoint.redo), LOG))
+                                       ereport(FATAL,
+                                                       (errmsg("could not find redo location referenced by checkpoint record"),
+                                                        errhint("If you are not restoring from a backup, try removing the file \"%s/backup_label\".", DataDir)));
+                       }
                }
                else
                {
-                       ereport(PANIC,
+                       ereport(FATAL,
                                        (errmsg("could not locate required checkpoint record"),
                                         errhint("If you are not restoring from a backup, try removing the file \"%s/backup_label\".", DataDir)));
                }
@@ -4464,10 +4479,10 @@ StartupXLOG(void)
                                ereport(PANIC,
                                         (errmsg("could not locate a valid checkpoint record")));
                }
+               memcpy(&checkPoint, XLogRecGetData(record), sizeof(CheckPoint));
        }
 
        LastRec = RecPtr = checkPointLoc;
-       memcpy(&checkPoint, XLogRecGetData(record), sizeof(CheckPoint));
        wasShutdown = (record->xl_info == XLOG_CHECKPOINT_SHUTDOWN);
 
        ereport(LOG,