Re: Fix slot synchronization with two_phase decoding enabled
Nisha Moond <nisha.moond412@gmail.com>
From: Nisha Moond <nisha.moond412@gmail.com>
To: Amit Kapila <amit.kapila16@gmail.com>
Cc: Masahiko Sawada <sawada.mshk@gmail.com>,
shveta malik <shveta.malik@gmail.com>, "Zhijie Hou (Fujitsu)" <houzj.fnst@fujitsu.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-06-03T05:35:07Z
Lists: pgsql-hackers
Attachments
- v17-0001-PG17-Approach-3-Fix-slot-synchronization-for-two.patch (application/octet-stream) patch v17-0001
- v17-0002-Fix-for-pg_dump.patch (application/octet-stream) patch v17-0002
On Mon, Jun 2, 2025 at 10:55 AM Amit Kapila <amit.kapila16@gmail.com> wrote: > > On Fri, May 30, 2025 at 3:00 PM Nisha Moond <nisha.moond412@gmail.com> wrote: > > > > Agree that we need to cover the simple pg_dump and pg_restore with the patch. > > > > When pg_dump and pg_restore are used outside of pg_upgrade, there's no > > guarantee that the target system does not have any prepared > > transactions. In such cases, restoring a subscription with both > > two_phase and failover enabled could lead to the bug, so we should > > avoid allowing both options via pg_restore. > > > > Here are a few possible solutions: > > > > 1) Split the CREATE SUBSCRIPTION command of such subscriptions in pg_restore : > > first create the sub with two_phase: > > - CREATE SUBSCRIPTION ... with (two_phase = on) > > then enable failover > > - ALTER SUBSCRIPTION ... with (failover=true) > > > > This won't work because we always dump a subscription with the > 'connect' option as 'false'. As changing the subscription's failover > option, needs the connection above split won't work. > > > However, this approach adds complexity in pg_restore and may still > > fail if the slot's restart_lsn is earlier than two_phase_at. > > > > 2) Prevent dump of subscription in non-upgrade mode: > > Raise an error/warning during pg_dump when a subscription with both > > two_phase and failover is encountered (unless in binary upgrade mode). > > That is, either fail the pg_dump, or skip dumping subscriptions in > > such a case with a warning. > > We can include a helpful hint: > > "Disable failover for subscription <sub-name> before dumping and > > re-enable it after restore." > > > > 3) Dump such subscriptions with (two_phase=on, failover=on, > > create_slot=false) together. As pg_dump always sets "connect=false" > > for subscription, it is up to users to reactivate the subscription > > suitably. In this case, we can add some document to warn that it's the > > user's responsibility to ensure the remote slot is in a safe state. > > > > What do you think? > > > > Please let me know if you have any other suggestions for handling this > > in pg_dump/pg_restore. > > > > Yet another idea is to dump the subscription with two_phase = on and > failover = false. We should do this when both options are 'true' > during the dump. As we are documenting that we always dump > createsubscription with connect as false and let users take care (see > [1] (When dumping logical replication subscriptions ...)), a similar > reasoning could be given for the failover flag. > +1 > The one more combination to consider is when someone takes a dump of > an older version and loads it into a newer version. For example, where > users dump from 17.5 and then restore in a newer version, say 17.6 > (which has our fix), the restore will fail due to newer restrictions > added by this patch. Do we need to do anything about it? > > [1] : https://www.postgresql.org/docs/devel/app-pgdump.html > ~~~ Attached v17 patches. Added a top-up patch 0002 implementing the idea suggested by Amit above. Thanks, Nisha
Commits
-
Don't retreat slot's confirmed_flush LSN.
- ad5eaf390c58 18.0 landed
- 7318f241d29c 17.6 landed
- c0f51fde534d 16.10 landed
- 9d1a62359606 15.14 landed
- e68459489c20 14.19 landed
- e323d9df002d 13.22 landed
-
Fix assertion failure during decoding from synced slots.
- 3ff2a1f0c9e8 18.0 landed
-
Fix xmin advancement during fast_forward decoding.
- d65485b02b1f 13.21 landed
- aaf9e95e8764 18.0 landed
- 36148b22ee09 17.5 landed
- 21a7caeeb948 16.9 landed
- f6429bd7db5e 15.13 landed
- 1f63b3626a52 14.18 landed
-
Fix slot synchronization for two_phase enabled slots.
- 4868c96bc8c6 18.0 landed
-
Again match pg_user_mappings to information_schema.user_mapping_options.
- b6e39ca92eee 9.4.13 cited