Skip to content

Commit f2e41d9

Browse files
author
Amit Kapila
committed
Doc: Improve logical replication failover documentation.
Clarified that the failover steps apply to a specific PostgreSQL subscriber and added guidance for verifying replication slot synchronization during planned failover. Additionally, corrected the standby query to avoid false positives by checking invalidation_reason IS NULL instead of conflicting. Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> Author: Shveta Malik <shveta.malik@gmail.com> Backpatch-through: 17, where it was introduced Discussion: https://www.postgresql.org/message-id/CAExHW5uiZ-fF159=jwBwPMbjZeZDtmcTbN+hd4mrURLCg2uzJg@mail.gmail.com
1 parent 95cf1a1 commit f2e41d9

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

doc/src/sgml/logical-replication.sgml

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,8 @@ ALTER SUBSCRIPTION
714714
</para>
715715

716716
<para>
717-
To confirm that the standby server is indeed ready for failover, follow these
718-
steps to verify that all necessary logical replication slots have been
717+
To confirm that the standby server is indeed ready for failover for a given subscriber, follow these
718+
steps to verify that all the logical replication slots required by that subscriber have been
719719
synchronized to the standby server:
720720
</para>
721721

@@ -769,7 +769,7 @@ test_sub=# SELECT
769769
Check that the logical replication slots identified above exist on
770770
the standby server and are ready for failover.
771771
<programlisting>
772-
test_standby=# SELECT slot_name, (synced AND NOT temporary AND NOT conflicting) AS failover_ready
772+
test_standby=# SELECT slot_name, (synced AND NOT temporary AND invalidation_reason IS NULL) AS failover_ready
773773
FROM pg_replication_slots
774774
WHERE slot_name IN
775775
('sub1','sub2','sub3', 'pg_16394_sync_16385_7394666715149055164');
@@ -787,10 +787,42 @@ test_standby=# SELECT slot_name, (synced AND NOT temporary AND NOT conflicting)
787787
<para>
788788
If all the slots are present on the standby server and the result
789789
(<literal>failover_ready</literal>) of the above SQL query is true, then
790-
existing subscriptions can continue subscribing to publications now on the
791-
new primary server.
790+
existing subscriptions can continue subscribing to publications on the new
791+
primary server.
792+
</para>
793+
794+
<para>
795+
The first two steps in the above procedure are meant for a
796+
<productname>PostgreSQL</productname> subscriber. It is recommended to run
797+
these steps on each subscriber node, that will be served by the designated
798+
standby after failover, to obtain the complete list of replication
799+
slots. This list can then be verified in Step 3 to ensure failover readiness.
800+
Non-<productname>PostgreSQL</productname> subscribers, on the other hand, may
801+
use their own methods to identify the replication slots used by their
802+
respective subscriptions.
803+
</para>
804+
805+
<para>
806+
In some cases, such as during a planned failover, it is necessary to confirm
807+
that all subscribers, whether <productname>PostgreSQL</productname> or
808+
non-<productname>PostgreSQL</productname>, will be able to continue
809+
replication after failover to a given standby server. In such cases, use the
810+
following SQL, instead of performing the first two steps above, to identify
811+
which replication slots on the primary need to be synced to the standby that
812+
is intended for promotion. This query returns the relevant replication slots
813+
associated with all the failover-enabled subscriptions.
792814
</para>
793815

816+
<para>
817+
<programlisting>
818+
/* primary # */ SELECT array_agg(quote_literal(r.slot_name)) AS slots
819+
FROM pg_replication_slots r
820+
WHERE r.failover AND NOT r.temporary;
821+
slots
822+
-------
823+
{'sub1','sub2','sub3', 'pg_16394_sync_16385_7394666715149055164'}
824+
(1 row)
825+
</programlisting></para>
794826
</sect1>
795827

796828
<sect1 id="logical-replication-row-filter">

0 commit comments

Comments
 (0)