Archive timeline history files in standby if archive_mode is set to "always".
authorFujii Masao <[email protected]>
Tue, 29 Sep 2020 07:21:46 +0000 (16:21 +0900)
committerFujii Masao <[email protected]>
Tue, 29 Sep 2020 07:25:51 +0000 (16:25 +0900)
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

doc/src/sgml/high-availability.sgml
src/backend/replication/walreceiver.c

index a4e5ed219018d6b41c9ea3355e725434de04740a..6e893b0efe8c9ebba8d11dd1727dda9816686210 100644 (file)
@@ -1248,7 +1248,8 @@ primary_slot_name = 'node_a_slot'
      If <varname>archive_mode</varname> is set to <literal>on</>, 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
index 7a198910c4aa016b828694daf5d68c8203a21c88..37ffad6c7b3668ddf3b4598415c2a53531af86f2 100644 (file)
@@ -686,6 +686,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);
        }