Skip to content

Commit 8e1e827

Browse files
committed
Check if we've reached end-of-backup point also if no redo is required.
If you restored from a backup taken from a standby, and the last record in the backup is the checkpoint record, ie. there is no redo required except for the checkpoint record, we would fail to notice that we've reached the end-of-backup point, and the database is consistent. The result was an error "WAL ends before end of online backup". To fix, move the have-we-reached-end-of-backup check into CheckRecoveryConsistency(), which is already responsible for similar checks with minRecoveryPoint, and is called in the right places. Backpatch to 9.2, this check and bug did not exist before that.
1 parent 31e0349 commit 8e1e827

File tree

1 file changed

+28
-21
lines changed
  • src/backend/access/transam

1 file changed

+28
-21
lines changed

src/backend/access/transam/xlog.c

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6776,27 +6776,6 @@ StartupXLOG(void)
67766776
/* Pop the error context stack */
67776777
error_context_stack = errcontext.previous;
67786778

6779-
if (!XLogRecPtrIsInvalid(ControlFile->backupEndPoint) &&
6780-
XLByteLE(ControlFile->backupEndPoint, EndRecPtr))
6781-
{
6782-
/*
6783-
* We have reached the end of base backup, the point where
6784-
* the minimum recovery point in pg_control indicates. The
6785-
* data on disk is now consistent. Reset backupStartPoint
6786-
* and backupEndPoint.
6787-
*/
6788-
elog(DEBUG1, "end of backup reached");
6789-
6790-
LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
6791-
6792-
MemSet(&ControlFile->backupStartPoint, 0, sizeof(XLogRecPtr));
6793-
MemSet(&ControlFile->backupEndPoint, 0, sizeof(XLogRecPtr));
6794-
ControlFile->backupEndRequired = false;
6795-
UpdateControlFile();
6796-
6797-
LWLockRelease(ControlFileLock);
6798-
}
6799-
68006779
/*
68016780
* Update lastReplayedEndRecPtr after this record has been
68026781
* successfully replayed.
@@ -7176,6 +7155,34 @@ CheckRecoveryConsistency(void)
71767155
if (XLogRecPtrIsInvalid(minRecoveryPoint))
71777156
return;
71787157

7158+
/*
7159+
* Have we reached the point where our base backup was completed?
7160+
*/
7161+
if (!XLogRecPtrIsInvalid(ControlFile->backupEndPoint) &&
7162+
XLByteLE(ControlFile->backupEndPoint, EndRecPtr))
7163+
{
7164+
/*
7165+
* We have reached the end of base backup, as indicated by pg_control.
7166+
* The data on disk is now consistent. Reset backupStartPoint and
7167+
* backupEndPoint, and update minRecoveryPoint to make sure we don't
7168+
* allow starting up at an earlier point even if recovery is stopped
7169+
* and restarted soon after this.
7170+
*/
7171+
elog(DEBUG1, "end of backup reached");
7172+
7173+
LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
7174+
7175+
if (XLByteLT(ControlFile->minRecoveryPoint, EndRecPtr))
7176+
ControlFile->minRecoveryPoint = EndRecPtr;
7177+
7178+
MemSet(&ControlFile->backupStartPoint, 0, sizeof(XLogRecPtr));
7179+
MemSet(&ControlFile->backupEndPoint, 0, sizeof(XLogRecPtr));
7180+
ControlFile->backupEndRequired = false;
7181+
UpdateControlFile();
7182+
7183+
LWLockRelease(ControlFileLock);
7184+
}
7185+
71797186
/*
71807187
* Have we passed our safe starting point? Note that minRecoveryPoint
71817188
* is known to be incorrectly set if ControlFile->backupEndRequired,

0 commit comments

Comments
 (0)