From 26caa46a978e09469070a8ad3f0bdc0d77b233df Mon Sep 17 00:00:00 2001 From: Dilip Kumar Date: Mon, 29 Sep 2025 14:36:38 +0530 Subject: [PATCH v2 2/2] Don't add conflict history tables to publishable relation When all table option is used with publication don't publish the conflict history tables. --- src/backend/catalog/pg_publication.c | 3 ++ src/backend/commands/subscriptioncmds.c | 40 +++++++++++++++++++++++++ src/include/commands/subscriptioncmds.h | 2 ++ 3 files changed, 45 insertions(+) diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c index b911efcf9cb..1e4ce2d6116 100644 --- a/src/backend/catalog/pg_publication.c +++ b/src/backend/catalog/pg_publication.c @@ -31,6 +31,7 @@ #include "catalog/pg_publication_rel.h" #include "catalog/pg_type.h" #include "commands/publicationcmds.h" +#include "commands/subscriptioncmds.h" #include "funcapi.h" #include "utils/array.h" #include "utils/builtins.h" @@ -883,7 +884,9 @@ GetAllTablesPublicationRelations(bool pubviaroot) Form_pg_class relForm = (Form_pg_class) GETSTRUCT(tuple); Oid relid = relForm->oid; + /* conflict history tables are not published. */ if (is_publishable_class(relid, relForm) && + !IsConflictHistoryRelid(relid) && !(relForm->relispartition && pubviaroot)) result = lappend_oid(result, relid); } diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c index dbaeed4b0b1..f5d04c4d9cc 100644 --- a/src/backend/commands/subscriptioncmds.c +++ b/src/backend/commands/subscriptioncmds.c @@ -15,6 +15,7 @@ #include "postgres.h" #include "access/commit_ts.h" +#include "access/heapam.h" #include "access/htup_details.h" #include "access/table.h" #include "access/twophase.h" @@ -3024,3 +3025,42 @@ defGetStreamingMode(DefElem *def) def->defname))); return LOGICALREP_STREAM_OFF; /* keep compiler quiet */ } + +/* + * IsConflictHistoryRelid - is this relid used as conflict history table + * + * Scan all the subscription and check whether the relation is used as + * conflict history table. + */ +bool +IsConflictHistoryRelid(Oid relid) +{ + Relation rel; + TableScanDesc scan; + HeapTuple tup; + bool found = false; + + rel = table_open(SubscriptionRelationId, AccessShareLock); + scan = table_beginscan_catalog(rel, 0, NULL); + + while (HeapTupleIsValid(tup = heap_getnext(scan, ForwardScanDirection))) + { + Form_pg_subscription subform = (Form_pg_subscription) GETSTRUCT(tup); + Oid nspid; + char *relname; + + relname = get_subscription_conflictrel(subform->oid, &nspid); + if (relname == NULL) + continue; + if (relid == get_relname_relid(relname, nspid)) + { + found = true; + break; + } + } + + table_endscan(scan); + table_close(rel, AccessShareLock); + + return found; +} diff --git a/src/include/commands/subscriptioncmds.h b/src/include/commands/subscriptioncmds.h index fb4e26a51a4..550af0bb034 100644 --- a/src/include/commands/subscriptioncmds.h +++ b/src/include/commands/subscriptioncmds.h @@ -36,4 +36,6 @@ extern void CheckSubDeadTupleRetention(bool check_guc, bool sub_disabled, bool retention_active, bool max_retention_set); +extern bool IsConflictHistoryRelid(Oid relid); + #endif /* SUBSCRIPTIONCMDS_H */ -- 2.49.0