pg_upgrade does not preserve subretentionactive, so a subscription whose dead-tuple retention had stopped (max_retention_duration exceeded) comes back retaining; if disabled it pins pg_conflict_detection xmin indefinitely and VACUUM stops removing dead tuples =================================================================================================================================================================================================================================================================== AI-generated bug report from the AI Annex Report ID: 01a21b69-9aa2-7f87-9e23-865a3aa92f97 Filed: 2026-11-27 05:10:35 UTC Severity: 27/100 Blamed commit: a850be2fe653b3b529969946c1cefe0fd9e34a8d ## Summary When a subscription with `retain_dead_tuples = true` and a non-zero `max_retention_duration` exceeds that duration, the apply worker sets `pg_subscription.subretentionactive = false` and the launcher clears the xmin of the `pg_conflict_detection` slot, so VACUUM can remove dead tuples again. pg_dump (including `--binary-upgrade`, used by pg_upgrade) does not dump `subretentionactive`. The subscription is re-created with `CREATE SUBSCRIPTION ... WITH (retain_dead_tuples = true, ...)`, which always sets `subretentionactive = true`. After the upgrade, retention is active again although the old cluster had stopped it. If the subscription is disabled, this is persistent: the launcher seeds the conflict slot xmin and never advances it, because a retention-active subscription that is disabled blocks `can_update_xmin`. VACUUM then cannot remove any dead tuples newer than that xmin, in any database, until the user enables the subscription or toggles `retain_dead_tuples`. Before the upgrade the same cluster had no xmin held. If the subscription is enabled, retention restarts and only stops again once the duration is exceeded again. The documentation for `max_retention_duration` lists when retention resumes on its own: an apply worker confirms that the duration is within the limit, a new subscription is created with `retain_dead_tuples = true`, or the user re-enables `retain_dead_tuples`. An upgrade is not among them, and the binary-upgrade dump already takes care to keep the subscription's enabled state. ## Reproduction Publisher (wal_level = logical), port 5432: ```sql CREATE TABLE t (a int PRIMARY KEY, b int); CREATE PUBLICATION pb FOR TABLE t; SELECT pg_create_physical_replication_slot('blocker'); ``` Subscriber (wal_level = logical, track_commit_timestamp = on), port 5433: ```sql CREATE TABLE t (a int PRIMARY KEY, b int); CREATE TABLE loc (a int); CREATE SUBSCRIPTION sb CONNECTION 'port=5432 dbname=postgres' PUBLICATION pb WITH (retain_dead_tuples = true, failover = true); ``` Make retention stop. As in the existing TAP test, an inactive slot in `synchronized_standby_slots` on the publisher blocks progress: ```sql -- publisher ALTER SYSTEM SET synchronized_standby_slots = 'blocker'; SELECT pg_reload_conf(); INSERT INTO t VALUES (1000, 1); -- subscriber SELECT txid_current(); ALTER SUBSCRIPTION sb SET (max_retention_duration = 1); -- wait for "has stopped retaining the information for detecting -- conflicts" in the subscriber log SELECT subretentionactive FROM pg_subscription; -- f SELECT xmin FROM pg_replication_slots WHERE slot_name = 'pg_conflict_detection'; -- NULL ALTER SUBSCRIPTION sb DISABLE; INSERT INTO loc SELECT generate_series(1, 1000); DELETE FROM loc; VACUUM (VERBOSE) loc; -- tuples: 1000 removed ``` Stop the subscriber, run pg_upgrade into a freshly initdb'd cluster (same version is enough), start the new cluster, then: ```sql SELECT subenabled, submaxretention, subretentionactive FROM pg_subscription; -- f | 1 | t (expected: f | 1 | f) SELECT xmin FROM pg_replication_slots WHERE slot_name = 'pg_conflict_detection'; -- 700 (expected: NULL) INSERT INTO loc SELECT generate_series(1, 1000); DELETE FROM loc; VACUUM (VERBOSE) loc; -- tuples: 0 removed, 1000 remain, 1000 are dead but not yet removable -- removable cutoff: 700 ``` The xmin stays at 700 indefinitely while the subscription is disabled. ## Analysis `subretentionactive` was added together with `max_retention_duration` in the blamed commit. `getSubscriptions()` / `dumpSubscription()` in `src/bin/pg_dump/pg_dump.c` dump `retain_dead_tuples` and `max_retention_duration` but not the retention state, and `CreateSubscription()` sets `subretentionactive` to `opts.retaindeadtuples`. There is no way to restore a stopped state through SQL, so the binary-upgrade dump would need a support function (as done for the origin remote_lsn) or another way to carry the flag over. On the new cluster, `ApplyLauncherMain()` sees a retention-active, disabled subscription: it calls `CreateConflictDetectionSlot()`, resets the slot xmin to the safe horizon for a newly retained database, and then keeps `can_update_xmin` false because `sub->enabled` is false, so the xmin is never advanced or cleared. A plain dump and restore re-creates the subscription the same way (from reading the code; not run separately). ## Notes - Tested on master ad33a140c76f53d66f37330edfa47c5d96e2d6ce. - Workaround: after the upgrade, enable the subscription or run `ALTER SUBSCRIPTION ... SET (retain_dead_tuples = false)` then `true`. - Related report on another subscription field missing from pg_dump: https://ai-annex.j-davis.com/report/01a21695-1d03-78bc-a968-e73aec374d20 (conflict_log_destination; different column and commit). Branches: REL_19 and master (max_retention_duration is new in 19).