8000 Before removing backup_label and irrevocably changing pg_control file… · sureandrew/postgres@35b66df · GitHub
[go: up one dir, main page]

Skip to content

Commit 35b66df

Browse files
committed
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.
1 parent 62f86b3 commit 35b66df

File tree

1 file changed

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

1 file changed

+17
-2
lines changed

src/backend/access/transam/xlog.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4423,14 +4423,29 @@ StartupXLOG(void)
44234423
record = ReadCheckpointRecord(checkPointLoc, 0);
44244424
if (record != NULL)
44254425
{
4426+
memcpy(&checkPoint, XLogRecGetData(record), sizeof(CheckPoint));
44264427
ereport(LOG,
44274428
(errmsg("checkpoint record is at %X/%X",
44284429
checkPointLoc.xlogid, checkPointLoc.xrecoff)));
44294430
InRecovery = true; /* force recovery even if SHUTDOWNED */
4431+
4432+
/*
4433+
* Make sure that REDO location exists. This may not be
4434+
* the case if there was a crash during an online backup,
4435+
* which left a backup_label around that references a WAL
4436+
* segment that's already been archived.
4437+
*/
4438+
if (XLByteLT(checkPoint.redo, checkPointLoc))
4439+
{
4440+
if (!ReadRecord(&(checkPoint.redo), LOG))
4441+
ereport(FATAL,
4442< B722 /code>+
(errmsg("could not find redo location referenced by checkpoint record"),
4443+
errhint("If you are not restoring from a backup, try removing the file \"%s/backup_label\".", DataDir)));
4444+
}
44304445
}
44314446
else
44324447
{
4433-
ereport(PANIC,
4448+
ereport(FATAL,
44344449
(errmsg("could not locate required checkpoint record"),
44354450
errhint("If you are not restoring from a backup, try removing the file \"%s/backup_label\".", DataDir)));
44364451
}
@@ -4464,10 +4479,10 @@ StartupXLOG(void)
44644479
ereport(PANIC,
44654480
(errmsg("could not locate a valid checkpoint record")));
44664481
}
4482+
memcpy(&checkPoint, XLogRecGetData(record), sizeof(CheckPoint));
44674483
}
44684484

44694485
LastRec = RecPtr = checkPointLoc;
4470-
memcpy(&checkPoint, XLogRecGetData(record), sizeof(CheckPoint));
44714486
wasShutdown = (record->xl_info == XLOG_CHECKPOINT_SHUTDOWN);
44724487

44734488
ereport(LOG,

0 commit comments

Comments
 (0)
0