diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2012-11-19 10:02:25 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2012-11-19 10:14:20 +0200 |
commit | 644a0a6379afc00803dd89ffe8416514f5dfc217 (patch) | |
tree | da387d3319795781f31d8448d2d101cead2e3151 /src/backend/access/transam/xlogarchive.c | |
parent | b6e3798f3aa2747db145f25e03a8d34f2e5ec8c8 (diff) | |
download | postgresql-644a0a6379afc00803dd89ffe8416514f5dfc217.tar.gz postgresql-644a0a6379afc00803dd89ffe8416514f5dfc217.zip |
Fix archive_cleanup_command.
When I moved ExecuteRecoveryCommand() from xlog.c to xlogarchive.c, I didn't
realize that it's called from the checkpoint process, not the startup
process. I tried to use InRedo variable to decide whether or not to attempt
cleaning up the archive (must not do so before we have read the initial
checkpoint record), but that variable is only valid within the startup
process.
Instead, let ExecuteRecoveryCommand() always clean up the archive, and add
an explicit argument to RestoreArchivedFile() to say whether that's allowed
or not. The caller knows better.
Reported by Erik Rijkers, diagnosis by Fujii Masao. Only 9.3devel is
affected.
Diffstat (limited to 'src/backend/access/transam/xlogarchive.c')
-rw-r--r-- | src/backend/access/transam/xlogarchive.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/transam/xlogarchive.c index ce9dfaa9601..9bd6b8e3a2f 100644 --- a/src/backend/access/transam/xlogarchive.c +++ b/src/backend/access/transam/xlogarchive.c @@ -41,10 +41,15 @@ * For fixed-size files, the caller may pass the expected size as an * additional crosscheck on successful recovery. If the file size is not * known, set expectedSize = 0. + * + * When 'cleanupEnabled' is false, refrain from deleting any old WAL segments + * in the archive. This is used when fetching the initial checkpoint record, + * when we are not yet sure how far back we need the WAL. */ bool RestoreArchivedFile(char *path, const char *xlogfname, - const char *recovername, off_t expectedSize) + const char *recovername, off_t expectedSize, + bool cleanupEnabled) { char xlogpath[MAXPGPATH]; char xlogRestoreCmd[MAXPGPATH]; @@ -113,9 +118,10 @@ RestoreArchivedFile(char *path, const char *xlogfname, * replication. All files earlier than this point can be deleted from the * archive, though there is no requirement to do so. * - * We initialise this with the filename of an InvalidXLogRecPtr, which - * will prevent the deletion of any WAL files from the archive because of - * the alphabetic sorting property of WAL filenames. + * If cleanup is not enabled, initialise this with the filename of + * InvalidXLogRecPtr, which will prevent the deletion of any WAL files + * from the archive because of the alphabetic sorting property of WAL + * filenames. * * Once we have successfully located the redo pointer of the checkpoint * from which we start recovery we never request a file prior to the redo @@ -124,9 +130,9 @@ RestoreArchivedFile(char *path, const char *xlogfname, * flags to signify the point when we can begin deleting WAL files from * the archive. */ - GetOldestRestartPoint(&restartRedoPtr, &restartTli); - if (!XLogRecPtrIsInvalid(restartRedoPtr)) + if (cleanupEnabled) { + GetOldestRestartPoint(&restartRedoPtr, &restartTli); XLByteToSeg(restartRedoPtr, restartSegNo); XLogFileName(lastRestartPointFname, restartTli, restartSegNo); /* we shouldn't need anything earlier than last restart point */ |