0001-Skip-table-specific-handling-for-sequences-only-publ.patch
text/x-patch
Filename: 0001-Skip-table-specific-handling-for-sequences-only-publ.patch
Type: text/x-patch
Part: 0
Message:
Re: Logical Replication of sequences
From f607b671dc6c009fb7f56412840f0e6c8e368239 Mon Sep 17 00:00:00 2001
From: Vignesh C <vignesh21@gmail.com>
Date: Thu, 18 Dec 2025 14:59:44 +0530
Subject: [PATCH] Skip table specific handling for sequences only publications
Skip trying to get the list of tables, publish_via_partition_root
handling, and invalidation where the publication does not publish
tables. This avoids unnecessary work and ensures table specific
logic is applied only to relevant publications.
---
src/backend/catalog/pg_publication.c | 11 ++++++++---
src/backend/commands/alter.c | 7 +++++--
src/backend/commands/publicationcmds.c | 6 +++---
3 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c
index 7aa3f179924..39410120f65 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -1170,7 +1170,7 @@ pg_get_publication_tables(PG_FUNCTION_ARGS)
if (pub_elem->alltables)
pub_elem_tables = GetAllPublicationRelations(RELKIND_RELATION,
pub_elem->pubviaroot);
- else
+ else if (!pub_elem->allsequences)
{
List *relids,
*schemarelids;
@@ -1203,8 +1203,13 @@ pg_get_publication_tables(PG_FUNCTION_ARGS)
table_infos = lappend(table_infos, table_info);
}
- /* At least one publication is using publish_via_partition_root. */
- if (pub_elem->pubviaroot)
+ /*
+ * At least one publication is using publish_via_partition_root.
+ * Skip sequences only publications, as publish_via_partition_root
+ * is applicable only to table publications.
+ */
+ if (pub_elem->pubviaroot &&
+ (!pub_elem->allsequences || pub_elem->alltables))
viaroot = true;
}
diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c
index cb75e11fced..e79756af7bb 100644
--- a/src/backend/commands/alter.c
+++ b/src/backend/commands/alter.c
@@ -349,9 +349,12 @@ AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
* Unlike ALTER PUBLICATION ADD/SET/DROP commands, renaming a
* publication does not impact the publication status of tables. So,
* we don't need to invalidate relcache to rebuild the rd_pubdesc.
- * Instead, we invalidate only the relsyncache.
+ * Instead, invalidate the relation sync cache for publications that
+ * include tables. Invalidation is not required for sequences only
+ * publications.
*/
- InvalidatePubRelSyncCache(pub->oid, pub->puballtables);
+ if (!pub->puballsequences || pub->puballtables)
+ InvalidatePubRelSyncCache(pub->oid, pub->puballtables);
}
/* Release memory */
diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c
index a1983508950..e128789a673 100644
--- a/src/backend/commands/publicationcmds.c
+++ b/src/backend/commands/publicationcmds.c
@@ -1028,8 +1028,8 @@ AlterPublicationOptions(ParseState *pstate, AlterPublicationStmt *stmt,
* disallow using WHERE clause and column lists on partitioned table in
* this case.
*/
- if (!pubform->puballtables && publish_via_partition_root_given &&
- !publish_via_partition_root)
+ if (!pubform->puballtables && !pubform->puballsequences &&
+ publish_via_partition_root_given && !publish_via_partition_root)
{
/*
* Lock the publication so nobody else can do anything with it. This
@@ -1149,7 +1149,7 @@ AlterPublicationOptions(ParseState *pstate, AlterPublicationStmt *stmt,
{
CacheInvalidateRelcacheAll();
}
- else
+ else if (!pubform->puballsequences)
{
List *relids = NIL;
List *schemarelids = NIL;
--
2.43.0