Skip to content

Commit f904e9a

Browse files
committed
Prevent the already-archived WAL file from being archived again.
Previously the archive recovery always created .ready file for the last WAL file of the old timeline at the end of recovery even when it's restored from the archive and has .done file. That is, there was the case where the WAL file had both .ready and .done files. This caused the already-archived WAL file to be archived again. This commit prevents the archive recovery from creating .ready file for the last WAL file if it has .done file, in order to prevent it from being archived again. This bug was added when cascading replication feature was introduced, i.e., the commit 5286105. So, back-patch to 9.2, where cascading replication was added. Reviewed by Michael Paquier
1 parent 6fa31d8 commit f904e9a

File tree

1 file changed

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

1 file changed

+9
-7
lines changed

src/backend/access/transam/xlog.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5786,7 +5786,7 @@ static void
57865786
exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg)
57875787
{
57885788
char recoveryPath[MAXPGPATH];
5789-
char xlogpath[MAXPGPATH];
5789+
char xlogfname[MAXFNAMELEN];
57905790

57915791
/*
57925792
* We are no longer in archive recovery state.
@@ -5814,27 +5814,29 @@ exitArchiveRecovery(TimeLineID endTLI, uint32 endLogId, uint32 endLogSeg)
58145814
* for the new timeline.
58155815
*
58165816
* Notify the archiver that the last WAL segment of the old timeline is
5817-
* ready to copy to archival storage. Otherwise, it is not archived for a
5818-
* while.
5817+
* ready to copy to archival storage if its .done file doesn't exist
5818+
* (e.g., if it's the restored WAL file, it's expected to have .done file).
5819+
* Otherwise, it is not archived for a while.
58195820
*/
58205821
if (endTLI != ThisTimeLineID)
58215822
{
58225823
XLogFileCopy(endLogId, endLogSeg,
58235824
endTLI, endLogId, endLogSeg);
58245825

5826+
/* Create .ready file only when neither .ready nor .done files exist */
58255827
if (XLogArchivingActive())
58265828
{
5827-
XLogFileName(xlogpath, endTLI, endLogId, endLogSeg);
5828-
XLogArchiveNotify(xlogpath);
5829+
XLogFileName(xlogfname, endTLI, endLogId, endLogSeg);
5830+
XLogArchiveCheckDone(xlogfname);
58295831
}
58305832
}
58315833

58325834
/*
58335835
* Let's just make real sure there are not .ready or .done flags posted
58345836
* for the new segment.
58355837
*/
5836-
XLogFileName(xlogpath, ThisTimeLineID, endLogId, endLogSeg);
5837-
XLogArchiveCleanup(xlogpath);
5838+
XLogFileName(xlogfname, ThisTimeLineID, endLogId, endLogSeg);
5839+
XLogArchiveCleanup(xlogfname);
58385840

58395841
/*
58405842
* Since there might be a partial WAL segment named RECOVERYXLOG, get rid

0 commit comments

Comments
 (0)