Skip to content

Commit 2a0bfa4

Browse files
committed
Prevent WAL files created by pg_basebackup -x/X from being archived again.
WAL (and timeline history) files created by pg_basebackup did not maintain the new base backup's archive status. That's currently not a problem if the new node is used as a standby - but if that node is promoted all still existing files can get archived again. With a high wal_keep_segment settings that can happen a significant time later - which is quite confusing. Change both the backend (for the -x/-X fetch case) and pg_basebackup (for -X stream) itself to always mark WAL/timeline files included in the base backup as .done. That's in line with walreceiver.c doing so. The verbosity of the pg_basebackup changes show pretty clearly that it needs some refactoring, but that'd result in not be backpatchable changes. Backpatch to 9.1 where pg_basebackup was introduced. Discussion: 20141205002854.GE21964@awork2.anarazel.de
1 parent 6dd3050 commit 2a0bfa4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/backend/replication/basebackup.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
257257
while (true)
258258
{
259259
/* Send another xlog segment */
260+
char sn[MAXPGPATH];
260261
char fn[MAXPGPATH];
262+
char pathbuf[MAXPGPATH];
261263
int i;
262264

263265
XLogFilePath(fn, ThisTimeLineID, logid, logseg);
@@ -290,6 +292,15 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
290292
* boundary, so padding is never necessary.
291293
*/
292294

295+
/*
296+
* Mark file as archived, otherwise files can get archived again
297+
* after promotion of a new node. This is in line with
298+
* walreceiver.c always doing a XLogArchiveForceDone() after a
299+
* complete segment.
300+
*/
301+
XLogFileName(sn, ThisTimeLineID, logid, logseg);
302+
StatusFilePath(pathbuf, sn, ".done");
303+
sendFileWithContent(pathbuf, "");
293304

294305
/* Advance to the next WAL file */
295306
NextLogSeg(logid, logseg);
@@ -715,6 +726,15 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces)
715726
_tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf);
716727
}
717728
size += 512; /* Size of the header just added */
729+
730+
/*
731+
* Also send archive_status directory (by hackishly reusing
732+
* statbuf from above ...).
733+
*/
734+
if (!sizeonly)
735+
_tarWriteHeader("./pg_xlog/archive_status", NULL, &statbuf);
736+
size += 512; /* Size of the header just added */
737+
718738
continue; /* don't recurse into pg_xlog */
719739
}
720740

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy