Re: Replication slot is not able to sync up - Mailing list pgsql-hackers

From Amit Kapila
Subject Re: Replication slot is not able to sync up
Date
Msg-id CAA4eK1J=vJ0UhkFppwykN+KtDPri-r_XeB6fhbw5o0Y4tGe8CQ@mail.gmail.com
Whole thread Raw
In response to Re: Replication slot is not able to sync up  (Amit Kapila <amit.kapila16@gmail.com>)
List pgsql-hackers
On Fri, May 30, 2025 at 4:05 PM Amul Sul <sulamul@gmail.com> wrote:
>
> Quick question -- due to my limited understanding of this area: why
> can't we perform an action similar to pg_logical_slot_get_changes()
> implicitly from pg_sync_replication_slots()? Would there be any
> implications of doing so?
>

Yes, there would be implications if we did it that way. It would mean
that the consumer of the slot may not process those changes (for which
sync_slot API has done the get_changes) and send it to the client.
Consider a publisher-subscriber and physical standby setup. In this
setup, the subscriber creates a logical slot corresponding to the
subscription on the publisher. Now, the publisher process changes and
sends it to the subscriber; then the slot is advanced (both its xmin
and WAL locations) once the corresponding changes are sent to the
client.

If we allow pg_sync_replication_slots() to do
pg_logical_slot_get_changes or equivalent in some way, then we may end
up advancing the slot without sending the changes to the subscriber,
which would be considered a data loss for the subscriber.

I have explained in terms of built-in logical replication, but the
external plugins using these APIs (pg_logical_*) should be doing
something similar to process the changes and advance the slot.

Does this answer your question and make sense to you?

--
With Regards,
Amit Kapila.



pgsql-hackers by date:

Previous
From: Daniil Davydov
Date:
Subject: Speedup truncations of temporary relation forks
Next
From: David Rowley
Date:
Subject: Re: Add comment explaining why queryid is int64 in pg_stat_statements