Reset conflict slot's xmin when a subscription (re)starts retention. Since the retain_dead_tuples feature uses a single cluster-wide replication slot across all subscriptions, adding a new subscription on a database with an older active transaction can require conflict_detection_slot.xmin to move backward to avoid missing dead tuples needed for update_deleted conflict detection.
Previously, if a newly created subscription had an older active transaction than the slot's current xmin, the slot update occurred during worker apply, leading to an assertion failure. Fix this by having the launcher track the set of databases with active tuple-retaining subscriptions. When a database joins this set (either via a new subscription or when retention restarts), the launcher resets the slot's xmin to the cluster-wide safe decoding horizon before starting any workers. Because this horizon accounts for all active transactions across the entire cluster, it serves as a safe seed without requiring retroactive backward movement by individual apply workers. In passing, update the retain_dead_tuples documentation to clarify two operational boundary cases: (a) Conflict data continues to accumulate even when a subscription is disabled or its apply worker is stopped. (b) track_commit_timestamp must be enabled for conflict detection to function properly. Reported-by: Nisha Moond <[email protected]> Author: Zhijie Hou <[email protected]> Author: Amit Kapila <[email protected]> Reviewed-by: Amit Kapila <[email protected]> Reviewed-by: Nisha Moond <[email protected]> Reviewed-by: shveta malik <[email protected]> Reviewed-by: Hayato Kuroda <[email protected]> Discussion: https://postgr.es/m/ty4pr01mb177182f547a62fc2666ec04ec94...@ty4pr01mb17718.jpnprd01.prod.outlook.com Backpatch-through: 19, where it was introduced Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/6168c65ddcac4494fb292418cc774897791e0667 Modified Files -------------- doc/src/sgml/ref/create_subscription.sgml | 31 +++++- src/backend/replication/logical/launcher.c | 173 ++++++++++++++++++++--------- src/test/subscription/t/035_conflicts.pl | 73 ++++++++++++ 3 files changed, 221 insertions(+), 56 deletions(-)
