aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFujii Masao <fujii@postgresql.org>2020-09-29 16:21:46 +0900
committerFujii Masao <fujii@postgresql.org>2020-09-29 16:23:57 +0900
commit059caf36c3074afd998b6e5f36ea9da460dcaee8 (patch)
treed31eff95171d21c830a7e0bb71223ad6a4022817
parent1aedaba78aa8617b24b7a703abd1359f9d78f62a (diff)
downloadpostgresql-059caf36c3074afd998b6e5f36ea9da460dcaee8.tar.gz
postgresql-059caf36c3074afd998b6e5f36ea9da460dcaee8.zip
Archive timeline history files in standby if archive_mode is set to "always".
Previously the standby server didn't archive timeline history files streamed from the primary even when archive_mode is set to "always", while it archives the streamed WAL files. This could cause the PITR to fail because there was no required timeline history file in the archive. The cause of this issue was that walreceiver didn't mark those files as ready for archiving. This commit makes walreceiver mark those streamed timeline history files as ready for archiving if archive_mode=always. Then the archiver process archives the marked timeline history files. Back-patch to all supported versions. Reported-by: Grigory Smolkin Author: Grigory Smolkin, Fujii Masao Reviewed-by: David Zhang, Anastasia Lubennikova Discussion: https://postgr.es/m/54b059d4-2b48-13a4-6f43-95a087c92367@postgrespro.ru
-rw-r--r--doc/src/sgml/high-availability.sgml3
-rw-r--r--src/backend/replication/walreceiver.c9
2 files changed, 11 insertions, 1 deletions
diff --git a/doc/src/sgml/high-availability.sgml b/doc/src/sgml/high-availability.sgml
index c2f13ff16a9..1fd57aa3029 100644
--- a/doc/src/sgml/high-availability.sgml
+++ b/doc/src/sgml/high-availability.sgml
@@ -1396,7 +1396,8 @@ synchronous_standby_names = 'ANY 2 (s1, s2, s3)'
If <varname>archive_mode</varname> is set to <literal>on</literal>, the
archiver is not enabled during recovery or standby mode. If the standby
server is promoted, it will start archiving after the promotion, but
- will not archive any WAL it did not generate itself. To get a complete
+ will not archive any WAL or timeline history files that
+ it did not generate itself. To get a complete
series of WAL files in the archive, you must ensure that all WAL is
archived, before it reaches the standby. This is inherently true with
file-based log shipping, as the standby can only restore files that
diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c
index d1ad75da87a..a6c0351c815 100644
--- a/src/backend/replication/walreceiver.c
+++ b/src/backend/replication/walreceiver.c
@@ -761,6 +761,15 @@ WalRcvFetchTimeLineHistoryFiles(TimeLineID first, TimeLineID last)
*/
writeTimeLineHistoryFile(tli, content, len);
+ /*
+ * Mark the streamed history file as ready for archiving
+ * if archive_mode is always.
+ */
+ if (XLogArchiveMode != ARCHIVE_MODE_ALWAYS)
+ XLogArchiveForceDone(fname);
+ else
+ XLogArchiveNotify(fname);
+
pfree(fname);
pfree(content);
}