@@ -888,8 +888,8 @@ static int emode_for_corrupt_record(int emode, XLogRecPtr RecPtr);
888
888
static void XLogFileClose (void );
889
889
static void PreallocXlogFiles (XLogRecPtr endptr );
890
890
static void RemoveTempXlogFiles (void );
891
- static void RemoveOldXlogFiles (XLogSegNo segno , XLogRecPtr PriorRedoPtr , XLogRecPtr endptr );
892
- static void RemoveXlogFile (const char * segname , XLogRecPtr PriorRedoPtr , XLogRecPtr endptr );
891
+ static void RemoveOldXlogFiles (XLogSegNo segno , XLogRecPtr RedoRecPtr , XLogRecPtr endptr );
892
+ static void RemoveXlogFile (const char * segname , XLogRecPtr RedoRecPtr , XLogRecPtr endptr );
893
893
static void UpdateLastRemovedPtr (char * filename );
894
894
static void ValidateXLOGDirectoryStructure (void );
895
895
static void CleanupBackupHistory (void );
@@ -2287,7 +2287,7 @@ assign_checkpoint_completion_target(double newval, void *extra)
2287
2287
* XLOG segments? Returns the highest segment that should be preallocated.
2288
2288
*/
2289
2289
static XLogSegNo
2290
- XLOGfileslop (XLogRecPtr PriorRedoPtr )
2290
+ XLOGfileslop (XLogRecPtr RedoRecPtr )
2291
2291
{
2292
2292
XLogSegNo minSegNo ;
2293
2293
XLogSegNo maxSegNo ;
@@ -2299,9 +2299,9 @@ XLOGfileslop(XLogRecPtr PriorRedoPtr)
2299
2299
* correspond to. Always recycle enough segments to meet the minimum, and
2300
2300
* remove enough segments to stay below the maximum.
2301
2301
*/
2302
- minSegNo = PriorRedoPtr / wal_segment_size +
2302
+ minSegNo = RedoRecPtr / wal_segment_size +
2303
2303
ConvertToXSegs (min_wal_size_mb , wal_segment_size ) - 1 ;
2304
- maxSegNo = PriorRedoPtr / wal_segment_size +
2304
+ maxSegNo = RedoRecPtr / wal_segment_size +
2305
2305
ConvertToXSegs (max_wal_size_mb , wal_segment_size ) - 1 ;
2306
2306
2307
2307
/*
@@ -2316,7 +2316,7 @@ XLOGfileslop(XLogRecPtr PriorRedoPtr)
2316
2316
/* add 10% for good measure. */
2317
2317
distance *= 1.10 ;
2318
2318
2319
- recycleSegNo = (XLogSegNo ) ceil (((double ) PriorRedoPtr + distance ) /
2319
+ recycleSegNo = (XLogSegNo ) ceil (((double ) RedoRecPtr + distance ) /
2320
2320
wal_segment_size );
2321
2321
2322
2322
if (recycleSegNo < minSegNo )
@@ -3899,12 +3899,12 @@ RemoveTempXlogFiles(void)
3899
3899
/*
3900
3900
* Recycle or remove all log files older or equal to passed segno.
3901
3901
*
3902
- * endptr is current (or recent) end of xlog, and PriorRedoRecPtr is the
3903
- * redo pointer of the previous checkpoint. These are used to determine
3902
+ * endptr is current (or recent) end of xlog, and RedoRecPtr is the
3903
+ * redo pointer of the last checkpoint. These are used to determine
3904
3904
* whether we want to recycle rather than delete no-longer-wanted log files.
3905
3905
*/
3906
3906
static void
3907
- RemoveOldXlogFiles (XLogSegNo segno , XLogRecPtr PriorRedoPtr , XLogRecPtr endptr )
3907
+ RemoveOldXlogFiles (XLogSegNo segno , XLogRecPtr RedoRecPtr , XLogRecPtr endptr )
3908
3908
{
3909
3909
DIR * xldir ;
3910
3910
struct dirent * xlde ;
@@ -3947,7 +3947,7 @@ RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr PriorRedoPtr, XLogRecPtr endptr)
3947
3947
/* Update the last removed location in shared memory first */
3948
3948
UpdateLastRemovedPtr (xlde -> d_name );
3949
3949
3950
- RemoveXlogFile (xlde -> d_name , PriorRedoPtr , endptr );
3950
+ RemoveXlogFile (xlde -> d_name , RedoRecPtr , endptr );
3951
3951
}
3952
3952
}
3953
3953
}
@@ -4021,14 +4021,14 @@ RemoveNonParentXlogFiles(XLogRecPtr switchpoint, TimeLineID newTLI)
4021
4021
/*
4022
4022
* Recycle or remove a log file that's no longer needed.
4023
4023
*
4024
- * endptr is current (or recent) end of xlog, and PriorRedoRecPtr is the
4025
- * redo pointer of the previous checkpoint. These are used to determine
4024
+ * endptr is current (or recent) end of xlog, and RedoRecPtr is the
4025
+ * redo pointer of the last checkpoint. These are used to determine
4026
4026
* whether we want to recycle rather than delete no-longer-wanted log files.
4027
- * If PriorRedoRecPtr is not known, pass invalid, and the function will
4028
- * recycle, somewhat arbitrarily, 10 future segments.
4027
+ * If RedoRecPtr is not known, pass invalid, and the function will recycle,
4028
+ * somewhat arbitrarily, 10 future segments.
4029
4029
*/
4030
4030
static void
4031
- RemoveXlogFile (const char * segname , XLogRecPtr PriorRedoPtr , XLogRecPtr endptr )
4031
+ RemoveXlogFile (const char * segname , XLogRecPtr RedoRecPtr , XLogRecPtr endptr )
4032
4032
{
4033
4033
char path [MAXPGPATH ];
4034
4034
#ifdef WIN32
@@ -4042,10 +4042,10 @@ RemoveXlogFile(const char *segname, XLogRecPtr PriorRedoPtr, XLogRecPtr endptr)
4042
4042
* Initialize info about where to try to recycle to.
4043
4043
*/
4044
4044
XLByteToSeg (endptr , endlogSegNo , wal_segment_size );
4045
- if (PriorRedoPtr == InvalidXLogRecPtr )
4045
+ if (RedoRecPtr == InvalidXLogRecPtr )
4046
4046
recycleSegNo = endlogSegNo + 10 ;
4047
4047
else
4048
- recycleSegNo = XLOGfileslop (PriorRedoPtr );
4048
+ recycleSegNo = XLOGfileslop (RedoRecPtr );
4049
4049
4050
4050
snprintf (path , MAXPGPATH , XLOGDIR "/%s" , segname );
4051
4051
@@ -8706,6 +8706,7 @@ CreateCheckPoint(int flags)
8706
8706
bool shutdown ;
8707
8707
CheckPoint checkPoint ;
8708
8708
XLogRecPtr recptr ;
8709
+ XLogSegNo _logSegNo ;
8709
8710
XLogCtlInsert * Insert = & XLogCtl -> Insert ;
8710
8711
uint32 freespace ;
8711
8712
XLogRecPtr PriorRedoPtr ;
@@ -9073,21 +9074,20 @@ CreateCheckPoint(int flags)
9073
9074
smgrpostckpt ();
9074
9075
9075
9076
/*
9076
- * Delete old log files and recycle them
9077
+ * Update the average distance between checkpoints if the prior checkpoint
9078
+ * exists.
9077
9079
*/
9078
9080
if (PriorRedoPtr != InvalidXLogRecPtr )
9079
- {
9080
- XLogSegNo _logSegNo ;
9081
-
9082
- /* Update the average distance between checkpoints. */
9083
9081
UpdateCheckPointDistanceEstimate (RedoRecPtr - PriorRedoPtr );
9084
9082
9085
- /* Trim from the last checkpoint, not the last - 1 */
9086
- XLByteToSeg (RedoRecPtr , _logSegNo , wal_segment_size );
9087
- KeepLogSeg (recptr , & _logSegNo );
9088
- _logSegNo -- ;
9089
- RemoveOldXlogFiles (_logSegNo , PriorRedoPtr , recptr );
9090
- }
9083
+ /*
9084
+ * Delete old log files, those no longer needed for last checkpoint to
9085
+ * prevent the disk holding the xlog from growing full.
9086
+ */
9087
+ XLByteToSeg (RedoRecPtr , _logSegNo , wal_segment_size );
9088
+ KeepLogSeg (recptr , & _logSegNo );
9089
+ _logSegNo -- ;
9090
+ RemoveOldXlogFiles (_logSegNo , RedoRecPtr , recptr );
9091
9091
9092
9092
/*
9093
9093
* Make more log segments if needed. (Do this after recycling old log
@@ -9253,6 +9253,11 @@ CreateRestartPoint(int flags)
9253
9253
XLogRecPtr lastCheckPointEndPtr ;
9254
9254
CheckPoint lastCheckPoint ;
9255
9255
XLogRecPtr PriorRedoPtr ;
9256
+ XLogRecPtr receivePtr ;
9257
+ XLogRecPtr replayPtr ;
9258
+ TimeLineID replayTLI ;
9259
+ XLogRecPtr endptr ;
9260
+ XLogSegNo _logSegNo ;
9256
9261
TimestampTz xtime ;
9257
9262
9258
9263
/*
@@ -9395,68 +9400,60 @@ CreateRestartPoint(int flags)
9395
9400
LWLockRelease (ControlFileLock );
9396
9401
9397
9402
/*
9398
- * Delete old log files (those no longer needed even for previous
9399
- * checkpoint/restartpoint) to prevent the disk holding the xlog from
9400
- * growing full.
9403
+ * Update the average distance between checkpoints/restartpoints if the
9404
+ * prior checkpoint exists.
9401
9405
*/
9402
9406
if (PriorRedoPtr != InvalidXLogRecPtr )
9403
- {
9404
- XLogRecPtr receivePtr ;
9405
- XLogRecPtr replayPtr ;
9406
- TimeLineID replayTLI ;
9407
- XLogRecPtr endptr ;
9408
- XLogSegNo _logSegNo ;
9409
-
9410
- /* Update the average distance between checkpoints/restartpoints. */
9411
9407
UpdateCheckPointDistanceEstimate (RedoRecPtr - PriorRedoPtr );
9412
9408
9413
- XLByteToSeg (PriorRedoPtr , _logSegNo , wal_segment_size );
9414
-
9415
- /*
9416
- * Get the current end of xlog replayed or received, whichever is
9417
- * later.
9418
- */
9419
- receivePtr = GetWalRcvWriteRecPtr (NULL , NULL );
9420
- replayPtr = GetXLogReplayRecPtr (& replayTLI );
9421
- endptr = (receivePtr < replayPtr ) ? replayPtr : receivePtr ;
9409
+ /*
9410
+ * Delete old log files, those no longer needed for last restartpoint to
9411
+ * prevent the disk holding the xlog from growing full.
9412
+ */
9413
+ XLByteToSeg (RedoRecPtr , _logSegNo , wal_segment_size );
9422
9414
9423
- KeepLogSeg (endptr , & _logSegNo );
9424
- _logSegNo -- ;
9415
+ /*
9416
+ * Retreat _logSegNo using the current end of xlog replayed or received,
9417
+ * whichever is later.
9418
+ */
9419
+ receivePtr = GetWalRcvWriteRecPtr (NULL , NULL );
9420
+ replayPtr = GetXLogReplayRecPtr (& replayTLI );
9421
+ endptr = (receivePtr < replayPtr ) ? replayPtr : receivePtr ;
9422
+ KeepLogSeg (endptr , & _logSegNo );
9423
+ _logSegNo -- ;
9425
9424
9426
- /*
9427
- * Try to recycle segments on a useful timeline. If we've been
9428
- * promoted since the beginning of this restartpoint, use the new
9429
- * timeline chosen at end of recovery (RecoveryInProgress() sets
9430
- * ThisTimeLineID in that case). If we're still in recovery, use the
9431
- * timeline we're currently replaying.
9432
- *
9433
- * There is no guarantee that the WAL segments will be useful on the
9434
- * current timeline; if recovery proceeds to a new timeline right
9435
- * after this, the pre-allocated WAL segments on this timeline will
9436
- * not be used, and will go wasted until recycled on the next
9437
- * restartpoint. We'll live with that.
9438
- */
9439
- if (RecoveryInProgress ())
9440
- ThisTimeLineID = replayTLI ;
9425
+ /*
9426
+ * Try to recycle segments on a useful timeline. If we've been promoted
9427
+ * since the beginning of this restartpoint, use the new timeline chosen
9428
+ * at end of recovery (RecoveryInProgress() sets ThisTimeLineID in that
9429
+ * case). If we're still in recovery, use the timeline we're currently
9430
+ * replaying.
9431
+ *
9432
+ * There is no guarantee that the WAL segments will be useful on the
9433
+ * current timeline; if recovery proceeds to a new timeline right after
9434
+ * this, the pre-allocated WAL segments on this timeline will not be used,
9435
+ * and will go wasted until recycled on the next restartpoint. We'll live
9436
+ * with that.
9437
+ */
9438
+ if (RecoveryInProgress ())
9439
+ ThisTimeLineID = replayTLI ;
9441
9440
9442
- RemoveOldXlogFiles (_logSegNo , PriorRedoPtr , endptr );
9441
+ RemoveOldXlogFiles (_logSegNo , RedoRecPtr , endptr );
9443
9442
9444
- /*
9445
- * Make more log segments if needed. (Do this after recycling old log
9446
- * segments, since that may supply some of the needed files.)
9447
- */
9448
- PreallocXlogFiles (endptr );
9443
+ /*
9444
+ * Make more log segments if needed. (Do this after recycling old log
9445
+ * segments, since that may supply some of the needed files.)
9446
+ */
9447
+ PreallocXlogFiles (endptr );
9449
9448
9450
- /*
9451
- * ThisTimeLineID is normally not set when we're still in recovery.
9452
- * However, recycling/preallocating segments above needed
9453
- * ThisTimeLineID to determine which timeline to install the segments
9454
- * on. Reset it now, to restore the normal state of affairs for
9455
- * debugging purposes.
9456
- */
9457
- if (RecoveryInProgress ())
9458
- ThisTimeLineID = 0 ;
9459
- }
9449
+ /*
9450
+ * ThisTimeLineID is normally not set when we're still in recovery.
9451
+ * However, recycling/preallocating segments above needed ThisTimeLineID
9452
+ * to determine which timeline to install the segments on. Reset it now,
9453
+ * to restore the normal state of affairs for debugging purposes.
9454
+ */
9455
+ if (RecoveryInProgress ())
9456
+ ThisTimeLineID = 0 ;
9460
9457
9461
9458
/*
9462
9459
* Truncate pg_subtrans if possible. We can throw away all data before
0 commit comments