Add max_retention_duration option to subscriptions. This commit introduces a new subscription parameter, max_retention_duration, aimed at mitigating excessive accumulation of dead tuples when retain_dead_tuples is enabled and the apply worker lags behind the publisher.
When the time spent advancing a non-removable transaction ID exceeds the max_retention_duration threshold, the apply worker will stop retaining conflict detection information. In such cases, the conflict slot's xmin will be set to InvalidTransactionId, provided that all apply workers associated with the subscription (with retain_dead_tuples enabled) confirm the retention duration has been exceeded. To ensure retention status persists across server restarts, a new column subretentionactive has been added to the pg_subscription catalog. This prevents unnecessary reactivation of retention logic after a restart. The conflict detection slot will not be automatically re-initialized unless a new subscription is created with retain_dead_tuples = true, or the user manually re-enables retain_dead_tuples. A future patch will introduce support for automatic slot re-initialization once at least one apply worker confirms that the retention duration is within the configured max_retention_duration. Author: Zhijie Hou <houzj.f...@fujitsu.com> Reviewed-by: shveta malik <shveta.ma...@gmail.com> Reviewed-by: Nisha Moond <nisha.moond...@gmail.com> Reviewed-by: Masahiko Sawada <sawada.m...@gmail.com> Reviewed-by: Dilip Kumar <dilipbal...@gmail.com> Reviewed-by: Amit Kapila <amit.kapil...@gmail.com> Discussion: https://postgr.es/m/os0pr01mb5716be80daeb0ee2a6a5d1f594...@os0pr01mb5716.jpnprd01.prod.outlook.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/a850be2fe653b3b529969946c1cefe0fd9e34a8d Modified Files -------------- doc/src/sgml/catalogs.sgml | 25 +++ doc/src/sgml/ref/alter_subscription.sgml | 5 +- doc/src/sgml/ref/create_subscription.sgml | 43 ++++- src/backend/catalog/pg_subscription.c | 41 +++++ src/backend/catalog/system_views.sql | 4 +- src/backend/commands/subscriptioncmds.c | 163 ++++++++++++----- src/backend/replication/logical/launcher.c | 125 ++++++++----- src/backend/replication/logical/worker.c | 271 ++++++++++++++++++++++++----- src/bin/pg_dump/pg_dump.c | 18 +- src/bin/pg_dump/pg_dump.h | 1 + src/bin/psql/describe.c | 12 +- src/bin/psql/tab-complete.in.c | 6 +- src/include/catalog/catversion.h | 2 +- src/include/catalog/pg_subscription.h | 16 ++ src/include/catalog/pg_subscription_rel.h | 2 + src/include/commands/subscriptioncmds.h | 5 +- src/include/replication/worker_internal.h | 3 + src/test/regress/expected/subscription.out | 186 +++++++++++--------- src/test/regress/sql/subscription.sql | 16 ++ src/test/subscription/t/035_conflicts.pl | 53 ++++++ 20 files changed, 779 insertions(+), 218 deletions(-)