From f6ecabd30df02e8a56150a905c08c34fae7da13b Mon Sep 17 00:00:00 2001 From: Vignesh C Date: Wed, 9 Sep 2026 09:40:32 +0530 Subject: [PATCH v1 1/5] Fix ALTER PUBLICATION race with concurrent SET ALL TABLES AlterPublicationOptions() uses the puballtables value from a publication tuple fetched before acquiring the publication lock. A concurrent ALTER PUBLICATION ... SET ALL TABLES can change the publication state while the command waits for the lock, leaving the value stale. Use the current publication state after acquiring the lock when deciding whether to check for explicitly added relations. This avoids calling GetIncludedPublicationRelations() for a publication that is now FOR ALL TABLES. --- src/backend/commands/publicationcmds.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c index 96838730fe1..79276c842cc 100644 --- a/src/backend/commands/publicationcmds.c +++ b/src/backend/commands/publicationcmds.c @@ -1054,8 +1054,7 @@ 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 (publish_via_partition_root_given && !publish_via_partition_root) { /* * Lock the publication so nobody else can do anything with it. This @@ -1066,8 +1065,14 @@ AlterPublicationOptions(ParseState *pstate, AlterPublicationStmt *stmt, LockDatabaseObject(PublicationRelationId, pubform->oid, 0, AccessShareLock); - root_relids = GetIncludedPublicationRelations(pubform->oid, - PUBLICATION_PART_ROOT); + /* + * pubform was read before acquiring the lock, so puballtables may be + * stale if a concurrent ALTER PUBLICATION ... SET ALL TABLES committed + * while we waited. Use the current publication state. + */ + if (!GetPublication(pubform->oid)->alltables) + root_relids = GetIncludedPublicationRelations(pubform->oid, + PUBLICATION_PART_ROOT); foreach(lc, root_relids) { -- 2.55.0