Skip to content

Commit 0d0501e

Browse files
committed
Fix recycling of WAL segments after changing recovery target timeline.
After the recovery target timeline is changed, we would still recycle and preallocate WAL segments on the old target timeline. Those WAL segments created for the old timeline are a waste of space, although otherwise harmless. The problem is that when installing a recycled WAL segment as a future one, ThisTimeLineID is used to construct the filename. ThisTimeLineID is initialized in the checkpointer process to the recovery target timeline at startup, but it was not updated when the startup process chooses a new target timeline (recovery_target_timeline='latest'). To fix, always update ThisTimeLineID before recycling WAL segments at a restartpoint. This still leaves a small window where we might install WAL segments under wrong timeline ID, if the target timeline is changed just as we're about to start recycling. Also, when we're not on the target timeline yet, but still replaying some older timeline, we'll install WAL segments to the newer timeline anyway and they will still go wasted. We'll just live with the waste in that situation. Commit to 9.2 and 9.1. Older versions didn't change recovery target timeline after startup, and for master, I'll commit a slightly different variant of this.
1 parent b487c39 commit 0d0501e

File tree

1 file changed

+7
-0
lines changed
  • src/backend/access/transam

1 file changed

+7
-0
lines changed

src/backend/access/transam/xlog.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8259,6 +8259,13 @@ CreateRestartPoint(int flags)
82598259
endptr = GetWalRcvWriteRecPtr(NULL);
82608260

82618261
PrevLogSeg(_logId, _logSeg);
8262+
8263+
/*
8264+
* Update ThisTimeLineID to the recovery target timeline, so that
8265+
* we install any recycled segments on the correct timeline.
8266+
*/
8267+
ThisTimeLineID = GetRecoveryTargetTLI();
8268+
82628269
RemoveOldXlogFiles(_logId, _logSeg, endptr);
82638270

82648271
/*

0 commit comments

Comments
 (0)