pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feedReview items for EXCEPT TABLE publication
42+ messages / 6 participants
[nested] [flat]
Commits from this thread:
2026-09-14 17d84c2b67 7056ed4663 Disallow SET UNLOGGED for tables in a publication's EXCEPT clause.
2026-09-11 f6b2d6b827 5624de9904 Validate ALTER PUBLICATION after acquiring the publication lock.
* Review items for EXCEPT TABLE publication
@ 2026-09-10 05:39 vignesh C <vignesh21@gmail.com>
0 siblings, 9 replies; 42+ messages in thread
From: vignesh C @ 2026-09-10 05:39 UTC (permalink / raw)
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Hi,
I ran claude to identify issues related to the EXCEPT TABLE
publication changes. After reviewing the findings, I found the
following issues that need to be fixed.
Finding #1: ALTER PUBLICATION race
AlterPublicationOptions() performs validation using the publication
tuple before acquiring the publication lock. A concurrent ALTER
PUBLICATION ... SET ALL TABLES can change puballtables while the
second command is waiting for the lock. Since the tuple is not
re-fetched after acquiring the lock, the validation can proceed based
on stale state while subsequent catalog lookups see the updated state.
In an assert-enabled build, this can trigger the assertion in
GetIncludedPublicationRelations() because of
"Assert(!GetPublication(pubid)->alltables)" and crash the backend.
Test to reproduce:
-- session 1: -- session 2:
CREATE PUBLICATION p;
BEGIN;
ALTER PUBLICATION p
SET ALL TABLES;
ALTER PUBLICATION p
SET
(publish_via_partition_root = false);
-- reads puballtables=false,
-- enters the branch
-- blocks while acquiring
-- AccessShareLock
COMMIT; -- resumes and assertion fires
The fix is to check the current publication state after acquiring the
publication lock.
Finding #2: ALTER PUBLICATION validates against pre-lock state
CheckAlterPublication() validates that pg_publication_rel entries are
either all inclusions or all exclusions. However, this check is
performed before LockDatabaseObject(). A concurrent ALTER PUBLICATION
can therefore add an inclusion while another session is validating and
waiting for the lock. The second command then proceeds without
revalidating after the lock is acquired, leaving the publication with
a mixture of inclusion and exclusion entries.
Test to reproduce:
-- session 1: -- session 2:
CREATE PUBLICATION p;
BEGIN;
ALTER PUBLICATION p
ADD TABLE t2;
ALTER PUBLICATION p
SET ALL TABLES EXCEPT (TABLE t1);
-- passes CheckAlterPublication()
-- while s1's row is invisible,
-- then blocks on the lock
COMMIT; -- resumes without re-checking
The fix is to perform CheckAlterPublication() after acquiring the
publication lock, so that validation is performed against the current
publication state.
Finding #3: Missing check in test_except_root_partition
In test_except_root_partition, the test assigns the result of:
SELECT count(*) = 0 FROM pg_logical_slot_get_binary_changes(...)
to $result under a comment saying that it verifies the table is not
published, but there is no is() check. $result is then overwritten by
the following loop, so the check has no effect.
Added an is() check to verify the result of the query.
Finding #4: Test uses a stale subscription
tap_sub is not dropped between the two multi-publication sub-tests. As
a result, the second CREATE SUBSCRIPTION tap_sub fails with "already
exists". Since the command uses psql(), the error is ignored.
The subsequent assertions therefore run against the existing
subscription rather than the intended fresh one. This means the test
does not exercise the intended scenario: a fresh subscription whose
initial COPY of tab1 must occur because tap_pub2 FOR ALL TABLES
overrides tap_pub1's EXCEPT clause.
Fixed this by dropping the subscription before recreating it.
Finding #5: SET UNLOGGED on an excluded table produces an unrestorable
catalog state
CREATE PUBLICATION ... FOR ALL TABLES EXCEPT (...) correctly rejects
unlogged tables. However, ALTER TABLE ... SET UNLOGGED does not
perform the same check. Its publication check uses
GetRelationIncludedPublications(), which ignores pg_publication_rel
rows marked as prexcept.
As a result, the following currently succeeds:
CREATE TABLE t (a int);
CREATE PUBLICATION p FOR ALL TABLES EXCEPT (TABLE t);
ALTER TABLE t SET UNLOGGED;
This leaves an unlogged table in the publication's EXCEPT list, even
though an unlogged table cannot be added to an EXCEPT clause directly.
This causes failures when restoring a dump or running pg_upgrade.
For example, pg_dump produces:
CREATE PUBLICATION pub1 FOR ALL TABLES EXCEPT (TABLE ONLY public.t1)
WITH (publish = 'insert, update, delete, truncate');
where t1 is an unlogged table. Restoring the dump fails with:
ERROR: cannot specify relation "public.t1" in the publication EXCEPT clause
DETAIL: This operation is not supported for unlogged tables.
A similar error is seen during pg_upgrade:
ERROR: cannot specify relation "public.t1" in the publication EXCEPT clause
DETAIL: This operation is not supported for unlogged tables.
The fix is to reject changing a table to UNLOGGED when it is
referenced in a publication's EXCEPT clause, similar to the existing
check for tables included in a publication.
I have attached patches for these issues:
Finding #1: v1-0001-Fix-ALTER-PUBLICATION-race-with-concurrent-SET-AL.patch
Finding #2: v1-0002-Fix-ALTER-PUBLICATION-validation-race.patch
Finding #3: v1-0003-Fix-missing-check-in-test_except_root_partition.patch
Finding #4: v1-0004-Fix-test-to-use-a-fresh-subscription.patch
Finding #5: v1-0005-Prevent-unlogged-tables-in-publication-EXCEPT-cla.patch
Regards,
Vignesh
Attachments: download all (5 files, .tar.gz)
v1-0001-Fix-ALTER-PUBLICATION-race-with-concurrent-SET-AL.patch (application/octet-stream, 2.2K) download
From f6ecabd30df02e8a56150a905c08c34fae7da13b Mon Sep 17 00:00:00 2001
From: Vignesh C <c_vigneshwaran@apple.com>
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
v1-0005-Prevent-unlogged-tables-in-publication-EXCEPT-cla.patch (application/octet-stream, 4.1K) download
From 56058316df0cc241d5298003773f36268cf6f056 Mon Sep 17 00:00:00 2001
From: Vignesh C <c_vigneshwaran@apple.com>
Date: Thu, 10 Sep 2026 09:54:03 +0530
Subject: [PATCH v1 5/5] Prevent unlogged tables in publication EXCEPT clauses
Reject changing a table to UNLOGGED when it is referenced by a publication's
EXCEPT clause. This keeps the catalog state consistent with the restriction
that unlogged tables cannot be specified in publication EXCEPT clauses and
ensures that pg_dump can recreate the publication.
---
src/backend/commands/tablecmds.c | 12 ++++++++++++
src/test/regress/expected/publication.out | 9 +++++++++
src/test/regress/sql/publication.sql | 8 ++++++++
3 files changed, 29 insertions(+)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8dc70bfa0f1..1d7c659d367 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -19552,6 +19552,18 @@ ATPrepChangePersistence(AlteredTableInfo *tab, Relation rel, bool toLogged)
RelationGetRelationName(rel)),
errdetail("Unlogged relations cannot be replicated.")));
+ /*
+ * Likewise, reject the change if the table is named in a publication's
+ * EXCEPT clause, since unlogged tables are not allowed there.
+ */
+ if (!toLogged &&
+ GetRelationExcludedPublications(RelationGetRelid(rel)) != NIL)
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("cannot change table \"%s\" to unlogged because it is referenced in a publication EXCEPT clause",
+ RelationGetRelationName(rel)),
+ errhint("Remove the table from the EXCEPT clause using ALTER PUBLICATION ... SET ALL TABLES first.")));
+
/*
* Check existing foreign key constraints to preserve the invariant that
* permanent tables cannot reference unlogged ones. Self-referencing
diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.out
index 4f21462cc17..1fdea6ee088 100644
--- a/src/test/regress/expected/publication.out
+++ b/src/test/regress/expected/publication.out
@@ -279,6 +279,15 @@ CREATE PUBLICATION testpub_foralltables_excepttable2 FOR ALL TABLES EXCEPT (test
ERROR: syntax error at or near "testpub_tbl1"
LINE 1: ..._foralltables_excepttable2 FOR ALL TABLES EXCEPT (testpub_tb...
^
+-- A table in an EXCEPT clause cannot be changed to UNLOGGED.
+CREATE TABLE testpub_exc_unlogged_tbl (a int);
+CREATE PUBLICATION testpub_exc_unlogged FOR ALL TABLES EXCEPT (TABLE testpub_exc_unlogged_tbl);
+-- fail - the table is referenced in a publication EXCEPT clause
+ALTER TABLE testpub_exc_unlogged_tbl SET UNLOGGED;
+ERROR: cannot change table "testpub_exc_unlogged_tbl" to unlogged because it is referenced in a publication EXCEPT clause
+HINT: Remove the table from the EXCEPT clause using ALTER PUBLICATION ... SET ALL TABLES first.
+DROP PUBLICATION testpub_exc_unlogged;
+DROP TABLE testpub_exc_unlogged_tbl;
---------------------------------------------
-- SET ALL TABLES/SEQUENCES
---------------------------------------------
diff --git a/src/test/regress/sql/publication.sql b/src/test/regress/sql/publication.sql
index fac54b02e27..80c244c9138 100644
--- a/src/test/regress/sql/publication.sql
+++ b/src/test/regress/sql/publication.sql
@@ -126,6 +126,14 @@ CREATE PUBLICATION testpub_foralltables_excepttable1 FOR ALL TABLES EXCEPT (TABL
-- fail - first table in the EXCEPT list should use TABLE keyword
CREATE PUBLICATION testpub_foralltables_excepttable2 FOR ALL TABLES EXCEPT (testpub_tbl1, testpub_tbl2);
+-- A table in an EXCEPT clause cannot be changed to UNLOGGED.
+CREATE TABLE testpub_exc_unlogged_tbl (a int);
+CREATE PUBLICATION testpub_exc_unlogged FOR ALL TABLES EXCEPT (TABLE testpub_exc_unlogged_tbl);
+-- fail - the table is referenced in a publication EXCEPT clause
+ALTER TABLE testpub_exc_unlogged_tbl SET UNLOGGED;
+DROP PUBLICATION testpub_exc_unlogged;
+DROP TABLE testpub_exc_unlogged_tbl;
+
---------------------------------------------
-- SET ALL TABLES/SEQUENCES
---------------------------------------------
--
2.55.0
v1-0003-Fix-missing-check-in-test_except_root_partition.patch (application/octet-stream, 1.3K) download
From d1eea4f935209c48dff645ae6a13b361ce38c0f8 Mon Sep 17 00:00:00 2001
From: Vignesh C <c_vigneshwaran@apple.com>
Date: Wed, 9 Sep 2026 10:02:30 +0530
Subject: [PATCH v1 3/5] Fix missing check in test_except_root_partition
The test assigned the result of checking the replication slot for changes
to $result but never checked it, causing the check to be silently ignored.
Check that no changes for the excluded partitioned table are present in
the replication slot.
---
src/test/subscription/t/037_except.pl | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/test/subscription/t/037_except.pl b/src/test/subscription/t/037_except.pl
index 43b51c8ff71..a73a509e763 100644
--- a/src/test/subscription/t/037_except.pl
+++ b/src/test/subscription/t/037_except.pl
@@ -52,6 +52,10 @@ sub test_except_root_partition
$result = $node_publisher->safe_psql('postgres',
"SELECT count(*) = 0 FROM pg_logical_slot_get_binary_changes('test_slot', NULL, NULL, 'proto_version', '1', 'publication_names', 'tap_pub_part')"
);
+ is($result, qq(t),
+ "no changes for the partitioned table in the EXCEPT clause are present in the replication slot (publish_via_partition_root = $pubviaroot)"
+ );
+
$node_publisher->wait_for_catchup('tap_sub_part');
# Verify that no rows are replicated to subscriber for root or partitions.
--
2.55.0
v1-0002-Fix-ALTER-PUBLICATION-validation-race.patch (application/octet-stream, 2.3K) download
From d29cc80d400e206e13566748d9c20903725a5211 Mon Sep 17 00:00:00 2001
From: Vignesh C <c_vigneshwaran@apple.com>
Date: Wed, 9 Sep 2026 09:21:27 +0530
Subject: [PATCH v1 2/5] Fix ALTER PUBLICATION validation race
AlterPublication() calls CheckAlterPublication() before acquiring the
publication lock. A concurrent ALTER PUBLICATION can modify
pg_publication_rel while the command waits for the lock, allowing the
validation to pass based on stale state.
The command then re-fetches the publication tuple after acquiring the
lock, but does not revalidate the publication relations. This can leave
pg_publication_rel containing a mixture of inclusion and exclusion rows.
Re-run CheckAlterPublication() after acquiring the lock so that the
validation uses the current publication state.
---
src/backend/commands/publicationcmds.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c
index 79276c842cc..96d5c0453a1 100644
--- a/src/backend/commands/publicationcmds.c
+++ b/src/backend/commands/publicationcmds.c
@@ -1695,8 +1695,6 @@ AlterPublication(ParseState *pstate, AlterPublicationStmt *stmt)
ObjectsInPublicationToOids(stmt->pubobjects, pstate, &relations,
&exceptrelations, &schemaidlist);
- CheckAlterPublication(stmt, tup, relations, schemaidlist);
-
heap_freetuple(tup);
/* Lock the publication so nobody else can do anything with it. */
@@ -1716,6 +1714,17 @@ AlterPublication(ParseState *pstate, AlterPublicationStmt *stmt)
errmsg("publication \"%s\" does not exist",
stmt->pubname));
+ /*
+ * Validate after acquiring the lock so that the checks see the
+ * publication state we are about to modify. A concurrent ALTER
+ * PUBLICATION may otherwise change the state while we wait for the
+ * lock, causing both commands to pass their checks independently.
+ * LockDatabaseObject() accepts invalidation messages after acquiring
+ * the lock, so the catalog scans below see concurrently committed
+ * changes.
+ */
+ CheckAlterPublication(stmt, tup, relations, schemaidlist);
+
relations = list_concat(relations, exceptrelations);
AlterPublicationTables(stmt, tup, relations, pstate->p_sourcetext,
schemaidlist != NIL);
--
2.55.0
v1-0004-Fix-test-to-use-a-fresh-subscription.patch (application/octet-stream, 1.8K) download
From 18b5bc395d462e32844d8aef3e8a6e54942d880a Mon Sep 17 00:00:00 2001
From: Vignesh C <c_vigneshwaran@apple.com>
Date: Wed, 9 Sep 2026 10:09:05 +0530
Subject: [PATCH v1 4/5] Fix test to use a fresh subscription
Drop tap_sub before recreating it for the second multi-publication test.
Also use safe_psql() so that failure does not go unnoticed.
---
src/test/subscription/t/037_except.pl | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/test/subscription/t/037_except.pl b/src/test/subscription/t/037_except.pl
index a73a509e763..c85dcb6fd64 100644
--- a/src/test/subscription/t/037_except.pl
+++ b/src/test/subscription/t/037_except.pl
@@ -239,7 +239,7 @@ $node_publisher->safe_psql(
CREATE PUBLICATION tap_pub2 FOR TABLE tab1;
INSERT INTO tab1 VALUES(1);
));
-$node_subscriber->psql('postgres',
+$node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub1, tap_pub2"
);
$node_subscriber->wait_for_subscription_sync($node_publisher, 'tap_sub');
@@ -258,7 +258,11 @@ $node_publisher->safe_psql(
DROP PUBLICATION tap_pub2;
TRUNCATE tab1;
));
-$node_subscriber->safe_psql('postgres', qq(TRUNCATE tab1));
+$node_subscriber->safe_psql(
+ 'postgres', qq(
+ DROP SUBSCRIPTION tap_sub;
+ TRUNCATE tab1;
+));
# OK when a table is excluded by pub1 EXCEPT clause, but it is included by pub2
# FOR ALL TABLES.
@@ -267,7 +271,7 @@ $node_publisher->safe_psql(
CREATE PUBLICATION tap_pub2 FOR ALL TABLES;
INSERT INTO tab1 VALUES(1);
));
-$node_subscriber->psql('postgres',
+$node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub1, tap_pub2"
);
$node_subscriber->wait_for_subscription_sync($node_publisher, 'tap_sub');
--
2.55.0
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 05:45 Amit Kapila <amit.kapila16@gmail.com>
parent: vignesh C <vignesh21@gmail.com>
8 siblings, 1 reply; 42+ messages in thread
From: Amit Kapila @ 2026-09-10 05:45 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Thu, Sep 10, 2026 at 11:09 AM vignesh C <vignesh21@gmail.com> wrote:
>
> I ran claude to identify issues related to the EXCEPT TABLE
> publication changes.
>
Thanks for doing an AI based review of this feature. I'll look into
it. We can add an open item for this report.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 06:19 vignesh C <vignesh21@gmail.com>
parent: Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 0 replies; 42+ messages in thread
From: vignesh C @ 2026-09-10 06:19 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Thu, 10 Sept 2026 at 11:15, Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Thu, Sep 10, 2026 at 11:09 AM vignesh C <vignesh21@gmail.com> wrote:
> >
> > I ran claude to identify issues related to the EXCEPT TABLE
> > publication changes.
> >
>
> Thanks for doing an AI based review of this feature. I'll look into
> it. We can add an open item for this report.
Added "Review items for EXCEPT TABLE publication" open item at [1].
[1] - https://wiki.postgresql.org/wiki/PostgreSQL_19_Open_Items#Open_Issues
Regards,
Vignesh
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 07:10 Chao Li <li.evan.chao@gmail.com>
parent: vignesh C <vignesh21@gmail.com>
8 siblings, 1 reply; 42+ messages in thread
From: Chao Li @ 2026-09-10 07:10 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
> On Sep 10, 2026, at 13:39, vignesh C <vignesh21@gmail.com> wrote:
>
> Hi,
>
> I ran claude to identify issues related to the EXCEPT TABLE
> publication changes. After reviewing the findings, I found the
> following issues that need to be fixed.
> Finding #1: ALTER PUBLICATION race
> AlterPublicationOptions() performs validation using the publication
> tuple before acquiring the publication lock. A concurrent ALTER
> PUBLICATION ... SET ALL TABLES can change puballtables while the
> second command is waiting for the lock. Since the tuple is not
> re-fetched after acquiring the lock, the validation can proceed based
> on stale state while subsequent catalog lookups see the updated state.
> In an assert-enabled build, this can trigger the assertion in
> GetIncludedPublicationRelations() because of
> "Assert(!GetPublication(pubid)->alltables)" and crash the backend.
>
> Test to reproduce:
> -- session 1: -- session 2:
> CREATE PUBLICATION p;
> BEGIN;
> ALTER PUBLICATION p
> SET ALL TABLES;
> ALTER PUBLICATION p
> SET
> (publish_via_partition_root = false);
> -- reads puballtables=false,
> -- enters the branch
> -- blocks while acquiring
> -- AccessShareLock
> COMMIT; -- resumes and assertion fires
>
> The fix is to check the current publication state after acquiring the
> publication lock.
>
> Regards,
> Vignesh
> <v1-0001-Fix-ALTER-PUBLICATION-race-with-concurrent-SET-AL.patch><v1-0005-Prevent-unlogged-tables-in-publication-EXCEPT-cla.patch><v1-0003-Fix-missing-check-in-test_except_root_partition.patch><v1-0002-Fix-ALTER-PUBLICATION-validation-race.patch><v1-0004-Fix-test-to-use-a-fresh-subscription.patch>
Since each commit addresses one finding, I’ll review and reply to the commits one by one.
For 0001, I have two comments:
1. I don’t think this fix completely resolves the race. With GetPublication(pubform->oid)->alltables moved after acquiring the lock, S2 has to wait for S1 to commit, so it can see the alltables change made by S1.
However, tup was fetched before AlterPublicationOptions() was called. After S1 commits its update, a new tuple version has been created, so the tup held by S2 is stale. I think S2 should re-fetch the publication tuple after acquiring the lock, so that both the validation and the subsequent catalog update operate on the current tuple version.
2. From a code-structure perspective, before this patch the relation-validation block was entered only when the publication was not FOR ALL TABLES. With this patch, the outer if is entered regardless of puballtables, and when GetPublication(pubform->oid)->alltables is true, root_relids is simply left empty.
This is not a problem today because the only code that follows is the foreach, which does nothing when root_relids is empty. However, if more code is added after the loop in the future, it may unintentionally run for an ALL TABLESpublication as well.
I think it would be clearer and safer to keep the whole relation-validation section, including the foreach, inside the post-lock !alltables branch.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 07:17 Chao Li <li.evan.chao@gmail.com>
parent: vignesh C <vignesh21@gmail.com>
8 siblings, 0 replies; 42+ messages in thread
From: Chao Li @ 2026-09-10 07:17 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
> On Sep 10, 2026, at 13:39, vignesh C <vignesh21@gmail.com> wrote:
>
> Finding #2: ALTER PUBLICATION validates against pre-lock state
>
> CheckAlterPublication() validates that pg_publication_rel entries are
> either all inclusions or all exclusions. However, this check is
> performed before LockDatabaseObject(). A concurrent ALTER PUBLICATION
> can therefore add an inclusion while another session is validating and
> waiting for the lock. The second command then proceeds without
> revalidating after the lock is acquired, leaving the publication with
> a mixture of inclusion and exclusion entries.
>
> Test to reproduce:
> -- session 1: -- session 2:
> CREATE PUBLICATION p;
> BEGIN;
> ALTER PUBLICATION p
> ADD TABLE t2;
> ALTER PUBLICATION p
> SET ALL TABLES EXCEPT (TABLE t1);
> -- passes CheckAlterPublication()
> -- while s1's row is invisible,
> -- then blocks on the lock
> COMMIT; -- resumes without re-checking
>
> The fix is to perform CheckAlterPublication() after acquiring the
> publication lock, so that validation is performed against the current
> publication state.
>
>
> Regards,
> Vignesh
> <v1-0001-Fix-ALTER-PUBLICATION-race-with-concurrent-SET-AL.patch><v1-0005-Prevent-unlogged-tables-in-publication-EXCEPT-cla.patch><v1-0003-Fix-missing-check-in-test_except_root_partition.patch><v1-0002-Fix-ALTER-PUBLICATION-validation-race.patch><v1-0004-Fix-test-to-use-a-fresh-subscription.patch>
v1-0002 looks correct and appears to fix the race described in finding 2.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 07:23 Chao Li <li.evan.chao@gmail.com>
parent: vignesh C <vignesh21@gmail.com>
8 siblings, 0 replies; 42+ messages in thread
From: Chao Li @ 2026-09-10 07:23 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
> On Sep 10, 2026, at 13:39, vignesh C <vignesh21@gmail.com> wrote:
>
> Finding #3: Missing check in test_except_root_partition
>
> In test_except_root_partition, the test assigns the result of:
> SELECT count(*) = 0 FROM pg_logical_slot_get_binary_changes(...)
> to $result under a comment saying that it verifies the table is not
> published, but there is no is() check. $result is then overwritten by
> the following loop, so the check has no effect.
>
> Added an is() check to verify the result of the query.
>
> Regards,
> Vignesh
> <v1-0001-Fix-ALTER-PUBLICATION-race-with-concurrent-SET-AL.patch><v1-0005-Prevent-unlogged-tables-in-publication-EXCEPT-cla.patch><v1-0003-Fix-missing-check-in-test_except_root_partition.patch><v1-0002-Fix-ALTER-PUBLICATION-validation-race.patch><v1-0004-Fix-test-to-use-a-fresh-subscription.patch>
v1-0003 looks good to me. The added is() correctly makes the previously ignored check effective. I also ran the test and it passed.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 07:36 Chao Li <li.evan.chao@gmail.com>
parent: vignesh C <vignesh21@gmail.com>
8 siblings, 0 replies; 42+ messages in thread
From: Chao Li @ 2026-09-10 07:36 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
> On Sep 10, 2026, at 13:39, vignesh C <vignesh21@gmail.com> wrote:
>
>
> Finding #4: Test uses a stale subscription
>
> tap_sub is not dropped between the two multi-publication sub-tests. As
> a result, the second CREATE SUBSCRIPTION tap_sub fails with "already
> exists". Since the command uses psql(), the error is ignored.
> The subsequent assertions therefore run against the existing
> subscription rather than the intended fresh one. This means the test
> does not exercise the intended scenario: a fresh subscription whose
> initial COPY of tab1 must occur because tap_pub2 FOR ALL TABLES
> overrides tap_pub1's EXCEPT clause.
>
> Fixed this by dropping the subscription before recreating it.
>
>
> Regards,
> Vignesh
> <v1-0001-Fix-ALTER-PUBLICATION-race-with-concurrent-SET-AL.patch><v1-0005-Prevent-unlogged-tables-in-publication-EXCEPT-cla.patch><v1-0003-Fix-missing-check-in-test_except_root_partition.patch><v1-0002-Fix-ALTER-PUBLICATION-validation-race.patch><v1-0004-Fix-test-to-use-a-fresh-subscription.patch>
v1-0001 looks good to me. Changing to safe_psql() ensures that errors are not silently ignored, and dropping tap_sub ensures that the second case uses a fresh subscription as intended. I also ran the test, and it passed.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 07:53 Chao Li <li.evan.chao@gmail.com>
parent: vignesh C <vignesh21@gmail.com>
8 siblings, 2 replies; 42+ messages in thread
From: Chao Li @ 2026-09-10 07:53 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
> On Sep 10, 2026, at 13:39, vignesh C <vignesh21@gmail.com> wrote:
>
> Finding #5: SET UNLOGGED on an excluded table produces an unrestorable
> catalog state
>
> CREATE PUBLICATION ... FOR ALL TABLES EXCEPT (...) correctly rejects
> unlogged tables. However, ALTER TABLE ... SET UNLOGGED does not
> perform the same check. Its publication check uses
> GetRelationIncludedPublications(), which ignores pg_publication_rel
> rows marked as prexcept.
> As a result, the following currently succeeds:
> CREATE TABLE t (a int);
> CREATE PUBLICATION p FOR ALL TABLES EXCEPT (TABLE t);
> ALTER TABLE t SET UNLOGGED;
>
> This leaves an unlogged table in the publication's EXCEPT list, even
> though an unlogged table cannot be added to an EXCEPT clause directly.
> This causes failures when restoring a dump or running pg_upgrade.
> For example, pg_dump produces:
> CREATE PUBLICATION pub1 FOR ALL TABLES EXCEPT (TABLE ONLY public.t1)
> WITH (publish = 'insert, update, delete, truncate');
> where t1 is an unlogged table. Restoring the dump fails with:
> ERROR: cannot specify relation "public.t1" in the publication EXCEPT clause
> DETAIL: This operation is not supported for unlogged tables.
>
> A similar error is seen during pg_upgrade:
> ERROR: cannot specify relation "public.t1" in the publication EXCEPT clause
> DETAIL: This operation is not supported for unlogged tables.
>
> The fix is to reject changing a table to UNLOGGED when it is
> referenced in a publication's EXCEPT clause, similar to the existing
> check for tables included in a publication.
>
>
> Regards,
> Vignesh
> <v1-0001-Fix-ALTER-PUBLICATION-race-with-concurrent-SET-AL.patch><v1-0005-Prevent-unlogged-tables-in-publication-EXCEPT-cla.patch><v1-0003-Fix-missing-check-in-test_except_root_partition.patch><v1-0002-Fix-ALTER-PUBLICATION-validation-race.patch><v1-0004-Fix-test-to-use-a-fresh-subscription.patch>
For v1-0005, the code change itself looks good to me.
However, I have some concern about the design. Since a table in the EXCEPT list is not published anyway, do we really need to reject SET UNLOGGED? Would it make more sense to remove the table from the EXCEPT list and emit a NOTICE to inform the user?
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 09:25 shveta malik <shveta.malik@gmail.com>
parent: Chao Li <li.evan.chao@gmail.com>
1 sibling, 3 replies; 42+ messages in thread
From: shveta malik @ 2026-09-10 09:25 UTC (permalink / raw)
To: Chao Li <li.evan.chao@gmail.com>; +Cc: vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; shveta malik <shveta.malik@gmail.com>
On Thu, Sep 10, 2026 at 1:24 PM Chao Li <li.evan.chao@gmail.com> wrote:
>
>
>
> > On Sep 10, 2026, at 13:39, vignesh C <vignesh21@gmail.com> wrote:
> >
> > Finding #5: SET UNLOGGED on an excluded table produces an unrestorable
> > catalog state
> >
> > CREATE PUBLICATION ... FOR ALL TABLES EXCEPT (...) correctly rejects
> > unlogged tables. However, ALTER TABLE ... SET UNLOGGED does not
> > perform the same check. Its publication check uses
> > GetRelationIncludedPublications(), which ignores pg_publication_rel
> > rows marked as prexcept.
> > As a result, the following currently succeeds:
> > CREATE TABLE t (a int);
> > CREATE PUBLICATION p FOR ALL TABLES EXCEPT (TABLE t);
> > ALTER TABLE t SET UNLOGGED;
> >
> > This leaves an unlogged table in the publication's EXCEPT list, even
> > though an unlogged table cannot be added to an EXCEPT clause directly.
> > This causes failures when restoring a dump or running pg_upgrade.
> > For example, pg_dump produces:
> > CREATE PUBLICATION pub1 FOR ALL TABLES EXCEPT (TABLE ONLY public.t1)
> > WITH (publish = 'insert, update, delete, truncate');
> > where t1 is an unlogged table. Restoring the dump fails with:
> > ERROR: cannot specify relation "public.t1" in the publication EXCEPT clause
> > DETAIL: This operation is not supported for unlogged tables.
> >
> > A similar error is seen during pg_upgrade:
> > ERROR: cannot specify relation "public.t1" in the publication EXCEPT clause
> > DETAIL: This operation is not supported for unlogged tables.
> >
> > The fix is to reject changing a table to UNLOGGED when it is
> > referenced in a publication's EXCEPT clause, similar to the existing
> > check for tables included in a publication.
> >
> >
> > Regards,
> > Vignesh
> > <v1-0001-Fix-ALTER-PUBLICATION-race-with-concurrent-SET-AL.patch><v1-0005-Prevent-unlogged-tables-in-publication-EXCEPT-cla.patch><v1-0003-Fix-missing-check-in-test_except_root_partition.patch><v1-0002-Fix-ALTER-PUBLICATION-validation-race.patch><v1-0004-Fix-test-to-use-a-fresh-subscription.patch>
>
> For v1-0005, the code change itself looks good to me.
>
> However, I have some concern about the design. Since a table in the EXCEPT list is not published anyway, do we really need to reject SET UNLOGGED? Would it make more sense to remove the table from the EXCEPT list and emit a NOTICE to inform the user?
I had given a similar comment offlist yesterday, but upon rethinking,
I feel automatically removing the table from the EXCEPT list is
slightly riskier even with NOTICE given. The user may later change the
table back to LOGGED, in which case the publication semantics would
have changed silently; the table would now be published(for ALL TABLEs
case) even though the user never changed the publication
configuration.
~~
I think the proposed fix is also incomplete though for partitioned tables:
CREATE TABLE root (a int) PARTITION BY RANGE (a);
CREATE TABLE part1 PARTITION OF root FOR VALUES FROM (1) TO (100);
CREATE PUBLICATION root_pub FOR ALL TABLES EXCEPT (TABLE root);
-- This fails:
ALTER TABLE root SET UNLOGGED;
-- But this succeeds:
ALTER TABLE part1 SET UNLOGGED;
Shouldn't the second command (for partition) fail too?
thanks
Shveta
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 09:31 Amit Kapila <amit.kapila16@gmail.com>
parent: Chao Li <li.evan.chao@gmail.com>
1 sibling, 1 reply; 42+ messages in thread
From: Amit Kapila @ 2026-09-10 09:31 UTC (permalink / raw)
To: Chao Li <li.evan.chao@gmail.com>; +Cc: vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Thu, Sep 10, 2026 at 1:24 PM Chao Li <li.evan.chao@gmail.com> wrote:
>
> > On Sep 10, 2026, at 13:39, vignesh C <vignesh21@gmail.com> wrote:
> >
> > Finding #5: SET UNLOGGED on an excluded table produces an unrestorable
> > catalog state
> >
>
> For v1-0005, the code change itself looks good to me.
>
> However, I have some concern about the design. Since a table in the EXCEPT list is not published anyway, do we really need to reject SET UNLOGGED? Would it make more sense to remove the table from the EXCEPT list and emit a NOTICE to inform the user?
>
I think removing the publication membership during another DDL will
unnecessarily widen the scope of publication memberships. For example,
consider, later one does, ALTER TABLE t SET LOGGED emits nothing, and
t is now published by p.
This is the damaging one and NOTICE in the previous message doesn't
prevent it. Either the subscriber lacks t, in which case apply fails
and the whole subscription
stalls, or it has t, in which case data the user deliberately excluded
starts flowing. Both are triggered by a local DDL statement with no
indication that replication scope just widened.
Also, it would be inconsistent with the INCLUDED case where we are
giving ERROR. I feel giving ERROR is the right thing to do here, so
that users can explicitly remove it from EXCEPT list and then later if
She wants to make table LOGGED again, She can execute following steps:
BEGIN;
ALTER TABLE t SET LOGGED;
ALTER PUBLICATION p SET ALL TABLES EXCEPT (TABLE t, ...);
COMMIT;
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 09:36 shveta malik <shveta.malik@gmail.com>
parent: shveta malik <shveta.malik@gmail.com>
2 siblings, 0 replies; 42+ messages in thread
From: shveta malik @ 2026-09-10 09:36 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; shveta malik <shveta.malik@gmail.com>; Chao Li <li.evan.chao@gmail.com>
patch 002:
Commit msg says:
----------
The command then re-fetches the publication tuple after acquiring the
lock, but does not revalidate the publication relations. This can leave
pg_publication_rel containing a mixture of inclusion and exclusion rows.
Re-run CheckAlterPublication() after acquiring the lock so that the
validation uses the current publication state.
---------
The commit message and the fix are not in sync and thus little
confusing. Commit msg talks about re-validation while patch has
shifted the validation to a later point. The code change looks good
though.
patch003: LGTM
patch004: LGTM
thanks
Shveta
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 09:37 Chao Li <li.evan.chao@gmail.com>
parent: shveta malik <shveta.malik@gmail.com>
2 siblings, 1 reply; 42+ messages in thread
From: Chao Li @ 2026-09-10 09:37 UTC (permalink / raw)
To: shveta malik <shveta.malik@gmail.com>; +Cc: vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
> On Sep 10, 2026, at 17:25, shveta malik <shveta.malik@gmail.com> wrote:
>
> On Thu, Sep 10, 2026 at 1:24 PM Chao Li <li.evan.chao@gmail.com> wrote:
>>
>>
>>
>>> On Sep 10, 2026, at 13:39, vignesh C <vignesh21@gmail.com> wrote:
>>>
>>> Finding #5: SET UNLOGGED on an excluded table produces an unrestorable
>>> catalog state
>>>
>>> CREATE PUBLICATION ... FOR ALL TABLES EXCEPT (...) correctly rejects
>>> unlogged tables. However, ALTER TABLE ... SET UNLOGGED does not
>>> perform the same check. Its publication check uses
>>> GetRelationIncludedPublications(), which ignores pg_publication_rel
>>> rows marked as prexcept.
>>> As a result, the following currently succeeds:
>>> CREATE TABLE t (a int);
>>> CREATE PUBLICATION p FOR ALL TABLES EXCEPT (TABLE t);
>>> ALTER TABLE t SET UNLOGGED;
>>>
>>> This leaves an unlogged table in the publication's EXCEPT list, even
>>> though an unlogged table cannot be added to an EXCEPT clause directly.
>>> This causes failures when restoring a dump or running pg_upgrade.
>>> For example, pg_dump produces:
>>> CREATE PUBLICATION pub1 FOR ALL TABLES EXCEPT (TABLE ONLY public.t1)
>>> WITH (publish = 'insert, update, delete, truncate');
>>> where t1 is an unlogged table. Restoring the dump fails with:
>>> ERROR: cannot specify relation "public.t1" in the publication EXCEPT clause
>>> DETAIL: This operation is not supported for unlogged tables.
>>>
>>> A similar error is seen during pg_upgrade:
>>> ERROR: cannot specify relation "public.t1" in the publication EXCEPT clause
>>> DETAIL: This operation is not supported for unlogged tables.
>>>
>>> The fix is to reject changing a table to UNLOGGED when it is
>>> referenced in a publication's EXCEPT clause, similar to the existing
>>> check for tables included in a publication.
>>>
>>>
>>> Regards,
>>> Vignesh
>>> <v1-0001-Fix-ALTER-PUBLICATION-race-with-concurrent-SET-AL.patch><v1-0005-Prevent-unlogged-tables-in-publication-EXCEPT-cla.patch><v1-0003-Fix-missing-check-in-test_except_root_partition.patch><v1-0002-Fix-ALTER-PUBLICATION-validation-race.patch><v1-0004-Fix-test-to-use-a-fresh-subscription.patch>
>>
>> For v1-0005, the code change itself looks good to me.
>>
>> However, I have some concern about the design. Since a table in the EXCEPT list is not published anyway, do we really need to reject SET UNLOGGED? Would it make more sense to remove the table from the EXCEPT list and emit a NOTICE to inform the user?
>
> I had given a similar comment offlist yesterday, but upon rethinking,
> I feel automatically removing the table from the EXCEPT list is
> slightly riskier even with NOTICE given. The user may later change the
> table back to LOGGED, in which case the publication semantics would
> have changed silently; the table would now be published(for ALL TABLEs
> case) even though the user never changed the publication
> configuration.
>
I actually considered that before I raised the comment. Now, to set a table unlogged, a user has to remove it from the EXPECT list manually, then if he sets the table logged again, the table will be published also, unless he remembers to move the table to the EXCEPT list again. So ends up the same result.
If we want to allow users to freely toggle logged/unlogged, maybe we need to leave unlogged table in EXPECT list.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 42+ messages in thread
* RE: Review items for EXCEPT TABLE publication
@ 2026-09-10 09:41 Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
parent: vignesh C <vignesh21@gmail.com>
8 siblings, 1 reply; 42+ messages in thread
From: Hayato Kuroda (Fujitsu) @ 2026-09-10 09:41 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Dear Vignesh,
> I ran claude to identify issues related to the EXCEPT TABLE
> publication changes.
Very nice. I think this should be part of the community's routine.
> Finding #1: ALTER PUBLICATION race
> Finding #2: ALTER PUBLICATION validates against pre-lock state
To confirm, why can't we acquire the lock at the beginning of AlterPublication()
and re-check the publication state? For now AlterPublicationOptions() acquires
the AccessShareLock only if the row filter and column list may be specified, but
it could cause elog(ERROR, "tuple concurrently updated") error. It cannot be
translated thus may be surprising. Instead, can we obtain AccessExclusive
(or ShareUpdateExclusiveLock, which can block each other) at the beginning to
block concurrent operations?
Best regards,
Hayato Kuroda
FUJITSU LIMITED
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 09:42 shveta malik <shveta.malik@gmail.com>
parent: Chao Li <li.evan.chao@gmail.com>
0 siblings, 0 replies; 42+ messages in thread
From: shveta malik @ 2026-09-10 09:42 UTC (permalink / raw)
To: Chao Li <li.evan.chao@gmail.com>; +Cc: vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; shveta malik <shveta.malik@gmail.com>
On Thu, Sep 10, 2026 at 12:41 PM Chao Li <li.evan.chao@gmail.com> wrote:
>
>
>
> > On Sep 10, 2026, at 13:39, vignesh C <vignesh21@gmail.com> wrote:
> >
> > Hi,
> >
> > I ran claude to identify issues related to the EXCEPT TABLE
> > publication changes. After reviewing the findings, I found the
> > following issues that need to be fixed.
> > Finding #1: ALTER PUBLICATION race
> > AlterPublicationOptions() performs validation using the publication
> > tuple before acquiring the publication lock. A concurrent ALTER
> > PUBLICATION ... SET ALL TABLES can change puballtables while the
> > second command is waiting for the lock. Since the tuple is not
> > re-fetched after acquiring the lock, the validation can proceed based
> > on stale state while subsequent catalog lookups see the updated state.
> > In an assert-enabled build, this can trigger the assertion in
> > GetIncludedPublicationRelations() because of
> > "Assert(!GetPublication(pubid)->alltables)" and crash the backend.
> >
> > Test to reproduce:
> > -- session 1: -- session 2:
> > CREATE PUBLICATION p;
> > BEGIN;
> > ALTER PUBLICATION p
> > SET ALL TABLES;
> > ALTER PUBLICATION p
> > SET
> > (publish_via_partition_root = false);
> > -- reads puballtables=false,
> > -- enters the branch
> > -- blocks while acquiring
> > -- AccessShareLock
> > COMMIT; -- resumes and assertion fires
> >
> > The fix is to check the current publication state after acquiring the
> > publication lock.
> >
> > Regards,
> > Vignesh
> > <v1-0001-Fix-ALTER-PUBLICATION-race-with-concurrent-SET-AL.patch><v1-0005-Prevent-unlogged-tables-in-publication-EXCEPT-cla.patch><v1-0003-Fix-missing-check-in-test_except_root_partition.patch><v1-0002-Fix-ALTER-PUBLICATION-validation-race.patch><v1-0004-Fix-test-to-use-a-fresh-subscription.patch>
>
> Since each commit addresses one finding, I’ll review and reply to the commits one by one.
>
> For 0001, I have two comments:
>
> 1. I don’t think this fix completely resolves the race. With GetPublication(pubform->oid)->alltables moved after acquiring the lock, S2 has to wait for S1 to commit, so it can see the alltables change made by S1.
>
> However, tup was fetched before AlterPublicationOptions() was called. After S1 commits its update, a new tuple version has been created, so the tup held by S2 is stale. I think S2 should re-fetch the publication tuple after acquiring the lock, so that both the validation and the subsequent catalog update operate on the current tuple version.
>
> 2. From a code-structure perspective, before this patch the relation-validation block was entered only when the publication was not FOR ALL TABLES. With this patch, the outer if is entered regardless of puballtables, and when GetPublication(pubform->oid)->alltables is true, root_relids is simply left empty.
>
> This is not a problem today because the only code that follows is the foreach, which does nothing when root_relids is empty. However, if more code is added after the loop in the future, it may unintentionally run for an ALL TABLESpublication as well.
I agree here.
> I think it would be clearer and safer to keep the whole relation-validation section, including the foreach, inside the post-lock !alltables branch.
+1.
thanks
Shveta
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 10:25 vignesh C <vignesh21@gmail.com>
parent: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
0 siblings, 1 reply; 42+ messages in thread
From: vignesh C @ 2026-09-10 10:25 UTC (permalink / raw)
To: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Thu, 10 Sept 2026 at 15:11, Hayato Kuroda (Fujitsu)
<kuroda.hayato@fujitsu.com> wrote:
>
> Dear Vignesh,
>
> > I ran claude to identify issues related to the EXCEPT TABLE
> > publication changes.
>
> Very nice. I think this should be part of the community's routine.
>
> > Finding #1: ALTER PUBLICATION race
> > Finding #2: ALTER PUBLICATION validates against pre-lock state
>
> To confirm, why can't we acquire the lock at the beginning of AlterPublication()
> and re-check the publication state? For now AlterPublicationOptions() acquires
> the AccessShareLock only if the row filter and column list may be specified, but
> it could cause elog(ERROR, "tuple concurrently updated") error. It cannot be
> translated thus may be surprising. Instead, can we obtain AccessExclusive
> (or ShareUpdateExclusiveLock, which can block each other) at the beginning to
> block concurrent operations?
Thanks kuroda-san. I have addressed this in the v2 version patch
attached, however I did not change the lock mode and used the existing
AccessShareLock mode itself as I felt that should suffice. This
approach also addresses Chao's comments from [1].
[1] - https://www.postgresql.org/message-id/23BC758C-7DBC-4270-9232-2CC09C3679FB%40gmail.com
Regards,
Vignesh
Attachments:
v2-0001-Fix-ALTER-PUBLICATION-race-with-concurrent-SET-AL.patch (application/octet-stream, 3.4K) download
From d64e025081722a1fe53641b9ab38cfa81e766695 Mon Sep 17 00:00:00 2001
From: Vignesh C <c_vigneshwaran@apple.com>
Date: Wed, 9 Sep 2026 09:40:32 +0530
Subject: [PATCH v2] 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.
---
src/backend/commands/publicationcmds.c | 43 ++++++++++++++++++++------
1 file changed, 33 insertions(+), 10 deletions(-)
diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c
index 96838730fe1..091797db402 100644
--- a/src/backend/commands/publicationcmds.c
+++ b/src/backend/commands/publicationcmds.c
@@ -1057,15 +1057,6 @@ AlterPublicationOptions(ParseState *pstate, AlterPublicationStmt *stmt,
if (!pubform->puballtables && publish_via_partition_root_given &&
!publish_via_partition_root)
{
- /*
- * Lock the publication so nobody else can do anything with it. This
- * prevents concurrent alter to add partitioned table(s) with WHERE
- * clause(s) and/or column lists which we don't allow when not
- * publishing via root.
- */
- LockDatabaseObject(PublicationRelationId, pubform->oid, 0,
- AccessShareLock);
-
root_relids = GetIncludedPublicationRelations(pubform->oid,
PUBLICATION_PART_ROOT);
@@ -1659,6 +1650,7 @@ AlterPublication(ParseState *pstate, AlterPublicationStmt *stmt)
Relation rel;
HeapTuple tup;
Form_pg_publication pubform;
+ Oid pubid;
rel = table_open(PublicationRelationId, RowExclusiveLock);
@@ -1678,14 +1670,45 @@ AlterPublication(ParseState *pstate, AlterPublicationStmt *stmt)
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_PUBLICATION,
stmt->pubname);
+ pubid = pubform->oid;
+
if (stmt->options)
+ {
+ /*
+ * Lock the publication so nobody else can change it while we validate
+ * and update it. This prevents a concurrent alter from adding
+ * partitioned table(s) with WHERE clause(s) and/or column lists,
+ * which we don't allow when not publishing via root, and it also
+ * prevents the publication definition from changing (for example, via
+ * SET ALL TABLES) between the validation performed by
+ * AlterPublicationOptions() and the subsequent catalog update.
+ */
+ LockDatabaseObject(PublicationRelationId, pubid, 0,
+ AccessShareLock);
+
+ heap_freetuple(tup);
+
+ /*
+ * It is possible that by the time we acquire the lock on publication,
+ * concurrent DDL has removed it. We can test this by checking the
+ * existence of publication. We get the tuple again to avoid the risk
+ * of any publication option getting changed.
+ */
+ tup = SearchSysCacheCopy1(PUBLICATIONOID,
+ ObjectIdGetDatum(pubid));
+ if (!HeapTupleIsValid(tup))
+ ereport(ERROR,
+ errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("publication \"%s\" does not exist",
+ stmt->pubname));
+
AlterPublicationOptions(pstate, stmt, rel, tup);
+ }
else
{
List *relations = NIL;
List *exceptrelations = NIL;
List *schemaidlist = NIL;
- Oid pubid = pubform->oid;
ObjectsInPublicationToOids(stmt->pubobjects, pstate, &relations,
&exceptrelations, &schemaidlist);
--
2.55.0
^ permalink raw reply [nested|flat] 42+ messages in thread
* RE: Review items for EXCEPT TABLE publication
@ 2026-09-10 11:06 Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
parent: vignesh C <vignesh21@gmail.com>
8 siblings, 0 replies; 42+ messages in thread
From: Hayato Kuroda (Fujitsu) @ 2026-09-10 11:06 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; Chao Li <li.evan.chao@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Dear Vignesh, Chao,
> Finding #4: Test uses a stale subscription
Not critical, but DROP SUBSCRIPTION might be better to put before the DROP
PUBLICATION. Also related with the test, I feel below lines are not needed.
```
$node_subscriber->safe_psql('postgres', 'DROP SUBSCRIPTION tap_sub');
$node_publisher->safe_psql('postgres', 'DROP PUBLICATION tap_pub1');
$node_publisher->safe_psql('postgres', 'DROP PUBLICATION tap_pub2');
$node_publisher->stop('fast');
```
> > Finding #5: SET UNLOGGED on an excluded table produces an unrestorable
> > catalog state
> However, I have some concern about the design. Since a table in the EXCEPT
> list is not published anyway, do we really need to reject SET UNLOGGED? Would
> it make more sense to remove the table from the EXCEPT list and emit a NOTICE
> to inform the user?
I prefer the Vignesh's idea. For now publications are created with extactly given
settings, but your idea may break the existing rule. Can you raise existing
examples?
Best regards,
Hayato Kuroda
FUJITSU LIMITED
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 11:12 vignesh C <vignesh21@gmail.com>
parent: shveta malik <shveta.malik@gmail.com>
2 siblings, 0 replies; 42+ messages in thread
From: vignesh C @ 2026-09-10 11:12 UTC (permalink / raw)
To: shveta malik <shveta.malik@gmail.com>; +Cc: Chao Li <li.evan.chao@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Thu, 10 Sept 2026 at 14:55, shveta malik <shveta.malik@gmail.com> wrote:
>
> On Thu, Sep 10, 2026 at 1:24 PM Chao Li <li.evan.chao@gmail.com> wrote:
> >
> >
> >
> > > On Sep 10, 2026, at 13:39, vignesh C <vignesh21@gmail.com> wrote:
> > >
> > > Finding #5: SET UNLOGGED on an excluded table produces an unrestorable
> > > catalog state
> > >
> > > CREATE PUBLICATION ... FOR ALL TABLES EXCEPT (...) correctly rejects
> > > unlogged tables. However, ALTER TABLE ... SET UNLOGGED does not
> > > perform the same check. Its publication check uses
> > > GetRelationIncludedPublications(), which ignores pg_publication_rel
> > > rows marked as prexcept.
> > > As a result, the following currently succeeds:
> > > CREATE TABLE t (a int);
> > > CREATE PUBLICATION p FOR ALL TABLES EXCEPT (TABLE t);
> > > ALTER TABLE t SET UNLOGGED;
> > >
> > > This leaves an unlogged table in the publication's EXCEPT list, even
> > > though an unlogged table cannot be added to an EXCEPT clause directly.
> > > This causes failures when restoring a dump or running pg_upgrade.
> > > For example, pg_dump produces:
> > > CREATE PUBLICATION pub1 FOR ALL TABLES EXCEPT (TABLE ONLY public.t1)
> > > WITH (publish = 'insert, update, delete, truncate');
> > > where t1 is an unlogged table. Restoring the dump fails with:
> > > ERROR: cannot specify relation "public.t1" in the publication EXCEPT clause
> > > DETAIL: This operation is not supported for unlogged tables.
> > >
> > > A similar error is seen during pg_upgrade:
> > > ERROR: cannot specify relation "public.t1" in the publication EXCEPT clause
> > > DETAIL: This operation is not supported for unlogged tables.
> > >
> > > The fix is to reject changing a table to UNLOGGED when it is
> > > referenced in a publication's EXCEPT clause, similar to the existing
> > > check for tables included in a publication.
> > >
> > >
> > > Regards,
> > > Vignesh
> > > <v1-0001-Fix-ALTER-PUBLICATION-race-with-concurrent-SET-AL.patch><v1-0005-Prevent-unlogged-tables-in-publication-EXCEPT-cla.patch><v1-0003-Fix-missing-check-in-test_except_root_partition.patch><v1-0002-Fix-ALTER-PUBLICATION-validation-race.patch><v1-0004-Fix-test-to-use-a-fresh-subscription.patch>
> >
> > For v1-0005, the code change itself looks good to me.
> >
> > However, I have some concern about the design. Since a table in the EXCEPT list is not published anyway, do we really need to reject SET UNLOGGED? Would it make more sense to remove the table from the EXCEPT list and emit a NOTICE to inform the user?
>
> I had given a similar comment offlist yesterday, but upon rethinking,
> I feel automatically removing the table from the EXCEPT list is
> slightly riskier even with NOTICE given. The user may later change the
> table back to LOGGED, in which case the publication semantics would
> have changed silently; the table would now be published(for ALL TABLEs
> case) even though the user never changed the publication
> configuration.
>
> ~~
>
> I think the proposed fix is also incomplete though for partitioned tables:
>
> CREATE TABLE root (a int) PARTITION BY RANGE (a);
> CREATE TABLE part1 PARTITION OF root FOR VALUES FROM (1) TO (100);
>
> CREATE PUBLICATION root_pub FOR ALL TABLES EXCEPT (TABLE root);
>
> -- This fails:
> ALTER TABLE root SET UNLOGGED;
>
> -- But this succeeds:
> ALTER TABLE part1 SET UNLOGGED;
>
> Shouldn't the second command (for partition) fail too?
I don't think this is an issue. Only the top-most ancestor can appear
in the EXCEPT clause, and we skip publishing based on the table's
last_oid. There is also no issue with dump/restore.
Regards,
Vignesh
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 11:18 Amit Kapila <amit.kapila16@gmail.com>
parent: Chao Li <li.evan.chao@gmail.com>
0 siblings, 0 replies; 42+ messages in thread
From: Amit Kapila @ 2026-09-10 11:18 UTC (permalink / raw)
To: Chao Li <li.evan.chao@gmail.com>; +Cc: shveta malik <shveta.malik@gmail.com>; vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Thu, Sep 10, 2026 at 4:25 PM Chao Li <li.evan.chao@gmail.com> wrote:
>
> >
> > I had given a similar comment offlist yesterday, but upon rethinking,
> > I feel automatically removing the table from the EXCEPT list is
> > slightly riskier even with NOTICE given. The user may later change the
> > table back to LOGGED, in which case the publication semantics would
> > have changed silently; the table would now be published(for ALL TABLEs
> > case) even though the user never changed the publication
> > configuration.
> >
>
> I actually considered that before I raised the comment. Now, to set a table unlogged, a user has to remove it from the EXPECT list manually, then if he sets the table logged again, the table will be published also, unless he remembers to move the table to the EXCEPT list again. So ends up the same result.
>
But if She explicitly removes it from the EXCEPT list then it will be
the user's responsibility to add it again. This is better than a
silent behavior.
> If we want to allow users to freely toggle logged/unlogged, maybe we need to leave unlogged table in EXPECT list.
>
The biggest challenge with this is to have a dangling entry in
pg_publication_rel. If nothing else, the callers of
GetExcludedPublicationTables() should be careful that it can contain
unlogged relations. The existing callers are immune to this but all
the future callers need to be aware of the same and may need
additional handling. I feel this approach to fix the issue is doable
but adds more maintenance burden.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 42+ messages in thread
* RE: Review items for EXCEPT TABLE publication
@ 2026-09-10 11:41 Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
parent: vignesh C <vignesh21@gmail.com>
0 siblings, 3 replies; 42+ messages in thread
From: Hayato Kuroda (Fujitsu) @ 2026-09-10 11:41 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Dear Vignesh,
> Thanks kuroda-san. I have addressed this in the v2 version patch
> attached, however I did not change the lock mode and used the existing
> AccessShareLock mode itself as I felt that should suffice. This
> approach also addresses Chao's comments from [1].
My intention was similar but can we unify codes for re-validation?
My idea attached here could be applied atop v2.
Best regards,
Hayato Kuroda
FUJITSU LIMITED
Attachments:
v2_kuroda.diffs (application/octet-stream, 3.8K) download
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 12:22 shveta malik <shveta.malik@gmail.com>
parent: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2 siblings, 0 replies; 42+ messages in thread
From: shveta malik @ 2026-09-10 12:22 UTC (permalink / raw)
To: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; +Cc: vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; shveta malik <shveta.malik@gmail.com>
On Thu, Sep 10, 2026 at 5:11 PM Hayato Kuroda (Fujitsu)
<kuroda.hayato@fujitsu.com> wrote:
>
> Dear Vignesh,
>
> > Thanks kuroda-san. I have addressed this in the v2 version patch
> > attached, however I did not change the lock mode and used the existing
> > AccessShareLock mode itself as I felt that should suffice. This
> > approach also addresses Chao's comments from [1].
>
> My intention was similar but can we unify codes for re-validation?
> My idea attached here could be applied atop v2.
>
+1. I had similar idea in mind about this patch's correction that we
can pull the code part out in AlterPublication() for both 'if' and
'else' block.
thanks
Shveta
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 13:28 Amit Kapila <amit.kapila16@gmail.com>
parent: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2 siblings, 1 reply; 42+ messages in thread
From: Amit Kapila @ 2026-09-10 13:28 UTC (permalink / raw)
To: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; +Cc: vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Thu, Sep 10, 2026 at 5:11 PM Hayato Kuroda (Fujitsu)
<kuroda.hayato@fujitsu.com> wrote:
>
> Dear Vignesh,
>
> > Thanks kuroda-san. I have addressed this in the v2 version patch
> > attached, however I did not change the lock mode and used the existing
> > AccessShareLock mode itself as I felt that should suffice. This
> > approach also addresses Chao's comments from [1].
>
> My intention was similar but can we unify codes for re-validation?
> My idea attached here could be applied atop v2.
>
Fair enough. But why do we want to change the order of heap_freetuple
in the following change?
- heap_freetuple(tup);
+ LockDatabaseObject(PublicationRelationId, pubid, 0,
+ stmt->options ? AccessShareLock : AccessExclusiveLock);
- /*
- * It is possible that by the time we acquire the lock on publication,
- * concurrent DDL has removed it. We can test this by checking the
- * existence of publication. We get the tuple again to avoid the risk
- * of any publication option getting changed.
- */
- tup = SearchSysCacheCopy1(PUBLICATIONOID,
- ObjectIdGetDatum(pubid));
- if (!HeapTupleIsValid(tup))
- ereport(ERROR,
- errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("publication \"%s\" does not exist",
- stmt->pubname));
+ heap_freetuple(tup);
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-10 16:17 vignesh C <vignesh21@gmail.com>
parent: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2 siblings, 2 replies; 42+ messages in thread
From: vignesh C @ 2026-09-10 16:17 UTC (permalink / raw)
To: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Thu, 10 Sept 2026 at 17:11, Hayato Kuroda (Fujitsu)
<kuroda.hayato@fujitsu.com> wrote:
>
> Dear Vignesh,
>
> > Thanks kuroda-san. I have addressed this in the v2 version patch
> > attached, however I did not change the lock mode and used the existing
> > AccessShareLock mode itself as I felt that should suffice. This
> > approach also addresses Chao's comments from [1].
>
> My intention was similar but can we unify codes for re-validation?
> My idea attached here could be applied atop v2.
Thanks, this looks better. The attached v3 version incorporates these changes.
I have also addressed Amit's suggestion from [1] and the test comment
fixes from [2]. Additionally, the test changes have been consolidated
into a single v3-002 patch.
[1] - https://www.postgresql.org/message-id/CAA4eK1J-W2omce_%2BD%2BNn9syUA3DPOkKHyB1K24pXGCEpfksYkg%40mail...
[2] - https://www.postgresql.org/message-id/OS9PR01MB12149C3E3EC7D9738644CEBD8F5BF2%40OS9PR01MB12149.jpnpr...
Regards,
Vignesh
Attachments: download all (2 files, .tar.gz)
v3-0002-Improve-EXCEPT-publication-tests.patch (application/octet-stream, 3.0K) download
From cb74f395348ef9f966388ac655745ec79b19d582 Mon Sep 17 00:00:00 2001
From: Vignesh C <c_vigneshwaran@apple.com>
Date: Wed, 9 Sep 2026 10:02:30 +0530
Subject: [PATCH v3 2/2] Improve EXCEPT publication tests
Fix except publication test to ensure replication changes for an
excluded partitioned table are actually checked. Also drop and recreate
the subscription before the second multi-publication test so that it
starts with a clean state, and use safe_psql() to ensure failures are
reported.
---
src/test/subscription/t/037_except.pl | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/src/test/subscription/t/037_except.pl b/src/test/subscription/t/037_except.pl
index 43b51c8ff71..dd79fbb46e1 100644
--- a/src/test/subscription/t/037_except.pl
+++ b/src/test/subscription/t/037_except.pl
@@ -52,6 +52,10 @@ sub test_except_root_partition
$result = $node_publisher->safe_psql('postgres',
"SELECT count(*) = 0 FROM pg_logical_slot_get_binary_changes('test_slot', NULL, NULL, 'proto_version', '1', 'publication_names', 'tap_pub_part')"
);
+ is($result, qq(t),
+ "no changes for the partitioned table in the EXCEPT clause are present in the replication slot (publish_via_partition_root = $pubviaroot)"
+ );
+
$node_publisher->wait_for_catchup('tap_sub_part');
# Verify that no rows are replicated to subscriber for root or partitions.
@@ -235,7 +239,7 @@ $node_publisher->safe_psql(
CREATE PUBLICATION tap_pub2 FOR TABLE tab1;
INSERT INTO tab1 VALUES(1);
));
-$node_subscriber->psql('postgres',
+$node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub1, tap_pub2"
);
$node_subscriber->wait_for_subscription_sync($node_publisher, 'tap_sub');
@@ -249,12 +253,17 @@ is( $result, qq(1
2),
"check replication of a table in the EXCEPT clause of one publication but included by another"
);
+
+$node_subscriber->safe_psql(
+ 'postgres', qq(
+ DROP SUBSCRIPTION tap_sub;
+ TRUNCATE tab1;
+));
$node_publisher->safe_psql(
'postgres', qq(
DROP PUBLICATION tap_pub2;
TRUNCATE tab1;
));
-$node_subscriber->safe_psql('postgres', qq(TRUNCATE tab1));
# OK when a table is excluded by pub1 EXCEPT clause, but it is included by pub2
# FOR ALL TABLES.
@@ -263,7 +272,7 @@ $node_publisher->safe_psql(
CREATE PUBLICATION tap_pub2 FOR ALL TABLES;
INSERT INTO tab1 VALUES(1);
));
-$node_subscriber->psql('postgres',
+$node_subscriber->safe_psql('postgres',
"CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub1, tap_pub2"
);
$node_subscriber->wait_for_subscription_sync($node_publisher, 'tap_sub');
@@ -278,10 +287,4 @@ is( $result, qq(1
"check replication of a table in the EXCEPT clause of one publication but included by another"
);
-$node_subscriber->safe_psql('postgres', 'DROP SUBSCRIPTION tap_sub');
-$node_publisher->safe_psql('postgres', 'DROP PUBLICATION tap_pub1');
-$node_publisher->safe_psql('postgres', 'DROP PUBLICATION tap_pub2');
-
-$node_publisher->stop('fast');
-
done_testing();
--
2.55.0
v3-0001-AlterPublication-revalidate-publication-after-acq.patch (application/octet-stream, 5.1K) download
From e1a4f7ab757cf841de795143a578da32ed3f030f Mon Sep 17 00:00:00 2001
From: Vignesh C <c_vigneshwaran@apple.com>
Date: Wed, 9 Sep 2026 09:40:32 +0530
Subject: [PATCH v3 1/2] AlterPublication(): revalidate publication after
acquiring lock
AlterPublicationOptions() can use stale publication state when the
publication is modified concurrently while waiting for the publication
lock. In particular, a concurrent ALTER PUBLICATION ... SET ALL TABLES
can change puballtables, causing the validation to make decisions based
on the old value.
Similarly, a concurrent ALTER PUBLICATION can modify pg_publication_rel
while the command waits for the lock. The publication tuple is
re-fetched after acquiring the lock, but the relation validation is not
re-run, potentially leaving pg_publication_rel with a mixture of
inclusion and exclusion rows.
Acquire the publication lock before re-reading the publication state and
re-run CheckAlterPublication() after acquiring the lock so that both
publication options and relations are validated against the current
state.
---
src/backend/commands/publicationcmds.c | 73 ++++++++++++++------------
1 file changed, 39 insertions(+), 34 deletions(-)
diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c
index 96838730fe1..301050104dd 100644
--- a/src/backend/commands/publicationcmds.c
+++ b/src/backend/commands/publicationcmds.c
@@ -1057,15 +1057,6 @@ AlterPublicationOptions(ParseState *pstate, AlterPublicationStmt *stmt,
if (!pubform->puballtables && publish_via_partition_root_given &&
!publish_via_partition_root)
{
- /*
- * Lock the publication so nobody else can do anything with it. This
- * prevents concurrent alter to add partitioned table(s) with WHERE
- * clause(s) and/or column lists which we don't allow when not
- * publishing via root.
- */
- LockDatabaseObject(PublicationRelationId, pubform->oid, 0,
- AccessShareLock);
-
root_relids = GetIncludedPublicationRelations(pubform->oid,
PUBLICATION_PART_ROOT);
@@ -1659,6 +1650,10 @@ AlterPublication(ParseState *pstate, AlterPublicationStmt *stmt)
Relation rel;
HeapTuple tup;
Form_pg_publication pubform;
+ List *relations = NIL;
+ List *exceptrelations = NIL;
+ List *schemaidlist = NIL;
+ Oid pubid;
rel = table_open(PublicationRelationId, RowExclusiveLock);
@@ -1678,38 +1673,48 @@ AlterPublication(ParseState *pstate, AlterPublicationStmt *stmt)
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_PUBLICATION,
stmt->pubname);
- if (stmt->options)
- AlterPublicationOptions(pstate, stmt, rel, tup);
- else
- {
- List *relations = NIL;
- List *exceptrelations = NIL;
- List *schemaidlist = NIL;
- Oid pubid = pubform->oid;
+ pubid = pubform->oid;
+ /*
+ * Resolve publication objects to OIDs when altering the publication
+ * objects.
+ */
+ if (!stmt->options)
ObjectsInPublicationToOids(stmt->pubobjects, pstate, &relations,
&exceptrelations, &schemaidlist);
- CheckAlterPublication(stmt, tup, relations, schemaidlist);
+ heap_freetuple(tup);
- heap_freetuple(tup);
+ /*
+ * Lock the publication while we validate and update it. This prevents
+ * concurrent changes to the publication's relation and schema set, such
+ * as adding partitioned table(s) with WHERE clause(s) and/or column
+ * lists, which are not allowed when not publishing via root. It also
+ * ensures that the publication definition does not change via SET ALL
+ * TABLES between the validation performed by AlterPublicationOptions()
+ * and the subsequent catalog update.
+ */
+ LockDatabaseObject(PublicationRelationId, pubid, 0,
+ stmt->options ? AccessShareLock : AccessExclusiveLock);
- /* Lock the publication so nobody else can do anything with it. */
- LockDatabaseObject(PublicationRelationId, pubid, 0,
- AccessExclusiveLock);
+ /*
+ * It is possible that by the time we acquire the lock on publication,
+ * concurrent DDL has removed it. We can test this by checking the
+ * existence of publication. We get the tuple again to avoid the risk of
+ * any publication option getting changed.
+ */
+ tup = SearchSysCacheCopy1(PUBLICATIONOID, ObjectIdGetDatum(pubid));
+ if (!HeapTupleIsValid(tup))
+ ereport(ERROR,
+ errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("publication \"%s\" does not exist",
+ stmt->pubname));
- /*
- * It is possible that by the time we acquire the lock on publication,
- * concurrent DDL has removed it. We can test this by checking the
- * existence of publication. We get the tuple again to avoid the risk
- * of any publication option getting changed.
- */
- tup = SearchSysCacheCopy1(PUBLICATIONOID, ObjectIdGetDatum(pubid));
- if (!HeapTupleIsValid(tup))
- ereport(ERROR,
- errcode(ERRCODE_UNDEFINED_OBJECT),
- errmsg("publication \"%s\" does not exist",
- stmt->pubname));
+ if (stmt->options)
+ AlterPublicationOptions(pstate, stmt, rel, tup);
+ else
+ {
+ CheckAlterPublication(stmt, tup, relations, schemaidlist);
relations = list_concat(relations, exceptrelations);
AlterPublicationTables(stmt, tup, relations, pstate->p_sourcetext,
--
2.55.0
^ permalink raw reply [nested|flat] 42+ messages in thread
* RE: Review items for EXCEPT TABLE publication
@ 2026-09-11 01:51 Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
parent: Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 0 replies; 42+ messages in thread
From: Hayato Kuroda (Fujitsu) @ 2026-09-11 01:51 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; vignesh C <vignesh21@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Dear Amit, Vignesh,
> Fair enough. But why do we want to change the order of heap_freetuple
> in the following change?
I put heap_freetuple() just before re-obtaining the syscache. But OK for me to
put before LockDatabaseObject(). v3 patch set LGTM.
Best regards,
Hayato Kuroda
FUJITSU LIMITED
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-11 03:19 shveta malik <shveta.malik@gmail.com>
parent: vignesh C <vignesh21@gmail.com>
1 sibling, 0 replies; 42+ messages in thread
From: shveta malik @ 2026-09-11 03:19 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>; shveta malik <shveta.malik@gmail.com>
On Thu, Sep 10, 2026 at 9:47 PM vignesh C <vignesh21@gmail.com> wrote:
>
> On Thu, 10 Sept 2026 at 17:11, Hayato Kuroda (Fujitsu)
> <kuroda.hayato@fujitsu.com> wrote:
> >
> > Dear Vignesh,
> >
> > > Thanks kuroda-san. I have addressed this in the v2 version patch
> > > attached, however I did not change the lock mode and used the existing
> > > AccessShareLock mode itself as I felt that should suffice. This
> > > approach also addresses Chao's comments from [1].
> >
> > My intention was similar but can we unify codes for re-validation?
> > My idea attached here could be applied atop v2.
>
> Thanks, this looks better. The attached v3 version incorporates these changes.
> I have also addressed Amit's suggestion from [1] and the test comment
> fixes from [2]. Additionally, the test changes have been consolidated
> into a single v3-002 patch.
>
> [1] - https://www.postgresql.org/message-id/CAA4eK1J-W2omce_%2BD%2BNn9syUA3DPOkKHyB1K24pXGCEpfksYkg%40mail...
> [2] - https://www.postgresql.org/message-id/OS9PR01MB12149C3E3EC7D9738644CEBD8F5BF2%40OS9PR01MB12149.jpnpr...
>
v3.* LGTM.
thanks
Shveta
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-11 04:03 vignesh C <vignesh21@gmail.com>
parent: Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 42+ messages in thread
From: vignesh C @ 2026-09-11 04:03 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Chao Li <li.evan.chao@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Thu, 10 Sept 2026 at 15:01, Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Thu, Sep 10, 2026 at 1:24 PM Chao Li <li.evan.chao@gmail.com> wrote:
> >
> > > On Sep 10, 2026, at 13:39, vignesh C <vignesh21@gmail.com> wrote:
> > >
> > > Finding #5: SET UNLOGGED on an excluded table produces an unrestorable
> > > catalog state
> > >
> >
> > For v1-0005, the code change itself looks good to me.
> >
> > However, I have some concern about the design. Since a table in the EXCEPT list is not published anyway, do we really need to reject SET UNLOGGED? Would it make more sense to remove the table from the EXCEPT list and emit a NOTICE to inform the user?
> >
>
> I think removing the publication membership during another DDL will
> unnecessarily widen the scope of publication memberships. For example,
> consider, later one does, ALTER TABLE t SET LOGGED emits nothing, and
> t is now published by p.
>
> This is the damaging one and NOTICE in the previous message doesn't
> prevent it. Either the subscriber lacks t, in which case apply fails
> and the whole subscription
> stalls, or it has t, in which case data the user deliberately excluded
> starts flowing. Both are triggered by a local DDL statement with no
> indication that replication scope just widened.
>
> Also, it would be inconsistent with the INCLUDED case where we are
> giving ERROR. I feel giving ERROR is the right thing to do here, so
> that users can explicitly remove it from EXCEPT list and then later if
> She wants to make table LOGGED again, She can execute following steps:
> BEGIN;
> ALTER TABLE t SET LOGGED;
> ALTER PUBLICATION p SET ALL TABLES EXCEPT (TABLE t, ...);
> COMMIT;
@Chao Li What do you think about proceeding this way, to keep the
behavior simple and consistent with table publications?
That is, return an ERROR when changing an EXCEPT-listed table to
UNLOGGED, similar to the behavior for INCLUDED tables, and require the
user to explicitly remove the table from the EXCEPT list first and
then change it to UNLOGGED.
Regards,
Vignesh
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-11 05:39 Amit Kapila <amit.kapila16@gmail.com>
parent: vignesh C <vignesh21@gmail.com>
1 sibling, 0 replies; 42+ messages in thread
From: Amit Kapila @ 2026-09-11 05:39 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Thu, Sep 10, 2026 at 9:47 PM vignesh C <vignesh21@gmail.com> wrote:
>
> Thanks, this looks better. The attached v3 version incorporates these changes.
> I have also addressed Amit's suggestion from [1] and the test comment
> fixes from [2]. Additionally, the test changes have been consolidated
> into a single v3-002 patch.
>
Pushed these two patches.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-11 05:51 Amit Kapila <amit.kapila16@gmail.com>
parent: vignesh C <vignesh21@gmail.com>
8 siblings, 2 replies; 42+ messages in thread
From: Amit Kapila @ 2026-09-11 05:51 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Thu, Sep 10, 2026 at 11:09 AM vignesh C <vignesh21@gmail.com> wrote:
>
> Finding #5: SET UNLOGGED on an excluded table produces an unrestorable
> catalog state
>
+ if (!toLogged &&
+ GetRelationExcludedPublications(RelationGetRelid(rel)) != NIL)
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("cannot change table \"%s\" to unlogged because i
Can we have one unified function to check whether a table is part of
any publication and get an additional out parameter whether that is an
include or exclude table? As we can't have the same table both
included and excluded, this should work unless I am missing something.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-11 06:04 Chao Li <li.evan.chao@gmail.com>
parent: vignesh C <vignesh21@gmail.com>
0 siblings, 0 replies; 42+ messages in thread
From: Chao Li @ 2026-09-11 06:04 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
> On Sep 11, 2026, at 12:03, vignesh C <vignesh21@gmail.com> wrote:
>
> On Thu, 10 Sept 2026 at 15:01, Amit Kapila <amit.kapila16@gmail.com> wrote:
>>
>> On Thu, Sep 10, 2026 at 1:24 PM Chao Li <li.evan.chao@gmail.com> wrote:
>>>
>>>> On Sep 10, 2026, at 13:39, vignesh C <vignesh21@gmail.com> wrote:
>>>>
>>>> Finding #5: SET UNLOGGED on an excluded table produces an unrestorable
>>>> catalog state
>>>>
>>>
>>> For v1-0005, the code change itself looks good to me.
>>>
>>> However, I have some concern about the design. Since a table in the EXCEPT list is not published anyway, do we really need to reject SET UNLOGGED? Would it make more sense to remove the table from the EXCEPT list and emit a NOTICE to inform the user?
>>>
>>
>> I think removing the publication membership during another DDL will
>> unnecessarily widen the scope of publication memberships. For example,
>> consider, later one does, ALTER TABLE t SET LOGGED emits nothing, and
>> t is now published by p.
>>
>> This is the damaging one and NOTICE in the previous message doesn't
>> prevent it. Either the subscriber lacks t, in which case apply fails
>> and the whole subscription
>> stalls, or it has t, in which case data the user deliberately excluded
>> starts flowing. Both are triggered by a local DDL statement with no
>> indication that replication scope just widened.
>>
>> Also, it would be inconsistent with the INCLUDED case where we are
>> giving ERROR. I feel giving ERROR is the right thing to do here, so
>> that users can explicitly remove it from EXCEPT list and then later if
>> She wants to make table LOGGED again, She can execute following steps:
>> BEGIN;
>> ALTER TABLE t SET LOGGED;
>> ALTER PUBLICATION p SET ALL TABLES EXCEPT (TABLE t, ...);
>> COMMIT;
>
> @Chao Li What do you think about proceeding this way, to keep the
> behavior simple and consistent with table publications?
> That is, return an ERROR when changing an EXCEPT-listed table to
> UNLOGGED, similar to the behavior for INCLUDED tables, and require the
> user to explicitly remove the table from the EXCEPT list first and
> then change it to UNLOGGED.
>
> Regards,
> Vignesh
I am fine with that.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-11 06:29 Peter Smith <smithpb2250@gmail.com>
parent: Amit Kapila <amit.kapila16@gmail.com>
1 sibling, 0 replies; 42+ messages in thread
From: Peter Smith @ 2026-09-11 06:29 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Fri, Sep 11, 2026 at 3:51 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Thu, Sep 10, 2026 at 11:09 AM vignesh C <vignesh21@gmail.com> wrote:
> >
> > Finding #5: SET UNLOGGED on an excluded table produces an unrestorable
> > catalog state
> >
>
> + if (!toLogged &&
> + GetRelationExcludedPublications(RelationGetRelid(rel)) != NIL)
> + ereport(ERROR,
> + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
> + errmsg("cannot change table \"%s\" to unlogged because i
>
> Can we have one unified function to check whether a table is part of
> any publication and get an additional out parameter whether that is an
> include or exclude table? As we can't have the same table both
> included and excluded, this should work unless I am missing something.
>
I did not understand "we can't have the same table both included and excluded".
What about:
test_pub=# CREATE PUBLICATION pub1 FOR ALL TABLES EXCEPT (TABLE t1);
CREATE PUBLICATION
test_pub=# CREATE PUBLICATION pub2 FOR TABLE t1;
CREATE PUBLICATION
test_pub=# select * from pg_publication_rel;
oid | prpubid | prrelid | prexcept | prqual | prattrs
-------+---------+---------+----------+--------+---------
16392 | 16391 | 16387 | t | |
16394 | 16393 | 16387 | f | |
(2 rows)
======
Kind Regards,
Peter Smith.
Fujitsu Australia
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-11 06:33 vignesh C <vignesh21@gmail.com>
parent: Amit Kapila <amit.kapila16@gmail.com>
1 sibling, 1 reply; 42+ messages in thread
From: vignesh C @ 2026-09-11 06:33 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Fri, 11 Sept 2026 at 11:21, Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Thu, Sep 10, 2026 at 11:09 AM vignesh C <vignesh21@gmail.com> wrote:
> >
> > Finding #5: SET UNLOGGED on an excluded table produces an unrestorable
> > catalog state
> >
>
> + if (!toLogged &&
> + GetRelationExcludedPublications(RelationGetRelid(rel)) != NIL)
> + ereport(ERROR,
> + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
> + errmsg("cannot change table \"%s\" to unlogged because i
>
> Can we have one unified function to check whether a table is part of
> any publication and get an additional out parameter whether that is an
> include or exclude table? As we can't have the same table both
> included and excluded, this should work unless I am missing something.
Here is an updated v4 version patch to handle the same.
Regards,
Vignesh
Attachments:
v4-0001-Prevent-unlogged-tables-in-publication-EXCEPT-cla.patch (application/octet-stream, 7.5K) download
From 757ece6bf5086ccd365b5d6b10b1918a352c1b95 Mon Sep 17 00:00:00 2001
From: Vignesh C <c_vigneshwaran@apple.com>
Date: Thu, 10 Sep 2026 09:54:03 +0530
Subject: [PATCH v4] Prevent unlogged tables in publication EXCEPT clauses
Reject changing a table to UNLOGGED when it is referenced by a publication's
EXCEPT clause. This keeps the catalog state consistent with the restriction
that unlogged tables cannot be specified in publication EXCEPT clauses and
ensures that pg_dump can recreate the publication.
Author: Vignesh C <vignesh21@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Discussion: https://postgr.es/m/CALDaNm1r2MkGu6h8zgU1Kj1sX-FcMQ7wGTeLSnhx-5joiyXEvg@mail.gmail.com
Backpatch-through: 19, where it was introduced
---
src/backend/catalog/pg_publication.c | 35 +++++++++++++++++++++++
src/backend/commands/tablecmds.c | 33 +++++++++++++++------
src/include/catalog/pg_publication.h | 1 +
src/test/regress/expected/publication.out | 10 +++++++
src/test/regress/sql/publication.sql | 8 ++++++
5 files changed, 78 insertions(+), 9 deletions(-)
diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c
index 12af7d15536..7516b0107e7 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -928,6 +928,41 @@ GetRelationExcludedPublications(Oid relid)
return get_relation_publications(relid, true);
}
+/*
+ * Check whether the relation is referenced by any publication.
+ *
+ * Returns true if the relation has a pg_publication_rel entry, and sets
+ * *isexcept according to whether that entry names the relation in the
+ * publication's EXCEPT clause rather than including it in the publication.
+ *
+ * This examines only the first entry found, so it avoids building a list of
+ * publication oids when the caller only needs to know whether the relation is
+ * referenced and in which way.
+ */
+bool
+RelationHasPublication(Oid relid, bool *isexcept)
+{
+ CatCList *pubrellist;
+ bool found = false;
+
+ /* Every entry in this list is for relid, so the first one will do. */
+ pubrellist = SearchSysCacheList1(PUBLICATIONRELMAP,
+ ObjectIdGetDatum(relid));
+ if (pubrellist->n_members > 0)
+ {
+ HeapTuple tup = &pubrellist->members[0]->tuple;
+ Form_pg_publication_rel pubrel;
+
+ pubrel = (Form_pg_publication_rel) GETSTRUCT(tup);
+ *isexcept = pubrel->prexcept;
+ found = true;
+ }
+
+ ReleaseSysCacheList(pubrellist);
+
+ return found;
+}
+
/*
* Internal function to get the list of relation oids for a publication.
*
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8dc70bfa0f1..89ea97b541a 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -19541,16 +19541,31 @@ ATPrepChangePersistence(AlteredTableInfo *tab, Relation rel, bool toLogged)
}
/*
- * Check that the table is not part of any publication when changing to
- * UNLOGGED, as UNLOGGED tables can't be published.
+ * UNLOGGED tables cannot be published, and they are not allowed in a
+ * publication's EXCEPT clause either, so reject the change if the table
+ * is referenced by a publication in either way.
*/
- if (!toLogged &&
- GetRelationIncludedPublications(RelationGetRelid(rel)) != NIL)
- ereport(ERROR,
- (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
- errmsg("cannot change table \"%s\" to unlogged because it is part of a publication",
- RelationGetRelationName(rel)),
- errdetail("Unlogged relations cannot be replicated.")));
+ if (!toLogged)
+ {
+ bool isexcept;
+
+ if (RelationHasPublication(RelationGetRelid(rel), &isexcept))
+ {
+ if (isexcept)
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("cannot change table \"%s\" to unlogged because it is referenced in a publication EXCEPT clause",
+ RelationGetRelationName(rel)),
+ errdetail("Unlogged relations cannot be specified in a publication EXCEPT clause."),
+ errhint("Remove the table from the EXCEPT clause using ALTER PUBLICATION ... SET ALL TABLES first.")));
+ else
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("cannot change table \"%s\" to unlogged because it is part of a publication",
+ RelationGetRelationName(rel)),
+ errdetail("Unlogged relations cannot be replicated.")));
+ }
+ }
/*
* Check existing foreign key constraints to preserve the invariant that
diff --git a/src/include/catalog/pg_publication.h b/src/include/catalog/pg_publication.h
index 89b4bb14f62..2d62972976e 100644
--- a/src/include/catalog/pg_publication.h
+++ b/src/include/catalog/pg_publication.h
@@ -157,6 +157,7 @@ extern Publication *GetPublication(Oid pubid);
extern Publication *GetPublicationByName(const char *pubname, bool missing_ok);
extern List *GetRelationIncludedPublications(Oid relid);
extern List *GetRelationExcludedPublications(Oid relid);
+extern bool RelationHasPublication(Oid relid, bool *isexcept);
/*---------
* Expected values for pub_partopt parameter of
diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.out
index 4f21462cc17..a83f0ccdcb8 100644
--- a/src/test/regress/expected/publication.out
+++ b/src/test/regress/expected/publication.out
@@ -279,6 +279,16 @@ CREATE PUBLICATION testpub_foralltables_excepttable2 FOR ALL TABLES EXCEPT (test
ERROR: syntax error at or near "testpub_tbl1"
LINE 1: ..._foralltables_excepttable2 FOR ALL TABLES EXCEPT (testpub_tb...
^
+-- A table in an EXCEPT clause cannot be changed to UNLOGGED.
+CREATE TABLE testpub_exc_unlogged_tbl (a int);
+CREATE PUBLICATION testpub_exc_unlogged FOR ALL TABLES EXCEPT (TABLE testpub_exc_unlogged_tbl);
+-- fail - the table is referenced in a publication EXCEPT clause
+ALTER TABLE testpub_exc_unlogged_tbl SET UNLOGGED;
+ERROR: cannot change table "testpub_exc_unlogged_tbl" to unlogged because it is referenced in a publication EXCEPT clause
+DETAIL: Unlogged relations cannot be specified in a publication EXCEPT clause.
+HINT: Remove the table from the EXCEPT clause using ALTER PUBLICATION ... SET ALL TABLES first.
+DROP PUBLICATION testpub_exc_unlogged;
+DROP TABLE testpub_exc_unlogged_tbl;
---------------------------------------------
-- SET ALL TABLES/SEQUENCES
---------------------------------------------
diff --git a/src/test/regress/sql/publication.sql b/src/test/regress/sql/publication.sql
index fac54b02e27..80c244c9138 100644
--- a/src/test/regress/sql/publication.sql
+++ b/src/test/regress/sql/publication.sql
@@ -126,6 +126,14 @@ CREATE PUBLICATION testpub_foralltables_excepttable1 FOR ALL TABLES EXCEPT (TABL
-- fail - first table in the EXCEPT list should use TABLE keyword
CREATE PUBLICATION testpub_foralltables_excepttable2 FOR ALL TABLES EXCEPT (testpub_tbl1, testpub_tbl2);
+-- A table in an EXCEPT clause cannot be changed to UNLOGGED.
+CREATE TABLE testpub_exc_unlogged_tbl (a int);
+CREATE PUBLICATION testpub_exc_unlogged FOR ALL TABLES EXCEPT (TABLE testpub_exc_unlogged_tbl);
+-- fail - the table is referenced in a publication EXCEPT clause
+ALTER TABLE testpub_exc_unlogged_tbl SET UNLOGGED;
+DROP PUBLICATION testpub_exc_unlogged;
+DROP TABLE testpub_exc_unlogged_tbl;
+
---------------------------------------------
-- SET ALL TABLES/SEQUENCES
---------------------------------------------
--
2.55.0
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-11 07:04 Peter Smith <smithpb2250@gmail.com>
parent: vignesh C <vignesh21@gmail.com>
0 siblings, 1 reply; 42+ messages in thread
From: Peter Smith @ 2026-09-11 07:04 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Fri, Sep 11, 2026 at 4:34 PM vignesh C <vignesh21@gmail.com> wrote:
>
> On Fri, 11 Sept 2026 at 11:21, Amit Kapila <amit.kapila16@gmail.com> wrote:
> >
> > On Thu, Sep 10, 2026 at 11:09 AM vignesh C <vignesh21@gmail.com> wrote:
> > >
> > > Finding #5: SET UNLOGGED on an excluded table produces an unrestorable
> > > catalog state
> > >
> >
> > + if (!toLogged &&
> > + GetRelationExcludedPublications(RelationGetRelid(rel)) != NIL)
> > + ereport(ERROR,
> > + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
> > + errmsg("cannot change table \"%s\" to unlogged because i
> >
> > Can we have one unified function to check whether a table is part of
> > any publication and get an additional out parameter whether that is an
> > include or exclude table? As we can't have the same table both
> > included and excluded, this should work unless I am missing something.
>
> Here is an updated v4 version patch to handle the same.
>
In my earlier example, there are both precept t and f.
Won't your v4 new function return a random *isexcept result based on
the first one it stumbles upon?
IIUC, that `isexcept` out parameter should maybe be called
`has_any_except`, and you should iterate until you find the first
prexcept==true or find none.
======
[1] https://www.postgresql.org/message-id/CAHut%2BPunLReA86mPmi7Wr1-Hd_TnhtM1%2BKo8Bc6HhBz1LRjQNg%40mail...
Kind Regards,
Peter Smith.
Fujitsu Australia
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-11 07:22 Amit Kapila <amit.kapila16@gmail.com>
parent: Peter Smith <smithpb2250@gmail.com>
0 siblings, 1 reply; 42+ messages in thread
From: Amit Kapila @ 2026-09-11 07:22 UTC (permalink / raw)
To: Peter Smith <smithpb2250@gmail.com>; +Cc: vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Fri, Sep 11, 2026 at 12:34 PM Peter Smith <smithpb2250@gmail.com> wrote:
>
> In my earlier example, there are both precept t and f.
>
> Won't your v4 new function return a random *isexcept result based on
> the first one it stumbles upon?
>
Yes, but how does that matter? We just don't want the operation to
proceed when the table is part of publication, users anyway need to
fix it before proceeding.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-11 07:42 Peter Smith <smithpb2250@gmail.com>
parent: Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 42+ messages in thread
From: Peter Smith @ 2026-09-11 07:42 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Fri, Sep 11, 2026 at 5:22 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Fri, Sep 11, 2026 at 12:34 PM Peter Smith <smithpb2250@gmail.com> wrote:
> >
> > In my earlier example, there are both precept t and f.
> >
> > Won't your v4 new function return a random *isexcept result based on
> > the first one it stumbles upon?
> >
>
> Yes, but how does that matter? We just don't want the operation to
> proceed when the table is part of publication, users anyway need to
> fix it before proceeding.
>
OTOH it doesn't matter because they are both problems the user must
fix. But won't it be better to get a consistent/deterministic error
message for the same problem?
e.g.1
test_pub=# CREATE PUBLICATION pub1 FOR ALL TABLES EXCEPT (TABLE t1);
CREATE PUBLICATION
test_pub=# CREATE PUBLICATION pub2 FOR TABLE t1;
CREATE PUBLICATION
test_pub=# select * from pg_publication_rel;
oid | prpubid | prrelid | prexcept | prqual | prattrs
-------+---------+---------+----------+--------+---------
16392 | 16391 | 16387 | t | |
16394 | 16393 | 16387 | f | |
(2 rows)
e.g.2
test_pub=# DROP publication pub1;
DROP PUBLICATION
test_pub=# DROP publication pub2;
DROP PUBLICATION
test_pub=# CREATE PUBLICATION pub2 FOR TABLE t1;
CREATE PUBLICATION
test_pub=# CREATE PUBLICATION pub1 FOR ALL TABLES EXCEPT (TABLE t1);
CREATE PUBLICATION
test_pub=# select * from pg_publication_rel;
oid | prpubid | prrelid | prexcept | prqual | prattrs
-------+---------+---------+----------+--------+---------
16396 | 16395 | 16387 | f | |
16398 | 16397 | 16387 | t | |
(2 rows)
Everything there is identical. Same pub names, same table
exclsions/inclusions etc. But the order of operations is different, so
the order of pg_publication_rel entries is different, so the *isexcept
returned from that function is different, so the user sees 2 different
error messages for the same problem.
That just seemed a bit strange to me. Won't that kind of
non-determinism also potentially break BF?
======
Kind Regards,
Peter Smith.
Fujitsu Australia
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-11 08:03 Amit Kapila <amit.kapila16@gmail.com>
parent: Peter Smith <smithpb2250@gmail.com>
0 siblings, 1 reply; 42+ messages in thread
From: Amit Kapila @ 2026-09-11 08:03 UTC (permalink / raw)
To: Peter Smith <smithpb2250@gmail.com>; +Cc: vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Fri, Sep 11, 2026 at 1:13 PM Peter Smith <smithpb2250@gmail.com> wrote:
>
> On Fri, Sep 11, 2026 at 5:22 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> >
> >
> > Yes, but how does that matter? We just don't want the operation to
> > proceed when the table is part of publication, users anyway need to
> > fix it before proceeding.
> >
>
> OTOH it doesn't matter because they are both problems the user must
> fix. But won't it be better to get a consistent/deterministic error
> message for the same problem?
>
Sure, but to distinguish ERROR-type, extra scan on catalog seems
costly. If you can avoid extra scans and or more cycles on scanning
catalog and still be able to manage this difference, then it is worth
considering.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-11 08:27 Peter Smith <smithpb2250@gmail.com>
parent: Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 1 reply; 42+ messages in thread
From: Peter Smith @ 2026-09-11 08:27 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Fri, Sep 11, 2026 at 6:03 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> On Fri, Sep 11, 2026 at 1:13 PM Peter Smith <smithpb2250@gmail.com> wrote:
> >
> > On Fri, Sep 11, 2026 at 5:22 PM Amit Kapila <amit.kapila16@gmail.com> wrote:
> > >
> > >
> > > Yes, but how does that matter? We just don't want the operation to
> > > proceed when the table is part of publication, users anyway need to
> > > fix it before proceeding.
> > >
> >
> > OTOH it doesn't matter because they are both problems the user must
> > fix. But won't it be better to get a consistent/deterministic error
> > message for the same problem?
> >
>
> Sure, but to distinguish ERROR-type, extra scan on catalog seems
> costly. If you can avoid extra scans and or more cycles on scanning
> catalog and still be able to manage this difference, then it is worth
> considering.
>
+ if (!toLogged)
+ {
+ bool isexcept;
+
+ if (RelationHasPublication(RelationGetRelid(rel), &isexcept))
+ {
+ if (isexcept)
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("cannot change table \"%s\" to unlogged because it is
referenced in a publication EXCEPT clause",
+ RelationGetRelationName(rel)),
+ errdetail("Unlogged relations cannot be specified in a publication
EXCEPT clause."),
+ errhint("Remove the table from the EXCEPT clause using ALTER
PUBLICATION ... SET ALL TABLES first.")));
+ else
+ ereport(ERROR,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("cannot change table \"%s\" to unlogged because it is part of
a publication",
+ RelationGetRelationName(rel)),
+ errdetail("Unlogged relations cannot be replicated.")));
+ }
+ }
I don't really see what is gained by splitting those error messages,
since the user will get an indeterminate one, and either way they have
to fix it
IMO, a single unified message could be a simpler/better choice here:
e.g.
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("cannot change table \"%s\" to unlogged because it is
referenced by a publication",
RelationGetRelationName(rel)),
errdetail("Unlogged relations cannot be published or excluded via
an EXCEPT clause."),
errhint("Remove the table from the publication first.")));
======
Kind Regards,
Peter Smith.
Fujitsu Australia
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-11 09:43 vignesh C <vignesh21@gmail.com>
parent: Peter Smith <smithpb2250@gmail.com>
0 siblings, 1 reply; 42+ messages in thread
From: vignesh C @ 2026-09-11 09:43 UTC (permalink / raw)
To: Peter Smith <smithpb2250@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Fri, 11 Sept 2026 at 13:57, Peter Smith <smithpb2250@gmail.com> wrote:
>
> I don't really see what is gained by splitting those error messages,
> since the user will get an indeterminate one, and either way they have
> to fix it
>
> IMO, a single unified message could be a simpler/better choice here:
>
> e.g.
>
> ereport(ERROR,
> (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
> errmsg("cannot change table \"%s\" to unlogged because it is
> referenced by a publication",
> RelationGetRelationName(rel)),
> errdetail("Unlogged relations cannot be published or excluded via
> an EXCEPT clause."),
> errhint("Remove the table from the publication first.")));
I agree with this approach. A single unified error message is better,
especially since the user needs to remove the table from the
publication either way.
Regards,
Vignesh
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-11 11:06 Amit Kapila <amit.kapila16@gmail.com>
parent: vignesh C <vignesh21@gmail.com>
0 siblings, 1 reply; 42+ messages in thread
From: Amit Kapila @ 2026-09-11 11:06 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: Peter Smith <smithpb2250@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Fri, Sep 11, 2026 at 3:13 PM vignesh C <vignesh21@gmail.com> wrote:
>
> On Fri, 11 Sept 2026 at 13:57, Peter Smith <smithpb2250@gmail.com> wrote:
> >
> > I don't really see what is gained by splitting those error messages,
> > since the user will get an indeterminate one, and either way they have
> > to fix it
> >
> > IMO, a single unified message could be a simpler/better choice here:
> >
> > e.g.
> >
> > ereport(ERROR,
> > (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
> > errmsg("cannot change table \"%s\" to unlogged because it is
> > referenced by a publication",
> > RelationGetRelationName(rel)),
> > errdetail("Unlogged relations cannot be published or excluded via
> > an EXCEPT clause."),
> > errhint("Remove the table from the publication first.")));
>
> I agree with this approach. A single unified error message is better,
> especially since the user needs to remove the table from the
> publication either way.
>
I am fine with the single message but how about changing the HINT to:
"Drop the table from the publication, or remove it from the
publication's EXCEPT clause, first." because the proposed message is
not suitable for the EXCEPT case.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-11 11:59 vignesh C <vignesh21@gmail.com>
parent: Amit Kapila <amit.kapila16@gmail.com>
0 siblings, 2 replies; 42+ messages in thread
From: vignesh C @ 2026-09-11 11:59 UTC (permalink / raw)
To: Amit Kapila <amit.kapila16@gmail.com>; +Cc: Peter Smith <smithpb2250@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Fri, 11 Sept 2026 at 16:36, Amit Kapila <amit.kapila16@gmail.com> wrote:
>
> I am fine with the single message but how about changing the HINT to:
> "Drop the table from the publication, or remove it from the
> publication's EXCEPT clause, first." because the proposed message is
> not suitable for the EXCEPT case.
Here is an updated v5 version to handle the suggested change.
Regards,
Vignesh
Attachments:
v5-0001-Prevent-unlogged-tables-in-publication-EXCEPT-cla.patch (application/octet-stream, 6.4K) download
From 99ac8e11925f5370abac97a1df2cf6266f9903be Mon Sep 17 00:00:00 2001
From: Vignesh C <vignesh21@gmail.com>
Date: Thu, 10 Sep 2026 09:54:03 +0530
Subject: [PATCH v5] Prevent unlogged tables in publication EXCEPT clauses
Reject changing a table to UNLOGGED when it is referenced by a publication's
EXCEPT clause. This keeps the catalog state consistent with the restriction
that unlogged tables cannot be specified in publication EXCEPT clauses and
ensures that pg_dump can recreate the publication.
Author: Vignesh C <vignesh21@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Peter Smith <smithpb2250@gmail.com>
Discussion: https://postgr.es/m/CALDaNm1r2MkGu6h8zgU1Kj1sX-FcMQ7wGTeLSnhx-5joiyXEvg@mail.gmail.com
Backpatch-through: 19, where it was introduced
---
src/backend/catalog/pg_publication.c | 19 +++++++++++++++++++
src/backend/commands/tablecmds.c | 13 +++++++------
src/include/catalog/pg_publication.h | 1 +
src/test/regress/expected/publication.out | 10 ++++++++++
src/test/regress/sql/publication.sql | 8 ++++++++
5 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c
index 26c86f667b9..6b752c4c738 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -937,6 +937,25 @@ GetRelationExcludedPublications(Oid relid)
return get_relation_publications(relid, true);
}
+/*
+ * Check whether the relation is referenced by any publication, either as a
+ * published relation or in a publication's EXCEPT clause.
+ */
+bool
+RelationHasPublication(Oid relid)
+{
+ CatCList *pubrellist;
+ bool found;
+
+ pubrellist = SearchSysCacheList1(PUBLICATIONRELMAP,
+ ObjectIdGetDatum(relid));
+ found = (pubrellist->n_members > 0);
+
+ ReleaseSysCacheList(pubrellist);
+
+ return found;
+}
+
/*
* Internal function to get the list of relation oids for a publication.
*
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 8dc70bfa0f1..ef32a3fee15 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -19541,16 +19541,17 @@ ATPrepChangePersistence(AlteredTableInfo *tab, Relation rel, bool toLogged)
}
/*
- * Check that the table is not part of any publication when changing to
- * UNLOGGED, as UNLOGGED tables can't be published.
+ * UNLOGGED tables can neither be published nor be named in a publication's
+ * EXCEPT clause, so reject the change if the table is referenced by any
+ * publication.
*/
- if (!toLogged &&
- GetRelationIncludedPublications(RelationGetRelid(rel)) != NIL)
+ if (!toLogged && RelationHasPublication(RelationGetRelid(rel)))
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
- errmsg("cannot change table \"%s\" to unlogged because it is part of a publication",
+ errmsg("cannot change table \"%s\" to unlogged because it is referenced by a publication",
RelationGetRelationName(rel)),
- errdetail("Unlogged relations cannot be replicated.")));
+ errdetail("Unlogged relations cannot be published or excluded via an EXCEPT clause."),
+ errhint("Drop the table from the publication, or remove it from the publication's EXCEPT clause, first.")));
/*
* Check existing foreign key constraints to preserve the invariant that
diff --git a/src/include/catalog/pg_publication.h b/src/include/catalog/pg_publication.h
index 89b4bb14f62..5d1e6c54a85 100644
--- a/src/include/catalog/pg_publication.h
+++ b/src/include/catalog/pg_publication.h
@@ -157,6 +157,7 @@ extern Publication *GetPublication(Oid pubid);
extern Publication *GetPublicationByName(const char *pubname, bool missing_ok);
extern List *GetRelationIncludedPublications(Oid relid);
extern List *GetRelationExcludedPublications(Oid relid);
+extern bool RelationHasPublication(Oid relid);
/*---------
* Expected values for pub_partopt parameter of
diff --git a/src/test/regress/expected/publication.out b/src/test/regress/expected/publication.out
index 4f21462cc17..fe602c4538e 100644
--- a/src/test/regress/expected/publication.out
+++ b/src/test/regress/expected/publication.out
@@ -279,6 +279,16 @@ CREATE PUBLICATION testpub_foralltables_excepttable2 FOR ALL TABLES EXCEPT (test
ERROR: syntax error at or near "testpub_tbl1"
LINE 1: ..._foralltables_excepttable2 FOR ALL TABLES EXCEPT (testpub_tb...
^
+-- A table in an EXCEPT clause cannot be changed to UNLOGGED.
+CREATE TABLE testpub_exc_unlogged_tbl (a int);
+CREATE PUBLICATION testpub_exc_unlogged FOR ALL TABLES EXCEPT (TABLE testpub_exc_unlogged_tbl);
+-- fail - the table is referenced in a publication EXCEPT clause
+ALTER TABLE testpub_exc_unlogged_tbl SET UNLOGGED;
+ERROR: cannot change table "testpub_exc_unlogged_tbl" to unlogged because it is referenced by a publication
+DETAIL: Unlogged relations cannot be published or excluded via an EXCEPT clause.
+HINT: Drop the table from the publication, or remove it from the publication's EXCEPT clause, first.
+DROP PUBLICATION testpub_exc_unlogged;
+DROP TABLE testpub_exc_unlogged_tbl;
---------------------------------------------
-- SET ALL TABLES/SEQUENCES
---------------------------------------------
diff --git a/src/test/regress/sql/publication.sql b/src/test/regress/sql/publication.sql
index fac54b02e27..80c244c9138 100644
--- a/src/test/regress/sql/publication.sql
+++ b/src/test/regress/sql/publication.sql
@@ -126,6 +126,14 @@ CREATE PUBLICATION testpub_foralltables_excepttable1 FOR ALL TABLES EXCEPT (TABL
-- fail - first table in the EXCEPT list should use TABLE keyword
CREATE PUBLICATION testpub_foralltables_excepttable2 FOR ALL TABLES EXCEPT (testpub_tbl1, testpub_tbl2);
+-- A table in an EXCEPT clause cannot be changed to UNLOGGED.
+CREATE TABLE testpub_exc_unlogged_tbl (a int);
+CREATE PUBLICATION testpub_exc_unlogged FOR ALL TABLES EXCEPT (TABLE testpub_exc_unlogged_tbl);
+-- fail - the table is referenced in a publication EXCEPT clause
+ALTER TABLE testpub_exc_unlogged_tbl SET UNLOGGED;
+DROP PUBLICATION testpub_exc_unlogged;
+DROP TABLE testpub_exc_unlogged_tbl;
+
---------------------------------------------
-- SET ALL TABLES/SEQUENCES
---------------------------------------------
--
2.55.0
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-14 04:22 Amit Kapila <amit.kapila16@gmail.com>
parent: vignesh C <vignesh21@gmail.com>
1 sibling, 0 replies; 42+ messages in thread
From: Amit Kapila @ 2026-09-14 04:22 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: Peter Smith <smithpb2250@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Fri, Sep 11, 2026 at 5:29 PM vignesh C <vignesh21@gmail.com> wrote:
>
> On Fri, 11 Sept 2026 at 16:36, Amit Kapila <amit.kapila16@gmail.com> wrote:
> >
> > I am fine with the single message but how about changing the HINT to:
> > "Drop the table from the publication, or remove it from the
> > publication's EXCEPT clause, first." because the proposed message is
> > not suitable for the EXCEPT case.
>
> Here is an updated v5 version to handle the suggested change.
>
Thanks, Pushed.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-14 04:40 Peter Smith <smithpb2250@gmail.com>
parent: vignesh C <vignesh21@gmail.com>
1 sibling, 1 reply; 42+ messages in thread
From: Peter Smith @ 2026-09-14 04:40 UTC (permalink / raw)
To: vignesh C <vignesh21@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Fri, Sep 11, 2026 at 9:59 PM vignesh C <vignesh21@gmail.com> wrote:
>
> On Fri, 11 Sept 2026 at 16:36, Amit Kapila <amit.kapila16@gmail.com> wrote:
> >
> > I am fine with the single message but how about changing the HINT to:
> > "Drop the table from the publication, or remove it from the
> > publication's EXCEPT clause, first." because the proposed message is
> > not suitable for the EXCEPT case.
>
> Here is an updated v5 version to handle the suggested change.
>
Hi Vignesh.
(I was about to post my v5 review comments when I saw this was already
pushed -- posting anyway)
+ errhint("Drop the table from the publication, or remove it from the
publication's EXCEPT clause, first.")));
Looks good, but isn't it more common for an errhint to say what
command to use instead of just "make this happen"?
e.g.
"First use ALTER PUBLICATION ... to drop the table from the
publication, or to remove it from the publication's EXCEPT clause."
======
Kind Regards,
Peter Smith
Fujitsu Australia
^ permalink raw reply [nested|flat] 42+ messages in thread
* RE: Review items for EXCEPT TABLE publication
@ 2026-09-14 05:34 Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
parent: Peter Smith <smithpb2250@gmail.com>
0 siblings, 1 reply; 42+ messages in thread
From: Hayato Kuroda (Fujitsu) @ 2026-09-14 05:34 UTC (permalink / raw)
To: Peter Smith <smithpb2250@gmail.com>; vignesh C <vignesh21@gmail.com>; +Cc: Amit Kapila <amit.kapila16@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Dear Peter,
> Looks good, but isn't it more common for an errhint to say what
> command to use instead of just "make this happen"?
>
> e.g.
> "First use ALTER PUBLICATION ... to drop the table from the
> publication, or to remove it from the publication's EXCEPT clause."
Possible, but other lines refer the FULL command in the notation. Like
ALTER TABLE ... ALTER CONSTRAINT ... INHERIT,
ALTER DATABASE ... REFRESH COLLATION VERSION,
ALTER SUBSCRIPTION ... SET PUBLICATION ... WITH (refresh = false).
Based on that current style may be more appropriate unless exact commands
are referred there.
Best regards,
Hayato Kuroda
FUJITSU LIMITED
^ permalink raw reply [nested|flat] 42+ messages in thread
* Re: Review items for EXCEPT TABLE publication
@ 2026-09-14 05:43 Amit Kapila <amit.kapila16@gmail.com>
parent: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
0 siblings, 0 replies; 42+ messages in thread
From: Amit Kapila @ 2026-09-14 05:43 UTC (permalink / raw)
To: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>; +Cc: Peter Smith <smithpb2250@gmail.com>; vignesh C <vignesh21@gmail.com>; PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
On Mon, Sep 14, 2026 at 11:04 AM Hayato Kuroda (Fujitsu)
<kuroda.hayato@fujitsu.com> wrote:
>
> > Looks good, but isn't it more common for an errhint to say what
> > command to use instead of just "make this happen"?
> >
> > e.g.
> > "First use ALTER PUBLICATION ... to drop the table from the
> > publication, or to remove it from the publication's EXCEPT clause."
>
> Possible, but other lines refer the FULL command in the notation. Like
> ALTER TABLE ... ALTER CONSTRAINT ... INHERIT,
> ALTER DATABASE ... REFRESH COLLATION VERSION,
> ALTER SUBSCRIPTION ... SET PUBLICATION ... WITH (refresh = false).
>
> Based on that current style may be more appropriate unless exact commands
> are referred there.
>
+1. We can use full commands here but that will make the hint longer
than usual cases, so I also would prefer the current message.
--
With Regards,
Amit Kapila.
^ permalink raw reply [nested|flat] 42+ messages in thread
end of thread, other threads:[~2026-09-14 05:43 UTC | newest]
Thread overview: 42+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-09-10 05:39 Review items for EXCEPT TABLE publication vignesh C <vignesh21@gmail.com>
2026-09-10 05:45 ` Amit Kapila <amit.kapila16@gmail.com>
2026-09-10 06:19 ` vignesh C <vignesh21@gmail.com>
2026-09-10 07:10 ` Chao Li <li.evan.chao@gmail.com>
2026-09-10 09:42 ` shveta malik <shveta.malik@gmail.com>
2026-09-10 07:17 ` Chao Li <li.evan.chao@gmail.com>
2026-09-10 07:23 ` Chao Li <li.evan.chao@gmail.com>
2026-09-10 07:36 ` Chao Li <li.evan.chao@gmail.com>
2026-09-10 07:53 ` Chao Li <li.evan.chao@gmail.com>
2026-09-10 09:25 ` shveta malik <shveta.malik@gmail.com>
2026-09-10 09:36 ` shveta malik <shveta.malik@gmail.com>
2026-09-10 09:37 ` Chao Li <li.evan.chao@gmail.com>
2026-09-10 11:18 ` Amit Kapila <amit.kapila16@gmail.com>
2026-09-10 11:12 ` vignesh C <vignesh21@gmail.com>
2026-09-10 09:31 ` Amit Kapila <amit.kapila16@gmail.com>
2026-09-11 04:03 ` vignesh C <vignesh21@gmail.com>
2026-09-11 06:04 ` Chao Li <li.evan.chao@gmail.com>
2026-09-10 09:41 ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-09-10 10:25 ` vignesh C <vignesh21@gmail.com>
2026-09-10 11:41 ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-09-10 12:22 ` shveta malik <shveta.malik@gmail.com>
2026-09-10 13:28 ` Amit Kapila <amit.kapila16@gmail.com>
2026-09-11 01:51 ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-09-10 16:17 ` vignesh C <vignesh21@gmail.com>
2026-09-11 03:19 ` shveta malik <shveta.malik@gmail.com>
2026-09-11 05:39 ` Amit Kapila <amit.kapila16@gmail.com>
2026-09-10 11:06 ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-09-11 05:51 ` Amit Kapila <amit.kapila16@gmail.com>
2026-09-11 06:29 ` Peter Smith <smithpb2250@gmail.com>
2026-09-11 06:33 ` vignesh C <vignesh21@gmail.com>
2026-09-11 07:04 ` Peter Smith <smithpb2250@gmail.com>
2026-09-11 07:22 ` Amit Kapila <amit.kapila16@gmail.com>
2026-09-11 07:42 ` Peter Smith <smithpb2250@gmail.com>
2026-09-11 08:03 ` Amit Kapila <amit.kapila16@gmail.com>
2026-09-11 08:27 ` Peter Smith <smithpb2250@gmail.com>
2026-09-11 09:43 ` vignesh C <vignesh21@gmail.com>
2026-09-11 11:06 ` Amit Kapila <amit.kapila16@gmail.com>
2026-09-11 11:59 ` vignesh C <vignesh21@gmail.com>
2026-09-14 04:22 ` Amit Kapila <amit.kapila16@gmail.com>
2026-09-14 04:40 ` Peter Smith <smithpb2250@gmail.com>
2026-09-14 05:34 ` Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
2026-09-14 05:43 ` Amit Kapila <amit.kapila16@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox