aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/transam/xlogarchive.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2018-09-28 11:54:38 +0900
committerMichael Paquier <michael@paquier.xyz>2018-09-28 11:54:38 +0900
commit78ea8b5daab9237fd42d7a8a836c1c451765499f (patch)
tree20ab90ebaf38571cb9f47d5256f276bad6140583 /src/backend/access/transam/xlogarchive.c
parentaaf10f32a308bc5f53772c773edf3f345f59bb74 (diff)
downloadpostgresql-78ea8b5daab9237fd42d7a8a836c1c451765499f.tar.gz
postgresql-78ea8b5daab9237fd42d7a8a836c1c451765499f.zip
Fix WAL recycling on standbys depending on archive_mode
A restart point or a checkpoint recycling WAL segments treats segments marked with neither ".done" (archiving is done) or ".ready" (segment is ready to be archived) in archive_status the same way for archive_mode being "on" or "always". While for a primary this is fine, a standby running a restart point with archive_mode = on would try to mark such a segment as ready for archiving, which is something that will never happen except after the standby is promoted. Note that this problem applies only to WAL segments coming from the local pg_wal the first time archive recovery is run. Segments part of a self-contained base backup are the most common case where this could happen, however even in this case normally the .done markers would be most likely part of the backup. Segments recovered from an archive are marked as .ready or .done by the startup process, and segments finished streaming are marked as such by the WAL receiver, so they are handled already. Reported-by: Haruka Takatsuka Author: Michael Paquier Discussion: https://postgr.es/m/15402-a453c90ed4cf88b2@postgresql.org Backpatch-through: 9.5, where archive_mode = always has been added.
Diffstat (limited to 'src/backend/access/transam/xlogarchive.c')
-rw-r--r--src/backend/access/transam/xlogarchive.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/backend/access/transam/xlogarchive.c b/src/backend/access/transam/xlogarchive.c
index 4a039b11901..d40317168e2 100644
--- a/src/backend/access/transam/xlogarchive.c
+++ b/src/backend/access/transam/xlogarchive.c
@@ -620,9 +620,16 @@ XLogArchiveCheckDone(const char *xlog)
{
char archiveStatusPath[MAXPGPATH];
struct stat stat_buf;
+ bool inRecovery = RecoveryInProgress();
- /* Always deletable if archiving is off */
- if (!XLogArchivingActive())
+ /*
+ * The file is always deletable if archive_mode is "off". On standbys
+ * archiving is disabled if archive_mode is "on", and enabled with
+ * "always". On a primary, archiving is enabled if archive_mode is "on"
+ * or "always".
+ */
+ if (!((XLogArchivingActive() && !inRecovery) ||
+ (XLogArchivingAlways() && inRecovery)))
return true;
/* First check for .done --- this means archiver is done with it */