From: Heikki Linnakangas Date: Tue, 30 Apr 2013 13:31:21 +0000 (+0300) Subject: Install recycled WAL segments with current timeline ID during recovery. X-Git-Tag: REL9_2_5~110 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4aed94f1660fb55bc825bf7f3135379dab28eb55;p=postgresql Install recycled WAL segments with current timeline ID during recovery. This is a follow-up to the earlier fix, which changed the recycling logic to recycle WAL segments under the current recovery target timeline. That turns out to be a bad idea, because installing a recycled segment with a TLI higher than what we're recovering at the moment means that the recovery logic will find the recycled WAL segment and try to replay it. It will fail, but but the mere presence of such a WAL segment will mask any other, real, file with the same log/seg, but smaller TLI. Per report from Mitsumasa Kondo. Apply to 9.1 and 9.2, like the previous fix. Master was already doing this differently; this patch makes 9.1 and 9.2 to do the same thing as master. --- diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 690077ce82..26c9ef3d41 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -8566,10 +8566,18 @@ CreateRestartPoint(int flags) PrevLogSeg(_logId, _logSeg); /* - * Update ThisTimeLineID to the recovery target timeline, so that - * we install any recycled segments on the correct timeline. + * Update ThisTimeLineID to the timeline we're currently replaying, + * so that we install any recycled segments on that timeline. + * + * There is no guarantee that the WAL segments will be useful on the + * current timeline; if recovery proceeds to a new timeline right + * after this, the pre-allocated WAL segments on this timeline will + * not be used, and will go wasted until recycled on the next + * restartpoint. We'll live with that. */ - ThisTimeLineID = GetRecoveryTargetTLI(); + SpinLockAcquire(&xlogctl->info_lck); + ThisTimeLineID = XLogCtl->lastCheckPoint.ThisTimeLineID; + SpinLockRelease(&xlogctl->info_lck); RemoveOldXlogFiles(_logId, _logSeg, endptr);