Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf267c1c

Browse files
committed
Fix possible pg_basebackup failure on standby with "include WAL".
If a restartpoint flushed no dirty buffers, it could fail to updatethe minimum recovery point, leading to a minimum recovery point priorto the starting REDO location. perform_base_backup() would interpretthat as meaning that no WAL files at all needed to be included in thebackup, failing an internal sanity check. To fix, have restartpointsalways update the minimum recovery point to just after the checkpointrecord itself, so that the file (or files) containing the checkpointrecord will always be included in the backup.Code by Amit Kapila, per a design suggestion by me, with someadditional work on the code comment by me. Test case by MichaelPaquier. Report by Kyotaro Horiguchi.
1 parentc32fe43 commitf267c1c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,14 @@ typedef struct XLogCtlData
615615

616616
/*
617617
* During recovery, we keep a copy of the latest checkpoint record here.
618-
* Used by the background writer when it wants to create a restartpoint.
618+
* lastCheckPointRecPtr points to start of checkpoint record and
619+
* lastCheckPointEndPtr points to end+1 of checkpoint record. Used by the
620+
* background writer when it wants to create a restartpoint.
619621
*
620622
* Protected by info_lck.
621623
*/
622624
XLogRecPtrlastCheckPointRecPtr;
625+
XLogRecPtrlastCheckPointEndPtr;
623626
CheckPointlastCheckPoint;
624627

625628
/*
@@ -8773,6 +8776,7 @@ RecoveryRestartPoint(const CheckPoint *checkPoint)
87738776
*/
87748777
SpinLockAcquire(&XLogCtl->info_lck);
87758778
XLogCtl->lastCheckPointRecPtr=ReadRecPtr;
8779+
XLogCtl->lastCheckPointEndPtr=EndRecPtr;
87768780
XLogCtl->lastCheckPoint=*checkPoint;
87778781
SpinLockRelease(&XLogCtl->info_lck);
87788782
}
@@ -8792,6 +8796,7 @@ bool
87928796
CreateRestartPoint(intflags)
87938797
{
87948798
XLogRecPtrlastCheckPointRecPtr;
8799+
XLogRecPtrlastCheckPointEndPtr;
87958800
CheckPointlastCheckPoint;
87968801
XLogRecPtrPriorRedoPtr;
87978802
TimestampTzxtime;
@@ -8805,6 +8810,7 @@ CreateRestartPoint(int flags)
88058810
/* Get a local copy of the last safe checkpoint record. */
88068811
SpinLockAcquire(&XLogCtl->info_lck);
88078812
lastCheckPointRecPtr=XLogCtl->lastCheckPointRecPtr;
8813+
lastCheckPointEndPtr=XLogCtl->lastCheckPointEndPtr;
88088814
lastCheckPoint=XLogCtl->lastCheckPoint;
88098815
SpinLockRelease(&XLogCtl->info_lck);
88108816

@@ -8908,6 +8914,27 @@ CreateRestartPoint(int flags)
89088914
ControlFile->checkPoint=lastCheckPointRecPtr;
89098915
ControlFile->checkPointCopy=lastCheckPoint;
89108916
ControlFile->time= (pg_time_t)time(NULL);
8917+
8918+
/*
8919+
* Ensure minRecoveryPoint is past the checkpoint record. Normally,
8920+
* this will have happened already while writing out dirty buffers,
8921+
* but not necessarily - e.g. because no buffers were dirtied. We do
8922+
* this because a non-exclusive base backup uses minRecoveryPoint to
8923+
* determine which WAL files must be included in the backup, and the
8924+
* file (or files) containing the checkpoint record must be included,
8925+
* at a minimum. Note that for an ordinary restart of recovery there's
8926+
* no value in having the minimum recovery point any earlier than this
8927+
* anyway, because redo will begin just after the checkpoint record.
8928+
*/
8929+
if (ControlFile->minRecoveryPoint<lastCheckPointEndPtr)
8930+
{
8931+
ControlFile->minRecoveryPoint=lastCheckPointEndPtr;
8932+
ControlFile->minRecoveryPointTLI=lastCheckPoint.ThisTimeLineID;
8933+
8934+
/* update local copy */
8935+
minRecoveryPoint=ControlFile->minRecoveryPoint;
8936+
minRecoveryPointTLI=ControlFile->minRecoveryPointTLI;
8937+
}
89118938
if (flags&CHECKPOINT_IS_SHUTDOWN)
89128939
ControlFile->state=DB_SHUTDOWNED_IN_RECOVERY;
89138940
UpdateControlFile();

‎src/test/recovery/t/001_stream_rep.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
# pg_basebackup works on a standby).
2525
$node_standby_1->backup($backup_name);
2626

27+
# Take a second backup of the standby while the master is offline.
28+
$node_master->stop;
29+
$node_standby_1->backup('my_backup_2');
30+
$node_master->start;
31+
2732
# Create second standby node linking to standby 1
2833
my$node_standby_2 = get_new_node('standby_2');
2934
$node_standby_2->init_from_backup($node_standby_1,$backup_name,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp