aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2010-10-26 21:15:42 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2010-10-26 21:41:32 +0300
commit49b5aba40e0b0adb1caaea81c88dd0e54a7d3890 (patch)
treef8a811b9ec3f1c232093e0e486eb05a9c8922f56 /src
parent77f8685bec94b642f1606f64cca6080a2d834441 (diff)
downloadpostgresql-49b5aba40e0b0adb1caaea81c88dd0e54a7d3890.tar.gz
postgresql-49b5aba40e0b0adb1caaea81c88dd0e54a7d3890.zip
Before removing backup_label and irrevocably changing pg_control file, check
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/access/transam/xlog.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 67081754c66..3cd53fd5fa4 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -4780,14 +4780,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)));
}
@@ -4823,10 +4838,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,