| From: | Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com> |
|---|---|
| To: | Amit Kapila <amit(dot)kapila16(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-18 14:15:17 |
| Message-ID: | av2y9Xr1eUxD6VU1@bdtpg |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
On Mon, Nov 16, 2026 at 03:46:25PM +0530, Amit Kapila wrote:
> On Tue, Nov 10, 2026 at 7:44 PM Bertrand Drouvot
> > 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.
Thanks for looking at it!
I think that could be too late. With parallel streaming, a parallel apply worker
may already have executed the transaction's changes.
So, in the attached, I went with checking the slot property after acquiring the
slot, before decoding starts. A PENDING subscription requires two_phase to remain
disabled until table synchronization is complete. Once ready, START_REPLICATION
can enable it.
The patches therefore add slot_failover and slot_two_phase pgoutput options to
validate the current slot properties without changing them.
For older publishers, the patches preserve the existing behavior and leave the
user responsible for ensuring that the values match. I also considered querying
pg_replication_slots before START_REPLICATION. That would provide useful best
effort validation, but the slot could be changed or recreated between the query
and its acquisition. I decided not to include it. What do you think?
> 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.
Yeah, a failover mismatch does not have the same immediate consequences as a
two_phase mismatch, but I think an ERROR is still preferable. For example, it can
prevent replication from resuming after promotion.
Also, since the documentation requires the values to match, I don't think we
should let replication continue with a mismatched configuration.
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Detect-mismatched-subscription-and-slot-failover-.patch | text/x-diff | 19.7 KB |
| v1-0002-Detect-mismatched-subscription-and-slot-two_phase.patch | text/x-diff | 21.3 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Heikki Linnakangas | 2026-11-18 14:25:17 | Re: Compile warnings under -DMEMORY_CONTEXT_CHECKING and no assertions |
| Previous Message | Heikki Linnakangas | 2026-11-18 14:14:28 | Re: CI slowdown due to PG_TEST_INITDB_EXTRA_OPTS |