mirror of
https://github.com/postgres/postgres.git
synced 2025-06-27 23:21:58 +03:00
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
This commit is contained in:
@ -404,6 +404,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
|
||||
errmsg("unexpected WAL file size \"%s\"", walFiles[i])));
|
||||
}
|
||||
|
||||
/* send the WAL file itself */
|
||||
_tarWriteHeader(pathbuf, NULL, &statbuf);
|
||||
|
||||
while ((cnt = fread(buf, 1, Min(sizeof(buf), XLogSegSize - len), fp)) > 0)
|
||||
@ -428,7 +429,17 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
|
||||
}
|
||||
|
||||
/* XLogSegSize is a multiple of 512, so no need for padding */
|
||||
|
||||
FreeFile(fp);
|
||||
|
||||
/*
|
||||
* Mark file as archived, otherwise files can get archived again
|
||||
* after promotion of a new node. This is in line with
|
||||
* walreceiver.c always doing a XLogArchiveForceDone() after a
|
||||
* complete segment.
|
||||
*/
|
||||
StatusFilePath(pathbuf, walFiles[i], ".done");
|
||||
sendFileWithContent(pathbuf, "");
|
||||
}
|
||||
|
||||
/*
|
||||
@ -452,6 +463,10 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
|
||||
errmsg("could not stat file \"%s\": %m", pathbuf)));
|
||||
|
||||
sendFile(pathbuf, pathbuf, &statbuf, false);
|
||||
|
||||
/* unconditionally mark file as archived */
|
||||
StatusFilePath(pathbuf, fname, ".done");
|
||||
sendFileWithContent(pathbuf, "");
|
||||
}
|
||||
|
||||
/* Send CopyDone message for the last tar file */
|
||||
@ -900,6 +915,15 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces)
|
||||
_tarWriteHeader(pathbuf + basepathlen + 1, NULL, &statbuf);
|
||||
}
|
||||
size += 512; /* Size of the header just added */
|
||||
|
||||
/*
|
||||
* Also send archive_status directory (by hackishly reusing
|
||||
* statbuf from above ...).
|
||||
*/
|
||||
if (!sizeonly)
|
||||
_tarWriteHeader("./pg_xlog/archive_status", NULL, &statbuf);
|
||||
size += 512; /* Size of the header just added */
|
||||
|
||||
continue; /* don't recurse into pg_xlog */
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user