| From: | Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> |
|---|---|
| To: | Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org, Zhijie Hou <houzhijie22(at)gmail(dot)com> |
| Subject: | Re: Detect mismatched subscription and replication slot properties |
| Date: | 2026-11-16 10:16:25 |
| Message-ID: | CAA4eK1LkvcxCkW0rm=q89wqbSTa0aFoePK-G2Sv3OBegn8LyeA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Tue, Nov 10, 2026 at 7:44 PM Bertrand Drouvot
<bertranddrouvot(dot)pg(at)gmail(dot)com> wrote:
>
> Hi hackers,
>
> This is a follow-up to the discussion at [1]. The issue raised was that, when the
> subscription's two phase state is already ENABLED, changing slot_name together
> with two_phase = true can succeed even though the replacement slot has two_phase
> = false.
>
> Although, the possibility of such a mismatch is documented [2], it does not sound
> ideal.
>
> The same issue exists for both two_phase and failover. The consequences are real:
> a mismatch can prevent replication from resuming after promotion or cause incorrect
> two phase transaction handling, potentially resulting in duplicate data.
>
> I initially thought about validating the properties during ALTER SUBSCRIPTION,
> but the slot selected by the apply worker, or its properties, can change
> independently of that command. Such a check could therefore already be stale when
> the slot is used.
>
> I wonder if it wouldn't make more sense to validate both properties when the main
> apply worker starts replication? At that point the actual publisher and slot are
> known. Ideally, the publisher would perform the validation after acquiring the
> slot and before decoding starts. This would only validate the properties, not
> modify them.
>
> For failover, the value should match exactly.
>
> For two_phase, the expected value depends on subtwophasestate:
>
> • DISABLED: the slot must have two_phase = false.
> • PENDING, before the tables are ready: it must remain false.
> • PENDING, once the tables are ready: either value can be accepted before enabling
> it and recording the state as ENABLED. This also makes the transition safe if the
> worker previously exited between those two operations.
> • ENABLED: the slot must have two_phase = true.
>
Instead of PENDING state checks, how about checking mismatch in
begin_prepared kind of functions whether the subscription has reached
ENABLED state? I am asking this because if the slot is initially
created with two_phase = true and the subscription is in pending state
then the apply worker will start receiving prepared transactions and
will lead to problems described under "TWO_PHASE TRANSACTIONS" in
worker.c.
> A persistent mismatch would cause the apply worker to fail each time it is restarted,
> so we would also need to consider disable_on_error, apply_error_count, and the
> resulting log messages. We would also need to consider how to handle a subscriber
> connecting to an older publisher.
>
> A related approach was discussed in [3], where Hou-san proposed updating the
> slot's failover property at each apply worker startup. What I have in mind here
> is different: only report an error, without modifying the slot properties.
>
> I'm not sharing any patch at this stage, just checking if this approach makes
> sense?
>
I think this makes sense to me. In general, we rely on users to set up
a logical-replication as desired, otherwise, it could easily lead to
non-recoverable situations (the data won't be replicated as expected
or could lead to ERRORs). For example, source and target schema must
match, appropriate privileges on the target table, the publications
should exist, etc. Having said that, it is good to tighten the
mismatch between pub-sub where possible without adding too much
complexity in the code.
If we want to proceed with this, then we should consider whether the
mismatch in 'failover' property should be an ERROR or a simple
'WARNING' as that won't immediately lead to data inconsistency or such
issues.
--
With Regards,
Amit Kapila.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Shlok Kyal | 2026-11-16 10:38:43 | Re: Initial table sync copies the whole table when it is no longer published |
| Previous Message | Dean Rasheed | 2026-11-16 10:07:50 | Re: [PATCH] Normalize numeric/bigint scientific notation after rounding |