Skip to content

Commit 462ff79

Browse files
committed
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
1 parent dd89ba5 commit 462ff79

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

doc/src/sgml/high-availability.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,8 @@ synchronous_standby_names = 'ANY 2 (s1, s2, s3)'
13891389
If <varname>archive_mode</varname> is set to <literal>on</literal>, the
13901390
archiver is not enabled during recovery or standby mode. If the standby
13911391
server is promoted, it will start archiving after the promotion, but
1392-
will not archive any WAL it did not generate itself. To get a complete
1392+
will not archive any WAL or timeline history files that
1393+
it did not generate itself. To get a complete
13931394
series of WAL files in the archive, you must ensure that all WAL is
13941395
archived, before it reaches the standby. This is inherently true with
13951396
file-based log shipping, as the standby can only restore files that

src/backend/replication/walreceiver.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,15 @@ WalRcvFetchTimeLineHistoryFiles(TimeLineID first, TimeLineID last)
747747
*/
748748
writeTimeLineHistoryFile(tli, content, len);
749749

750+
/*
751+
* Mark the streamed history file as ready for archiving
752+
* if archive_mode is always.
753+
*/
754+
if (XLogArchiveMode != ARCHIVE_MODE_ALWAYS)
755+
XLogArchiveForceDone(fname);
756+
else
757+
XLogArchiveNotify(fname);
758+
750759
pfree(fname);
751760
pfree(content);
752761
}

0 commit comments

Comments
 (0)