🌐 AI搜索 & 代理 主页
Skip to content

Commit 0d2d4a0

Browse files
author
Amit Kapila
committed
Add retry logic to pg_sync_replication_slots().
Previously, pg_sync_replication_slots() would finish without synchronizing slots that didn't meet requirements, rather than failing outright. This could leave some failover slots unsynchronized if required catalog rows or WAL segments were missing or at risk of removal, while the standby continued removing needed data. To address this, the function now waits for the primary slot to advance to a position where all required data is available on the standby before completing synchronization. It retries cyclically until all failover slots that existed on the primary at the start of the call are synchronized. Slots created after the function begins are not included. If the standby is promoted during this wait, the function exits gracefully and the temporary slots will be removed. Author: Ajin Cherian <itsajin@gmail.com> Author: Hou Zhijie <houzj.fnst@fujitsu.com> Reviewed-by: Shveta Malik <shveta.malik@gmail.com> Reviewed-by: Japin Li <japinli@hotmail.com> Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> Reviewed-by: Ashutosh Sharma <ashu.coek88@gmail.com> Reviewed-by: Chao Li <li.evan.chao@gmail.com> Reviewed-by: Yilin Zhang <jiezhilove@126.com> Reviewed-by: Amit Kapila <amit.kapila16@gmail.com> Discussion: https://postgr.es/m/CAFPTHDZAA%2BgWDntpa5ucqKKba41%3DtXmoXqN3q4rpjO9cdxgQrw%40mail.gmail.com
1 parent 33980ea commit 0d2d4a0

File tree

5 files changed

+245
-60
lines changed

5 files changed

+245
-60
lines changed

doc/src/sgml/func/func-admin.sgml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,9 +1497,7 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset
14971497
standby server. Temporary synced slots, if any, cannot be used for
14981498
logical decoding and must be dropped after promotion. See
14991499
<xref linkend="logicaldecoding-replication-slots-synchronization"/> for details.
1500-
Note that this function is primarily intended for testing and
1501-
debugging purposes and should be used with caution. Additionally,
1502-
this function cannot be executed if
1500+
Note that this function cannot be executed if
15031501
<link linkend="guc-sync-replication-slots"><varname>
15041502
sync_replication_slots</varname></link> is enabled and the slotsync
15051503
worker is already running to perform the synchronization of slots.

doc/src/sgml/logicaldecoding.sgml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -405,15 +405,13 @@ postgres=# SELECT * from pg_logical_slot_get_changes('regression_slot', NULL, NU
405405
periodic synchronization of failover slots, they can also be manually
406406
synchronized using the <link linkend="pg-sync-replication-slots">
407407
<function>pg_sync_replication_slots</function></link> function on the standby.
408-
However, this function is primarily intended for testing and debugging and
409-
should be used with caution. Unlike automatic synchronization, it does not
410-
include cyclic retries, making it more prone to synchronization failures,
411-
particularly during initial sync scenarios where the required WAL files
412-
or catalog rows for the slot might have already been removed or are at risk
413-
of being removed on the standby. In contrast, automatic synchronization
414-
via <varname>sync_replication_slots</varname> provides continuous slot
415-
updates, enabling seamless failover and supporting high availability.
416-
Therefore, it is the recommended method for synchronizing slots.
408+
However, unlike automatic synchronization, it does not perform incremental
409+
updates. It retries cyclically until all the failover slots that existed on
410+
primary at the start of the function call are synchronized. Any slots created
411+
after the function begins will not be synchronized. In contrast, automatic
412+
synchronization via <varname>sync_replication_slots</varname> provides
413+
continuous slot updates, enabling seamless failover and supporting high
414+
availability. Therefore, it is the recommended method for synchronizing slots.
417415
</para>
418416
</note>
419417

0 commit comments

Comments
 (0)