@@ -887,8 +887,8 @@ static bool WaitForWALToBecomeAvailable(XLogRecPtr RecPtr, bool randAccess,
887
887
static int emode_for_corrupt_record (int emode , XLogRecPtr RecPtr );
888
888
static void XLogFileClose (void );
889
889
static void PreallocXlogFiles (XLogRecPtr endptr );
890
- static void RemoveOldXlogFiles (XLogSegNo segno , XLogRecPtr PriorRedoPtr , XLogRecPtr endptr );
891
- static void RemoveXlogFile (const char * segname , XLogRecPtr PriorRedoPtr , XLogRecPtr endptr );
890
+ static void RemoveOldXlogFiles (XLogSegNo segno , XLogRecPtr RedoRecPtr , XLogRecPtr endptr );
891
+ static void RemoveXlogFile (const char * segname , XLogRecPtr RedoRecPtr , XLogRecPtr endptr );
892
892
static void UpdateLastRemovedPtr (char * filename );
893
893
static void ValidateXLOGDirectoryStructure (void );
894
894
static void CleanupBackupHistory (void );
@@ -2286,7 +2286,7 @@ assign_checkpoint_completion_target(double newval, void *extra)
2286
2286
* XLOG segments? Returns the highest segment that should be preallocated.
2287
2287
*/
2288
2288
static XLogSegNo
2289
- XLOGfileslop (XLogRecPtr PriorRedoPtr )
2289
+ XLOGfileslop (XLogRecPtr RedoRecPtr )
2290
2290
{
2291
2291
XLogSegNo minSegNo ;
2292
2292
XLogSegNo maxSegNo ;
@@ -2298,9 +2298,9 @@ XLOGfileslop(XLogRecPtr PriorRedoPtr)
2298
2298
* correspond to. Always recycle enough segments to meet the minimum, and
2299
2299
* remove enough segments to stay below the maximum.
2300
2300
*/
2301
- minSegNo = PriorRedoPtr / wal_segment_size +
2301
+ minSegNo = RedoRecPtr / wal_segment_size +
2302
2302
ConvertToXSegs (min_wal_size_mb , wal_segment_size ) - 1 ;
2303
- maxSegNo = PriorRedoPtr / wal_segment_size +
2303
+ maxSegNo = RedoRecPtr / wal_segment_size +
2304
2304
ConvertToXSegs (max_wal_size_mb , wal_segment_size ) - 1 ;
2305
2305
2306
2306
/*
@@ -2315,7 +2315,7 @@ XLOGfileslop(XLogRecPtr PriorRedoPtr)
2315
2315
/* add 10% for good measure. */
2316
2316
distance *= 1.10 ;
2317
2317
2318
- recycleSegNo = (XLogSegNo ) ceil (((double ) PriorRedoPtr + distance ) /
2318
+ recycleSegNo = (XLogSegNo ) ceil (((double ) RedoRecPtr + distance ) /
2319
2319
wal_segment_size );
2320
2320
2321
2321
if (recycleSegNo < minSegNo )
@@ -3866,12 +3866,12 @@ UpdateLastRemovedPtr(char *filename)
3866
3866
/*
3867
3867
* Recycle or remove all log files older or equal to passed segno.
3868
3868
*
3869
- * endptr is current (or recent) end of xlog, and PriorRedoRecPtr is the
3870
- * redo pointer of the previous checkpoint. These are used to determine
3869
+ * endptr is current (or recent) end of xlog, and RedoRecPtr is the
3870
+ * redo pointer of the last checkpoint. These are used to determine
3871
3871
* whether we want to recycle rather than delete no-longer-wanted log files.
3872
3872
*/
3873
3873
static void
3874
- RemoveOldXlogFiles (XLogSegNo segno , XLogRecPtr PriorRedoPtr , XLogRecPtr endptr )
3874
+ RemoveOldXlogFiles (XLogSegNo segno , XLogRecPtr RedoRecPtr , XLogRecPtr endptr )
3875
3875
{
3876
3876
DIR * xldir ;
3877
3877
struct dirent * xlde ;
@@ -3914,7 +3914,7 @@ RemoveOldXlogFiles(XLogSegNo segno, XLogRecPtr PriorRedoPtr, XLogRecPtr endptr)
3914
3914
/* Update the last removed location in shared memory first */
3915
3915
UpdateLastRemovedPtr (xlde -> d_name );
3916
3916
3917
- RemoveXlogFile (xlde -> d_name , PriorRedoPtr , endptr );
3917
+ RemoveXlogFile (xlde -> d_name , RedoRecPtr , endptr );
3918
3918
}
3919
3919
}
3920
3920
}
@@ -3988,14 +3988,14 @@ RemoveNonParentXlogFiles(XLogRecPtr switchpoint, TimeLineID newTLI)
3988
3988
/*
3989
3989
* Recycle or remove a log file that's no longer needed.
3990
3990
*
3991
- * endptr is current (or recent) end of xlog, and PriorRedoRecPtr is the
3992
- * redo pointer of the previous checkpoint. These are used to determine
3991
+ * endptr is current (or recent) end of xlog, and RedoRecPtr is the
3992
+ * redo pointer of the last checkpoint. These are used to determine
3993
3993
* whether we want to recycle rather than delete no-longer-wanted log files.
3994
- * If PriorRedoRecPtr is not known, pass invalid, and the function will
3995
- * recycle, somewhat arbitrarily, 10 future segments.
3994
+ * If RedoRecPtr is not known, pass invalid, and the function will recycle,
3995
+ * somewhat arbitrarily, 10 future segments.
3996
3996
*/
3997
3997
static void
3998
- RemoveXlogFile (const char * segname , XLogRecPtr PriorRedoPtr , XLogRecPtr endptr )
3998
+ RemoveXlogFile (const char * segname , XLogRecPtr RedoRecPtr , XLogRecPtr endptr )
3999
3999
{
4000
4000
char path [MAXPGPATH ];
4001
4001
#ifdef WIN32
@@ -4009,10 +4009,10 @@ RemoveXlogFile(const char *segname, XLogRecPtr PriorRedoPtr, XLogRecPtr endptr)
4009
4009
* Initialize info about where to try to recycle to.
4010
4010
*/
4011
4011
XLByteToSeg (endptr , endlogSegNo , wal_segment_size );
4012
- if (PriorRedoPtr == InvalidXLogRecPtr )
4012
+ if (RedoRecPtr == InvalidXLogRecPtr )
4013
4013
recycleSegNo = endlogSegNo + 10 ;
4014
4014
else
4015
- recycleSegNo = XLOGfileslop (PriorRedoPtr );
4015
+ recycleSegNo = XLOGfileslop (RedoRecPtr );
4016
4016
4017
4017
snprintf (path , MAXPGPATH , XLOGDIR "/%s" , segname );
4018
4018
@@ -8639,6 +8639,7 @@ CreateCheckPoint(int flags)
8639
8639
bool shutdown ;
8640
8640
CheckPoint checkPoint ;
8641
8641
XLogRecPtr recptr ;
8642
+ XLogSegNo _logSegNo ;
8642
8643
XLogCtlInsert * Insert = & XLogCtl -> Insert ;
8643
8644
uint32 freespace ;
8644
8645
XLogRecPtr PriorRedoPtr ;
@@ -9006,21 +9007,20 @@ CreateCheckPoint(int flags)
9006
9007
smgrpostckpt ();
9007
9008
9008
9009
/*
9009
- * Delete old log files and recycle them
9010
+ * Update the average distance between checkpoints if the prior checkpoint
9011
+ * exists.
9010
9012
*/
9011
9013
if (PriorRedoPtr != InvalidXLogRecPtr )
9012
- {
9013
- XLogSegNo _logSegNo ;
9014
-
9015
- /* Update the average distance between checkpoints. */
9016
9014
UpdateCheckPointDistanceEstimate (RedoRecPtr - PriorRedoPtr );
9017
9015
9018
- /* Trim from the last checkpoint, not the last - 1 */
9019
- XLByteToSeg (RedoRecPtr , _logSegNo , wal_segment_size );
9020
- KeepLogSeg (recptr , & _logSegNo );
9021
- _logSegNo -- ;
9022
- RemoveOldXlogFiles (_logSegNo , PriorRedoPtr , recptr );
9023
- }
9016
+ /*
9017
+ * Delete old log files, those no longer needed for last checkpoint to
9018
+ * prevent the disk holding the xlog from growing full.
9019
+ */
9020
+ XLByteToSeg (RedoRecPtr , _logSegNo , wal_segment_size );
9021
+ KeepLogSeg (recptr , & _logSegNo );
9022
+ _logSegNo -- ;
9023
+ RemoveOldXlogFiles (_logSegNo , RedoRecPtr , recptr );
9024
9024
9025
9025
/*
9026
9026
* Make more log segments if needed. (Do this after recycling old log
@@ -9186,6 +9186,11 @@ CreateRestartPoint(int flags)
9186
9186
XLogRecPtr lastCheckPointEndPtr ;
9187
9187
CheckPoint lastCheckPoint ;
9188
9188
XLogRecPtr PriorRedoPtr ;
9189
+ XLogRecPtr receivePtr ;
9190
+ XLogRecPtr replayPtr ;
9191
+ TimeLineID replayTLI ;
9192
+ XLogRecPtr endptr ;
9193
+ XLogSegNo _logSegNo ;
9189
9194
TimestampTz xtime ;
9190
9195
9191
9196
/*
@@ -9328,68 +9333,60 @@ CreateRestartPoint(int flags)
9328
9333
LWLockRelease (ControlFileLock );
9329
9334
9330
9335
/*
9331
- * Delete old log files (those no longer needed even for previous
9332
- * checkpoint/restartpoint) to prevent the disk holding the xlog from
9333
- * growing full.
9336
+ * Update the average distance between checkpoints/restartpoints if the
9337
+ * prior checkpoint exists.
9334
9338
*/
9335
9339
if (PriorRedoPtr != InvalidXLogRecPtr )
9336
- {
9337
- XLogRecPtr receivePtr ;
9338
- XLogRecPtr replayPtr ;
9339
- TimeLineID replayTLI ;
9340
- XLogRecPtr endptr ;
9341
- XLogSegNo _logSegNo ;
9342
-
9343
- /* Update the average distance between checkpoints/restartpoints. */
9344
9340
UpdateCheckPointDistanceEstimate (RedoRecPtr - PriorRedoPtr );
9345
9341
9346
- XLByteToSeg (PriorRedoPtr , _logSegNo , wal_segment_size );
9347
-
9348
- /*
9349
- * Get the current end of xlog replayed or received, whichever is
9350
- * later.
9351
- */
9352
- receivePtr = GetWalRcvWriteRecPtr (NULL , NULL );
9353
- replayPtr = GetXLogReplayRecPtr (& replayTLI );
9354
- endptr = (receivePtr < replayPtr ) ? replayPtr : receivePtr ;
9342
+ /*
9343
+ * Delete old log files, those no longer needed for last restartpoint to
9344
+ * prevent the disk holding the xlog from growing full.
9345
+ */
9346
+ XLByteToSeg (RedoRecPtr , _logSegNo , wal_segment_size );
9355
9347
9356
- KeepLogSeg (endptr , & _logSegNo );
9357
- _logSegNo -- ;
9348
+ /*
9349
+ * Retreat _logSegNo using the current end of xlog replayed or received,
9350
+ * whichever is later.
9351
+ */
9352
+ receivePtr = GetWalRcvWriteRecPtr (NULL , NULL );
9353
+ replayPtr = GetXLogReplayRecPtr (& replayTLI );
9354
+ endptr = (receivePtr < replayPtr ) ? replayPtr : receivePtr ;
9355
+ KeepLogSeg (endptr , & _logSegNo );
9356
+ _logSegNo -- ;
9358
9357
9359
- /*
9360
- * Try to recycle segments on a useful timeline. If we've been
9361
- * promoted since the beginning of this restartpoint, use the new
9362
- * timeline chosen at end of recovery (RecoveryInProgress() sets
9363
- * ThisTimeLineID in that case). If we're still in recovery, use the
9364
- * timeline we're currently replaying.
9365
- *
9366
- * There is no guarantee that the WAL segments will be useful on the
9367
- * current timeline; if recovery proceeds to a new timeline right
9368
- * after this, the pre-allocated WAL segments on this timeline will
9369
- * not be used, and will go wasted until recycled on the next
9370
- * restartpoint. We'll live with that.
9371
- */
9372
- if (RecoveryInProgress ())
9373
- ThisTimeLineID = replayTLI ;
9358
+ /*
9359
+ * Try to recycle segments on a useful timeline. If we've been promoted
9360
+ * since the beginning of this restartpoint, use the new timeline chosen
9361
+ * at end of recovery (RecoveryInProgress() sets ThisTimeLineID in that
9362
+ * case). If we're still in recovery, use the timeline we're currently
9363
+ * replaying.
9364
+ *
9365
+ * There is no guarantee that the WAL segments will be useful on the
9366
+ * current timeline; if recovery proceeds to a new timeline right after
9367
+ * this, the pre-allocated WAL segments on this timeline will not be used,
9368
+ * and will go wasted until recycled on the next restartpoint. We'll live
9369
+ * with that.
9370
+ */
9371
+ if (RecoveryInProgress ())
9372
+ ThisTimeLineID = replayTLI ;
9374
9373
9375
- RemoveOldXlogFiles (_logSegNo , PriorRedoPtr , endptr );
9374
+ RemoveOldXlogFiles (_logSegNo , RedoRecPtr , endptr );
9376
9375
9377
- /*
9378
- * Make more log segments if needed. (Do this after recycling old log
9379
- * segments, since that may supply some of the needed files.)
9380
- */
9381
- PreallocXlogFiles (endptr );
9376
+ /*
9377
+ * Make more log segments if needed. (Do this after recycling old log
9378
+ * segments, since that may supply some of the needed files.)
9379
+ */
9380
+ PreallocXlogFiles (endptr );
9382
9381
9383
- /*
9384
- * ThisTimeLineID is normally not set when we're still in recovery.
9385
- * However, recycling/preallocating segments above needed
9386
- * ThisTimeLineID to determine which timeline to install the segments
9387
- * on. Reset it now, to restore the normal state of affairs for
9388
- * debugging purposes.
9389
- */
9390
- if (RecoveryInProgress ())
9391
- ThisTimeLineID = 0 ;
9392
- }
9382
+ /*
9383
+ * ThisTimeLineID is normally not set when we're still in recovery.
9384
+ * However, recycling/preallocating segments above needed ThisTimeLineID
9385
+ * to determine which timeline to install the segments on. Reset it now,
9386
+ * to restore the normal state of affairs for debugging purposes.
9387
+ */
9388
+ if (RecoveryInProgress ())
9389
+ ThisTimeLineID = 0 ;
9393
9390
9394
9391
/*
9395
9392
* Truncate pg_subtrans if possible. We can throw away all data before
0 commit comments