aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2012-12-20 21:30:59 +0200
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2012-12-20 21:30:59 +0200
commit3881aedbcfb5e1e36e2860d081e045fb5283f8cc (patch)
tree6a6af7b037dc39cf0bc863653b8f2c39b01afea0
parent8e1e8278c35be9b70e92c8b43a8f65b372dc269a (diff)
downloadpostgresql-3881aedbcfb5e1e36e2860d081e045fb5283f8cc.tar.gz
postgresql-3881aedbcfb5e1e36e2860d081e045fb5283f8cc.zip
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.
-rw-r--r--src/backend/access/transam/xlog.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 1d1e47b588c..5df6063be99 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -8415,6 +8415,13 @@ CreateRestartPoint(int flags)
KeepLogSeg(endptr, &_logId, &_logSeg);
PrevLogSeg(_logId, _logSeg);
+
+ /*
+ * Update ThisTimeLineID to the recovery target timeline, so that
+ * we install any recycled segments on the correct timeline.
+ */
+ ThisTimeLineID = GetRecoveryTargetTLI();
+
RemoveOldXlogFiles(_logId, _logSeg, endptr);
/*