Re: Logical Replication slot disappeared after promote Standby - Mailing list pgsql-hackers

From Amit Kapila
Subject Re: Logical Replication slot disappeared after promote Standby
Date
Msg-id CAA4eK1L7BPjJ=orDuMCnk+EaeajYPC2r3u-fupBAnL2Pg=74ug@mail.gmail.com
Whole thread Raw
In response to Re: Logical Replication slot disappeared after promote Standby  (Perumal Raj <perucinci@gmail.com>)
Responses Resolved: Logical Replication slot disappeared after promote Standby
List pgsql-hackers
On Fri, Jun 13, 2025 at 10:52 PM Perumal Raj <perucinci@gmail.com> wrote:
>
> Thanks for explanation Shveta!
>
> ------------
> As Summary in this original thread,
>
> Prerequisites for Setting Up a Logical Replication Slot sync in >= pg17
>
> To successfully configure a logical replication slot, ensure the following settings are applied:
>
> wal_level = 'logical'
> hot_standby = 'on'
> hot_standby_feedback = 'on'
> sync_replication_slots = 'on'
>

Additionally, you need to configure primary_slot_name on the standby
and have dbname in primary_conninfo. For further details, you can
refer docs (1)(2).

> Replication Slot Synchronization
>
> Logical replication slots can synchronize with all direct standby servers of the primary but are not compatible with
cascadestandby servers. 
>
> Temporary Status of New Standby Slots
>
> If a new standby server is created after the logical replication slot, it will be marked as temporary=true until the
reset_lsnof the primary matches the confirmed_lsn of the new standby. 
>

It is restart_lsn on both nodes, but there are other things like
slot's catalog_xmin as well. As a user, you need to ensure that your
primary's logical slot is being consumed. And this is required
primarily at the initial sync time so that we sync the slot only if
the standby has required resources like WAL to allow decoding from the
synced slot after failover.

> Limitations on Using Logical Replication Slots
>
> While logical replication slots can synchronize on the direct standby side, they cannot be utilized (as in the case
ofDebezium) until the standby server is promoted to primary. Attempting to use a synchronized logical slot on a standby
serverwill result in the following error: 
>
> org.postgresql.util.PSQLException: ERROR: cannot use replication slot "kafka_logical_slot" for logical decoding
> Detail: This replication slot is being synchronized from the primary server.
>

I don't think we can call this a limitation. According to me, this is
a requirement for this feature to work. Consider if we allow the use
of this synced slot for decoding when sync is still in-progress, this
slot could be advanced ahead of the primary. Now, after the failover,
we won't be able to reuse this slot to allow the subscribers to
continue replication.

(1) -
https://www.postgresql.org/docs/devel/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS-SYNCHRONIZATION
(2) - https://www.postgresql.org/docs/devel/logical-replication-failover.html

--
With Regards,
Amit Kapila.



pgsql-hackers by date:

Previous
From: Junwang Zhao
Date:
Subject: Re: Add a bound check to TidRangeEval
Next
From: David Rowley
Date:
Subject: Re: Add a bound check to TidRangeEval