Support EXCEPT for TABLES IN SCHEMA publications
Support EXCEPT for TABLES IN SCHEMA publications
Hi hackers, Following earlier work to support EXCEPT for FOR ALL TABLES [1] publications, starting this thread to extend the same capability to schema-level publications (TABLES IN SCHEMA). Currently, TABLES IN SCHEMA publishes all tables in a schema with no way to exclude a subset. Users who want to skip a few tables must switch to an explicit FOR TABLE list, which loses the convenience of schema-level publishing and requires ongoing maintenance as tables are added. Proposed syntax: ------------------------ CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1); ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1); Note: Tables in the EXCEPT clause must be schema-qualified to avoid ambiguity and must belong to the published schema; otherwise, an error is raised. Rules and behavior: ---------------------------- 1) TABLES IN SCHEMA can be combined with FOR TABLE, but EXCEPT applies only to the schema clause and must appear immediately after it. Supported: CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1), TABLE s2.t1; CREATE PUBLICATION pub FOR TABLE s2.t1, TABLES IN SCHEMA s1 EXCEPT (s1.t1); CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1), s2 EXCEPT (s2.t1) Not supported: CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, TABLE s2.t1 EXCEPT (s1.t1); -- This same rule applies to ALTER PUBLICATION ... ADD/SET. 2) Conflicting definitions Specifying the same table both in the EXCEPT clause and explicitly in the TABLE clause results in an error, as this creates a conflicting definition for the publication. 3) "ALTER PUBLICATION ... DROP TABLES IN SCHEMA" does not support EXCEPT clause. Whereas, dropping a schema also removes any associated entries from the EXCEPT list of the publication. -- To only remove/update except list entries, use SET instead. 4) Consistency with ALL TABLES EXCEPT rules: 4a) Excluding a partitioned root excludes all its partitions 4b) Individual partitions cannot be excluded directly; exclude the root table. 4c) Excluding an inheritance parent (without ONLY) also excludes its children. The patches are divided into three parts to simplify review: Patch-001: Basic framework to support EXCEPT in CREATE PUBLICATION ... TABLES IN SCHEMA Patch-002: Extend support to ALTER PUBLICATION ... ADD TABLES IN SCHEMA Patch-003: Extend support to ALTER PUBLICATION ... SET TABLES IN SCHEMA The patches are attached, feedback and suggestions are welcome. [1] https://www.postgresql.org/message-id/CALDaNm3%3DJrucjhiiwsYQw5-PGtBHFONa6F7hhWCXMsGvh%3DtamA%40mail.gmail.com -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
On Tue, Apr 14, 2026 at 4:30 PM Nisha Moond wrote: > > Hi hackers, > > Following earlier work to support EXCEPT for FOR ALL TABLES [1] > publications, starting this thread to extend the same capability to > schema-level publications (TABLES IN SCHEMA). Hi Nisha. +1 for adding this new kind of exclusion clause to CREATE PUBLICATION command. > > Currently, TABLES IN SCHEMA publishes all tables in a schema with no > way to exclude a subset. Users who want to skip a few tables must > switch to an explicit FOR TABLE list, which loses the convenience of > schema-level publishing and requires ongoing maintenance as tables are > added. > > Proposed syntax: > ------------------------ > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1); > ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > Note: Tables in the EXCEPT clause must be schema-qualified to avoid > ambiguity and must belong to the published schema; otherwise, an error > is raised. > The proposed syntax is almost, but not quite, what I was anticipating. IMO the syntax shouldn't just be similar to the FOR ALL TABLES EXCEPT; It can be *identical* to it. e.g., your examples are missing the 'TABLE' keyword necessary to achieve the same command flexibility. Furthermore, what is the ambiguity referred to? An excluded table is clearly associated with the preceding schema. Can't the code infer the schema internally even when it is not provided by the user? Of course, the user *can* specify a schema-qualified name if they want to, but I didn't see why we are forcing that rule upon them. e.g. -- Syntax can be *identical* to the "EXCEPT (TABLE ...)" clause already pushed. -- Both of these below are equivalent. CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1, t2, t3); CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1, TABLE t2, TABLE t3); -- Below is an example of multiple schemas and multiple except clauses: -- publish all tables of schema s1 except s1.t1 and s1.t2 -- publish all tables of schema s2 -- publish all tables of schema s3 except table s3.t2 (how is this ambiguous with the excluded s1.t2?) CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1, t2), s2, s3 EXCEPT (TABLE t2); ====== Kind Regards, Peter Smith. Fujitsu Australia.
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Amit Kapila <amit.kapila16@gmail.com>
Дата:
On Tue, Apr 14, 2026 at 1:03 PM Peter Smith wrote: > > > -- Syntax can be *identical* to the "EXCEPT (TABLE ...)" clause already pushed. > -- Both of these below are equivalent. > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1, t2, t3); > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1, TABLE > t2, TABLE t3); > > -- Below is an example of multiple schemas and multiple except clauses: > -- publish all tables of schema s1 except s1.t1 and s1.t2 > -- publish all tables of schema s2 > -- publish all tables of schema s3 except table s3.t2 (how is this > ambiguous with the excluded s1.t2?) > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1, t2), > s2, s3 EXCEPT (TABLE t2); > We can go in the direction as proposed by you but my preference would be to avoid using EXCEPT keyword multiple times. -- With Regards, Amit Kapila.
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
On Tue, Apr 14, 2026 at 5:52 PM Amit Kapila wrote: > > On Tue, Apr 14, 2026 at 1:03 PM Peter Smith wrote: > > > > > > -- Syntax can be *identical* to the "EXCEPT (TABLE ...)" clause already pushed. > > -- Both of these below are equivalent. > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1, t2, t3); > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1, TABLE > > t2, TABLE t3); > > > > -- Below is an example of multiple schemas and multiple except clauses: > > -- publish all tables of schema s1 except s1.t1 and s1.t2 > > -- publish all tables of schema s2 > > -- publish all tables of schema s3 except table s3.t2 (how is this > > ambiguous with the excluded s1.t2?) > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1, t2), > > s2, s3 EXCEPT (TABLE t2); > > > > We can go in the direction as proposed by you but my preference would > be to avoid using EXCEPT keyword multiple times. > > -- Using the "EXCEPT keyword multiple times" wasn't anything different proposed by me. That was already part of the original post. e.g. in the 3rd example. ------ Supported: CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1), TABLE s2.t1; CREATE PUBLICATION pub FOR TABLE s2.t1, TABLES IN SCHEMA s1 EXCEPT (s1.t1); CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1), s2 EXCEPT (s2.t1); ------ ====== Kind Regards, Peter Smith. Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Tue, Apr 14, 2026 at 1:03 PM Peter Smith wrote: > > On Tue, Apr 14, 2026 at 4:30 PM Nisha Moond wrote: > > > > Hi hackers, > > > > Following earlier work to support EXCEPT for FOR ALL TABLES [1] > > publications, starting this thread to extend the same capability to > > schema-level publications (TABLES IN SCHEMA). > > Hi Nisha. > > +1 for adding this new kind of exclusion clause to CREATE PUBLICATION command. > > > > > Currently, TABLES IN SCHEMA publishes all tables in a schema with no > > way to exclude a subset. Users who want to skip a few tables must > > switch to an explicit FOR TABLE list, which loses the convenience of > > schema-level publishing and requires ongoing maintenance as tables are > > added. > > > > Proposed syntax: > > ------------------------ > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); > > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > Note: Tables in the EXCEPT clause must be schema-qualified to avoid > > ambiguity and must belong to the published schema; otherwise, an error > > is raised. > > > > The proposed syntax is almost, but not quite, what I was anticipating. > IMO the syntax shouldn't just be similar to the FOR ALL TABLES EXCEPT; > It can be *identical* to it. e.g., your examples are missing the > 'TABLE' keyword necessary to achieve the same command flexibility. > Furthermore, what is the ambiguity referred to? An excluded table is > clearly associated with the preceding schema. Can't the code infer the > schema internally even when it is not provided by the user? Of course, > the user *can* specify a schema-qualified name if they want to, but I > didn't see why we are forcing that rule upon them. +1. I also feel specifying only the table name is clear enough. Or are we referring to implementation complexity here? > e.g. > > -- Syntax can be *identical* to the "EXCEPT (TABLE ...)" clause already pushed. > -- Both of these below are equivalent. > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1, t2, t3); > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1, TABLE > t2, TABLE t3); > > -- Below is an example of multiple schemas and multiple except clauses: > -- publish all tables of schema s1 except s1.t1 and s1.t2 > -- publish all tables of schema s2 > -- publish all tables of schema s3 except table s3.t2 (how is this > ambiguous with the excluded s1.t2?) > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1, t2), > s2, s3 EXCEPT (TABLE t2); > > ====== > Kind Regards, > Peter Smith. > Fujitsu Australia. > >
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Amit Kapila <amit.kapila16@gmail.com>
Дата:
On Tue, Apr 14, 2026 at 2:05 PM shveta malik wrote: > > On Tue, Apr 14, 2026 at 1:03 PM Peter Smith wrote: > > > > On Tue, Apr 14, 2026 at 4:30 PM Nisha Moond wrote: > > > > > > Hi hackers, > > > > > > Following earlier work to support EXCEPT for FOR ALL TABLES [1] > > > publications, starting this thread to extend the same capability to > > > schema-level publications (TABLES IN SCHEMA). > > > > Hi Nisha. > > > > +1 for adding this new kind of exclusion clause to CREATE PUBLICATION command. > > > > > > > > Currently, TABLES IN SCHEMA publishes all tables in a schema with no > > > way to exclude a subset. Users who want to skip a few tables must > > > switch to an explicit FOR TABLE list, which loses the convenience of > > > schema-level publishing and requires ongoing maintenance as tables are > > > added. > > > > > > Proposed syntax: > > > ------------------------ > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); > > > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > > Note: Tables in the EXCEPT clause must be schema-qualified to avoid > > > ambiguity and must belong to the published schema; otherwise, an error > > > is raised. > > > > > > > The proposed syntax is almost, but not quite, what I was anticipating. > > IMO the syntax shouldn't just be similar to the FOR ALL TABLES EXCEPT; > > It can be *identical* to it. e.g., your examples are missing the > > 'TABLE' keyword necessary to achieve the same command flexibility. > > Furthermore, what is the ambiguity referred to? An excluded table is > > clearly associated with the preceding schema. Can't the code infer the > > schema internally even when it is not provided by the user? Of course, > > the user *can* specify a schema-qualified name if they want to, but I > > didn't see why we are forcing that rule upon them. > > +1. I also feel specifying only the table name is clear enough. Or are > we referring to implementation complexity here? > I think it will add complexity. Consider an example: CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2, s3 EXCEPT (t1, t2); So, which schema's exclusion list will these tables should be considered for? Say, if table with name t1 is present in all schemas then shall we exclude from all schemas or just consider it excluded from the first one (s1)? -- With Regards, Amit Kapila.
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Tue, Apr 14, 2026 at 1:03 PM Peter Smith wrote: > > On Tue, Apr 14, 2026 at 4:30 PM Nisha Moond wrote: > > > > Hi hackers, > > > > Following earlier work to support EXCEPT for FOR ALL TABLES [1] > > publications, starting this thread to extend the same capability to > > schema-level publications (TABLES IN SCHEMA). > > Hi Nisha. > > +1 for adding this new kind of exclusion clause to CREATE PUBLICATION command. > > > > > Currently, TABLES IN SCHEMA publishes all tables in a schema with no > > way to exclude a subset. Users who want to skip a few tables must > > switch to an explicit FOR TABLE list, which loses the convenience of > > schema-level publishing and requires ongoing maintenance as tables are > > added. > > > > Proposed syntax: > > ------------------------ > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); > > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > Note: Tables in the EXCEPT clause must be schema-qualified to avoid > > ambiguity and must belong to the published schema; otherwise, an error > > is raised. > > > > The proposed syntax is almost, but not quite, what I was anticipating. > IMO the syntax shouldn't just be similar to the FOR ALL TABLES EXCEPT; > It can be *identical* to it. e.g., your examples are missing the > 'TABLE' keyword necessary to achieve the same command flexibility. > I intentionally didn’t use the TABLE keyword inside EXCEPT. IIUC, for FOR ALL TABLES EXCEPT, there may be a future need to distinguish object types (e.g., tables vs schemas), which is why specifying TABLE makes sense there. However, for TABLES IN SCHEMA, only tables can be specified, so omitting TABLE keeps the syntax simpler and more intuitive. Let's hear others’ opinions too on this and I'll adjust if there’s a preference for including it. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Tue, Apr 14, 2026 at 3:15 PM Nisha Moond wrote: > > On Tue, Apr 14, 2026 at 1:03 PM Peter Smith wrote: > > > > On Tue, Apr 14, 2026 at 4:30 PM Nisha Moond wrote: > > > > > > Hi hackers, > > > > > > Following earlier work to support EXCEPT for FOR ALL TABLES [1] > > > publications, starting this thread to extend the same capability to > > > schema-level publications (TABLES IN SCHEMA). > > > > Hi Nisha. > > > > +1 for adding this new kind of exclusion clause to CREATE PUBLICATION command. > > > > > > > > Currently, TABLES IN SCHEMA publishes all tables in a schema with no > > > way to exclude a subset. Users who want to skip a few tables must > > > switch to an explicit FOR TABLE list, which loses the convenience of > > > schema-level publishing and requires ongoing maintenance as tables are > > > added. > > > > > > Proposed syntax: > > > ------------------------ > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); > > > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > > Note: Tables in the EXCEPT clause must be schema-qualified to avoid > > > ambiguity and must belong to the published schema; otherwise, an error > > > is raised. > > > > > > > The proposed syntax is almost, but not quite, what I was anticipating. > > IMO the syntax shouldn't just be similar to the FOR ALL TABLES EXCEPT; > > It can be *identical* to it. e.g., your examples are missing the > > 'TABLE' keyword necessary to achieve the same command flexibility. > > > > I intentionally didn’t use the TABLE keyword inside EXCEPT. > IIUC, for FOR ALL TABLES EXCEPT, there may be a future need to > distinguish object types (e.g., tables vs schemas), which is why > specifying TABLE makes sense there. > > However, for TABLES IN SCHEMA, only tables can be specified, so > omitting TABLE keeps the syntax simpler and more intuitive. > > Let's hear others’ opinions too on this and I'll adjust if there’s a > preference for including it. > Nisha, please see pt 1 in [1]. If we plan to support that, then we need TABLE keyword, otherwise we are fine. [1]: https://www.postgresql.org/message-id/CAJpy0uB%3DJxTYXOB7VmrhVLR%2B1PG0%3DTtHuGekaqibOPpo2UBLiQ%40mail.gmail.com thanks Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
vignesh C <vignesh21@gmail.com>
Дата:
On Tue, 14 Apr 2026 at 12:00, Nisha Moond wrote:
>
> Hi hackers,
>
> Following earlier work to support EXCEPT for FOR ALL TABLES [1]
> publications, starting this thread to extend the same capability to
> schema-level publications (TABLES IN SCHEMA).
>
> Currently, TABLES IN SCHEMA publishes all tables in a schema with no
> way to exclude a subset. Users who want to skip a few tables must
> switch to an explicit FOR TABLE list, which loses the convenience of
> schema-level publishing and requires ongoing maintenance as tables are
> added.
>
> Proposed syntax:
> ------------------------
> CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2);
> ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1);
> ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1);
>
> Note: Tables in the EXCEPT clause must be schema-qualified to avoid
> ambiguity and must belong to the published schema; otherwise, an error
> is raised.
>
> Rules and behavior:
> ----------------------------
> 1) TABLES IN SCHEMA can be combined with FOR TABLE, but EXCEPT applies
> only to the schema clause and must appear immediately after it.
>
> Supported:
> CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1), TABLE s2.t1;
> CREATE PUBLICATION pub FOR TABLE s2.t1, TABLES IN SCHEMA s1 EXCEPT (s1.t1);
> CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1), s2
> EXCEPT (s2.t1)
>
> Not supported:
> CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, TABLE s2.t1 EXCEPT (s1.t1);
>
> -- This same rule applies to ALTER PUBLICATION ... ADD/SET.
>
> 2) Conflicting definitions
> Specifying the same table both in the EXCEPT clause and explicitly in
> the TABLE clause results in an error, as this creates a conflicting
> definition for the publication.
>
> 3) "ALTER PUBLICATION ... DROP TABLES IN SCHEMA" does not support
> EXCEPT clause. Whereas, dropping a schema also removes any associated
> entries from the EXCEPT list of the publication.
> -- To only remove/update except list entries, use SET instead.
>
> 4) Consistency with ALL TABLES EXCEPT rules:
> 4a) Excluding a partitioned root excludes all its partitions
> 4b) Individual partitions cannot be excluded directly; exclude the root table.
> 4c) Excluding an inheritance parent (without ONLY) also excludes its children.
>
> The patches are divided into three parts to simplify review:
> Patch-001: Basic framework to support EXCEPT in CREATE PUBLICATION
> ... TABLES IN SCHEMA
> Patch-002: Extend support to ALTER PUBLICATION ... ADD TABLES IN SCHEMA
> Patch-003: Extend support to ALTER PUBLICATION ... SET TABLES IN SCHEMA
>
> The patches are attached, feedback and suggestions are welcome.
+1 for this.
Few comments for the first patch:
1) This should be collected only if except relation was specified, we
can skip it if it is not specified:
+ /*
+ * Collect explicit table OIDs now, before we
close the relation
+ * list, so that except-table validation below
can check for
+ * contradictions without relying on a catalog
scan that might not
+ * yet see the just-inserted rows.
+ */
+ foreach(lc, rels)
+ {
+ PublicationRelInfo *pri =
(PublicationRelInfo *) lfirst(lc);
+
+ explicitrelids = lappend_oid(explicitrelids,
+
RelationGetRelid(pri->relation));
+ }
2) Tab completion for except table of that particular schema lists
other schema, but currently specifying other schema tables is not
allowed:
+ else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR",
"TABLES", "IN", "SCHEMA", MatchAny, "EXCEPT", "("))
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
Can we list only the tables from the specified schema.
3) Can this check be done at parser itself, it can be done in
preprocess_pubobj_list parser function to detect the error early:
+ /*
+ * For TABLES IN SCHEMA publications,
require schema-qualified
+ * names to avoid ambiguity when
multiple schemas in the
+ * publication have identically-named tables.
+ */
+ foreach(lc, exceptrelations)
+ {
+ PublicationTable *t =
(PublicationTable *) lfirst(lc);
+
+ if (t->relation->schemaname == NULL)
+ ereport(ERROR,
+
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+
errmsg("table \"%s\" in EXCEPT clause must be schema-qualified",
+
t->relation->relname));
+ }
4) This error message does not seems to be conveying the correct error message:
postgres=# create publication pub1 for tables in schema sch3 except (
sch3.t1 ) ;
CREATE PUBLICATION
postgres=# alter publication pub1 add table sch3.t1 ;
ERROR: relation "t1" is already member of publication "pub1"
How about an error message like:
ERROR: table "sch3.t1" cannot be added explicitly because it is listed
in the EXCEPT clause of schema "sch3" in publication "pub1"
5) This change is not related to this patch:
@@ -5279,7 +5315,7 @@ foreach my $run (sort keys %pgdump_runs)
#
# Either "all_runs" should be set or there should be a
"like" list,
# even if it is empty. (This makes the test more
self-documenting.)
- if (!defined($tests{$test}->{all_runs})
+ if ( !defined($tests{$test}->{all_runs})
&& !defined($tests{$test}->{like}))
{
die "missing \"like\" in test \"$test\"";
6) There is an indentation issue here:
- pub_except_obj_list opt_pub_except_clause
+ pub_except_obj_list pub_schema_except_obj_list
+ opt_pub_except_clause opt_pub_schema_except_clause
Regards,
Vignesh
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
vignesh C <vignesh21@gmail.com>
Дата:
On Tue, 14 Apr 2026 at 12:00, Nisha Moond wrote:
>
> Hi hackers,
>
> Following earlier work to support EXCEPT for FOR ALL TABLES [1]
> publications, starting this thread to extend the same capability to
> schema-level publications (TABLES IN SCHEMA).
>
> Currently, TABLES IN SCHEMA publishes all tables in a schema with no
> way to exclude a subset. Users who want to skip a few tables must
> switch to an explicit FOR TABLE list, which loses the convenience of
> schema-level publishing and requires ongoing maintenance as tables are
> added.
>
> Proposed syntax:
> ------------------------
> CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2);
> ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1);
> ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1);
>
> Note: Tables in the EXCEPT clause must be schema-qualified to avoid
> ambiguity and must belong to the published schema; otherwise, an error
> is raised.
>
> Rules and behavior:
> ----------------------------
> 1) TABLES IN SCHEMA can be combined with FOR TABLE, but EXCEPT applies
> only to the schema clause and must appear immediately after it.
>
> Supported:
> CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1), TABLE s2.t1;
> CREATE PUBLICATION pub FOR TABLE s2.t1, TABLES IN SCHEMA s1 EXCEPT (s1.t1);
> CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1), s2
> EXCEPT (s2.t1)
>
> Not supported:
> CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, TABLE s2.t1 EXCEPT (s1.t1);
>
> -- This same rule applies to ALTER PUBLICATION ... ADD/SET.
>
> 2) Conflicting definitions
> Specifying the same table both in the EXCEPT clause and explicitly in
> the TABLE clause results in an error, as this creates a conflicting
> definition for the publication.
>
> 3) "ALTER PUBLICATION ... DROP TABLES IN SCHEMA" does not support
> EXCEPT clause. Whereas, dropping a schema also removes any associated
> entries from the EXCEPT list of the publication.
> -- To only remove/update except list entries, use SET instead.
>
> 4) Consistency with ALL TABLES EXCEPT rules:
> 4a) Excluding a partitioned root excludes all its partitions
> 4b) Individual partitions cannot be excluded directly; exclude the root table.
> 4c) Excluding an inheritance parent (without ONLY) also excludes its children.
>
> The patches are divided into three parts to simplify review:
> Patch-001: Basic framework to support EXCEPT in CREATE PUBLICATION
> ... TABLES IN SCHEMA
> Patch-002: Extend support to ALTER PUBLICATION ... ADD TABLES IN SCHEMA
> Patch-003: Extend support to ALTER PUBLICATION ... SET TABLES IN SCHEMA
>
> The patches are attached, feedback and suggestions are welcome.
When an EXCEPT table is specified together with TABLES IN SCHEMA sch1,
the EXCEPT entry is correctly created:
postgres=# create publication pub1 for tables in schema sch1 except (sch1.t1);
CREATE PUBLICATION
postgres=# \dRp+ pub1
Publication pub1
Owner | All tables | All sequences | Inserts | Updates | Deletes |
Truncates | Generated columns | Via root | Description
---------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+-------------
vignesh | f | f | t | t | t |
t | none | f |
Tables from schemas:
"sch1"
Except tables:
"sch1.t1"
However, after dropping the schema from the publication, the
previously recorded EXCEPT table entry is still retained:
postgres=# alter publication pub1 drop TABLES IN SCHEMA sch1 ;
ALTER PUBLICATION
postgres=# \dRp+ pub1
Publication pub1
Owner | All tables | All sequences | Inserts | Updates | Deletes |
Truncates | Generated columns | Via root | Description
---------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+-------------
vignesh | f | f | t | t | t |
t | none | f |
Except tables:
"sch1.t1"
This seems incorrect, because once sch1 is no longer part of the
publication, retaining "sch1.t1" as an EXCEPT entry no longer has any
semantic meaning and leaves behind stale catalog state.
Regards,
Vignesh
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
On Tue, Apr 14, 2026 at 7:37 PM Amit Kapila wrote:
>
> On Tue, Apr 14, 2026 at 2:05 PM shveta malik wrote:
> >
> > On Tue, Apr 14, 2026 at 1:03 PM Peter Smith wrote:
> > >
> > > On Tue, Apr 14, 2026 at 4:30 PM Nisha Moond wrote:
> > > >
> > > > Hi hackers,
> > > >
> > > > Following earlier work to support EXCEPT for FOR ALL TABLES [1]
> > > > publications, starting this thread to extend the same capability to
> > > > schema-level publications (TABLES IN SCHEMA).
> > >
> > > Hi Nisha.
> > >
> > > +1 for adding this new kind of exclusion clause to CREATE PUBLICATION command.
> > >
> > > >
> > > > Currently, TABLES IN SCHEMA publishes all tables in a schema with no
> > > > way to exclude a subset. Users who want to skip a few tables must
> > > > switch to an explicit FOR TABLE list, which loses the convenience of
> > > > schema-level publishing and requires ongoing maintenance as tables are
> > > > added.
> > > >
> > > > Proposed syntax:
> > > > ------------------------
> > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2);
> > > > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1);
> > > > ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1);
> > > >
> > > > Note: Tables in the EXCEPT clause must be schema-qualified to avoid
> > > > ambiguity and must belong to the published schema; otherwise, an error
> > > > is raised.
> > > >
> > >
> > > The proposed syntax is almost, but not quite, what I was anticipating.
> > > IMO the syntax shouldn't just be similar to the FOR ALL TABLES EXCEPT;
> > > It can be *identical* to it. e.g., your examples are missing the
> > > 'TABLE' keyword necessary to achieve the same command flexibility.
> > > Furthermore, what is the ambiguity referred to? An excluded table is
> > > clearly associated with the preceding schema. Can't the code infer the
> > > schema internally even when it is not provided by the user? Of course,
> > > the user *can* specify a schema-qualified name if they want to, but I
> > > didn't see why we are forcing that rule upon them.
> >
> > +1. I also feel specifying only the table name is clear enough. Or are
> > we referring to implementation complexity here?
> >
>
> I think it will add complexity. Consider an example:
> CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2, s3 EXCEPT (t1, t2);
>
> So, which schema's exclusion list will these tables should be
> considered for? Say, if table with name t1 is present in all schemas
> then shall we exclude from all schemas or just consider it excluded
> from the first one (s1)?
>
The exact pattern is already in common usage for row-filters and
column-lists, yet nobody is confused.
-- all these tables have the same column names
-- (analogous to multiple schemas having same table names)
CREATE TABLE t1(c1 int, c2 int);
CREATE TABLE t2(c1 int, c2 int);
CREATE TABLE t3(c1 int, c2 int);
-- all tables have a column c1
-- but this c1 means t3.c1 because the column-list is only for the adjacent t3.
CREATE PUBLICATION pub1 FOR TABLE t1, t2, t3 (c1);
-- all tables have a column c2
-- but this c2 means t3.c2 because the row-filter is only for the adjacent t3.
CREATE PUBLICATION pub2 FOR TABLE t1, t2, t3 WHERE (c2 > 99);
\dRp+
Publication pub1
Owner | All tables | All sequences | Inserts | Updates | Deletes |
Truncates | Generated columns | Via root | Description
----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+-------------
postgres | f | f | t | t | t |
t | none | f |
Tables:
"public.t1"
"public.t2"
"public.t3" (c1)
Publication pub2
Owner | All tables | All sequences | Inserts | Updates | Deletes |
Truncates | Generated columns | Via root | Description
----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+-------------
postgres | f | f | t | t | t |
t | none | f |
Tables:
"public.t1"
"public.t2"
"public.t3" WHERE (c2 > 99)
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
vignesh C <vignesh21@gmail.com>
Дата:
On Tue, 14 Apr 2026 at 12:00, Nisha Moond wrote:
>
> Hi hackers,
>
> Following earlier work to support EXCEPT for FOR ALL TABLES [1]
> publications, starting this thread to extend the same capability to
> schema-level publications (TABLES IN SCHEMA).
>
> Currently, TABLES IN SCHEMA publishes all tables in a schema with no
> way to exclude a subset. Users who want to skip a few tables must
> switch to an explicit FOR TABLE list, which loses the convenience of
> schema-level publishing and requires ongoing maintenance as tables are
> added.
>
> Proposed syntax:
> ------------------------
> CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2);
> ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1);
> ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1);
>
> Note: Tables in the EXCEPT clause must be schema-qualified to avoid
> ambiguity and must belong to the published schema; otherwise, an error
> is raised.
>
> Rules and behavior:
> ----------------------------
> 1) TABLES IN SCHEMA can be combined with FOR TABLE, but EXCEPT applies
> only to the schema clause and must appear immediately after it.
>
> Supported:
> CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1), TABLE s2.t1;
> CREATE PUBLICATION pub FOR TABLE s2.t1, TABLES IN SCHEMA s1 EXCEPT (s1.t1);
> CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1), s2
> EXCEPT (s2.t1)
>
> Not supported:
> CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, TABLE s2.t1 EXCEPT (s1.t1);
>
> -- This same rule applies to ALTER PUBLICATION ... ADD/SET.
>
> 2) Conflicting definitions
> Specifying the same table both in the EXCEPT clause and explicitly in
> the TABLE clause results in an error, as this creates a conflicting
> definition for the publication.
>
> 3) "ALTER PUBLICATION ... DROP TABLES IN SCHEMA" does not support
> EXCEPT clause. Whereas, dropping a schema also removes any associated
> entries from the EXCEPT list of the publication.
> -- To only remove/update except list entries, use SET instead.
>
> 4) Consistency with ALL TABLES EXCEPT rules:
> 4a) Excluding a partitioned root excludes all its partitions
> 4b) Individual partitions cannot be excluded directly; exclude the root table.
> 4c) Excluding an inheritance parent (without ONLY) also excludes its children.
>
> The patches are divided into three parts to simplify review:
> Patch-001: Basic framework to support EXCEPT in CREATE PUBLICATION
> ... TABLES IN SCHEMA
> Patch-002: Extend support to ALTER PUBLICATION ... ADD TABLES IN SCHEMA
> Patch-003: Extend support to ALTER PUBLICATION ... SET TABLES IN SCHEMA
>
> The patches are attached, feedback and suggestions are welcome.
Few comments for the second patch:
1) This patch adds support only for:
ALTER PUBLICATION pub ADD TABLES IN SCHEMA s EXCEPT (s.t1, s.t2);
But documentation mentions for both add and set:
@@ -31,7 +31,7 @@ ALTER PUBLICATION name RENAME TO where publication_object is one of:
TABLE table_and_columns [, ... ]
- TABLES IN SCHEMA { schema_name | CURRENT_SCHEMA } [, ...
]
+ TABLES IN SCHEMA { schema_name | CURRENT_SCHEMA } [
EXCEPT ( except_table_object [, ... ] ) ] [,
... ]
2) Tab completion missing for:
alter publication pub1 add TABLES IN SCHEMA sch1
3) Currently Set tables in schema sch1 also works partially with the
second patch without adding the except tables:
postgres=# alter publication pub1 set tables in schema sch1 except (sch1.t1);
ALTER PUBLICATION
postgres=# \dRp+ pub1
Publication pub1
Owner | All tables | All sequences | Inserts | Updates | Deletes |
Truncates | Generated columns | Via root | Description
---------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+-------------
vignesh | f | f | t | t | t |
t | none | f |
Tables from schemas:
"sch1"
Should there be a check here to throw an error:
+static void
+AlterPublicationExceptTables(AlterPublicationStmt *stmt,
+ HeapTuple
tup, List *exceptrelations,
+ List *schemaidlist)
+{
+ Form_pg_publication pubform = (Form_pg_publication) GETSTRUCT(tup);
+ Oid pubid = pubform->oid;
+
+ /*
+ * Nothing to do if no EXCEPT entries.
+ */
+ if (!exceptrelations)
+ return;
+
4) Can this check be done at parser itself, it can be done in
preprocess_pubobj_list parser function to detect the error early:
+ foreach(lc, exceptrelations)
+ {
+ PublicationTable *t = (PublicationTable *) lfirst(lc);
+
+ if (t->relation->schemaname == NULL)
+ ereport(ERROR,
+
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("table \"%s\"
in EXCEPT clause must be schema-qualified",
+
t->relation->relname));
+ }
Regards,
Vignesh
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Tue, Apr 14, 2026 at 3:22 PM shveta malik wrote: > > On Tue, Apr 14, 2026 at 3:15 PM Nisha Moond wrote: > > > > On Tue, Apr 14, 2026 at 1:03 PM Peter Smith wrote: > > > > > > On Tue, Apr 14, 2026 at 4:30 PM Nisha Moond wrote: > > > > > > > > Hi hackers, > > > > > > > > Following earlier work to support EXCEPT for FOR ALL TABLES [1] > > > > publications, starting this thread to extend the same capability to > > > > schema-level publications (TABLES IN SCHEMA). > > > > > > Hi Nisha. > > > > > > +1 for adding this new kind of exclusion clause to CREATE PUBLICATION command. > > > > > > > > > > > Currently, TABLES IN SCHEMA publishes all tables in a schema with no > > > > way to exclude a subset. Users who want to skip a few tables must > > > > switch to an explicit FOR TABLE list, which loses the convenience of > > > > schema-level publishing and requires ongoing maintenance as tables are > > > > added. > > > > > > > > Proposed syntax: > > > > ------------------------ > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); > > > > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > > > > Note: Tables in the EXCEPT clause must be schema-qualified to avoid > > > > ambiguity and must belong to the published schema; otherwise, an error > > > > is raised. > > > > > > > > > > The proposed syntax is almost, but not quite, what I was anticipating. > > > IMO the syntax shouldn't just be similar to the FOR ALL TABLES EXCEPT; > > > It can be *identical* to it. e.g., your examples are missing the > > > 'TABLE' keyword necessary to achieve the same command flexibility. > > > > > > > I intentionally didn’t use the TABLE keyword inside EXCEPT. > > IIUC, for FOR ALL TABLES EXCEPT, there may be a future need to > > distinguish object types (e.g., tables vs schemas), which is why > > specifying TABLE makes sense there. > > > > However, for TABLES IN SCHEMA, only tables can be specified, so > > omitting TABLE keeps the syntax simpler and more intuitive. > > > > Let's hear others’ opinions too on this and I'll adjust if there’s a > > preference for including it. > > > > Nisha, please see pt 1 in [1]. If we plan to support that, then we > need TABLE keyword, otherwise we are fine. > > [1]: https://www.postgresql.org/message-id/CAJpy0uB%3DJxTYXOB7VmrhVLR%2B1PG0%3DTtHuGekaqibOPpo2UBLiQ%40mail.gmail.com > Thank you Shveta for pointing to the discussion. So, if we were to extend CREATE PUBLICATION to support something like: "CREATE PUBLICATION pub FOR TABLES, SEQUENCES IN SCHEMA sch1 EXCEPT (TABLE t1, SEQUENCE s1);" then, introducing TABLE inside EXCEPT could make sense, but at this stage we’re not sure how the syntax for supporting SEQUENCES IN SCHEMA will evolve. The overall grammar may require broader changes rather than a simple extension. So, we can always introduce keywords like TABLE or SEQUENCE later, if and when they are actually needed. Just my thoughts. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Tue, Apr 14, 2026 at 8:46 PM vignesh C wrote: > > When an EXCEPT table is specified together with TABLES IN SCHEMA sch1, > the EXCEPT entry is correctly created: > postgres=# create publication pub1 for tables in schema sch1 except (sch1.t1); > CREATE PUBLICATION > > postgres=# \dRp+ pub1 > Publication pub1 > Owner | All tables | All sequences | Inserts | Updates | Deletes | > Truncates | Generated columns | Via root | Description > ---------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------------- > vignesh | f | f | t | t | t | > t | none | f | > Tables from schemas: > "sch1" > Except tables: > "sch1.t1" > However, after dropping the schema from the publication, the > previously recorded EXCEPT table entry is still retained: > postgres=# alter publication pub1 drop TABLES IN SCHEMA sch1 ; > ALTER PUBLICATION > postgres=# \dRp+ pub1 > Publication pub1 > Owner | All tables | All sequences | Inserts | Updates | Deletes | > Truncates | Generated columns | Via root | Description > ---------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------------- > vignesh | f | f | t | t | t | > t | none | f | > Except tables: > "sch1.t1" > > This seems incorrect, because once sch1 is no longer part of the > publication, retaining "sch1.t1" as an EXCEPT entry no longer has any > semantic meaning and leaves behind stale catalog state. > This is handled in v1-003 (last) patch along with other ALTER PUBLICATION related modifications. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Wed, Apr 15, 2026 at 2:22 PM Nisha Moond wrote: > > On Tue, Apr 14, 2026 at 3:22 PM shveta malik wrote: > > > > On Tue, Apr 14, 2026 at 3:15 PM Nisha Moond wrote: > > > > > > On Tue, Apr 14, 2026 at 1:03 PM Peter Smith wrote: > > > > > > > > On Tue, Apr 14, 2026 at 4:30 PM Nisha Moond wrote: > > > > > > > > > > Hi hackers, > > > > > > > > > > Following earlier work to support EXCEPT for FOR ALL TABLES [1] > > > > > publications, starting this thread to extend the same capability to > > > > > schema-level publications (TABLES IN SCHEMA). > > > > > > > > Hi Nisha. > > > > > > > > +1 for adding this new kind of exclusion clause to CREATE PUBLICATION command. > > > > > > > > > > > > > > Currently, TABLES IN SCHEMA publishes all tables in a schema with no > > > > > way to exclude a subset. Users who want to skip a few tables must > > > > > switch to an explicit FOR TABLE list, which loses the convenience of > > > > > schema-level publishing and requires ongoing maintenance as tables are > > > > > added. > > > > > > > > > > Proposed syntax: > > > > > ------------------------ > > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); > > > > > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > > > > > > Note: Tables in the EXCEPT clause must be schema-qualified to avoid > > > > > ambiguity and must belong to the published schema; otherwise, an error > > > > > is raised. > > > > > > > > > > > > > The proposed syntax is almost, but not quite, what I was anticipating. > > > > IMO the syntax shouldn't just be similar to the FOR ALL TABLES EXCEPT; > > > > It can be *identical* to it. e.g., your examples are missing the > > > > 'TABLE' keyword necessary to achieve the same command flexibility. > > > > > > > > > > I intentionally didn’t use the TABLE keyword inside EXCEPT. > > > IIUC, for FOR ALL TABLES EXCEPT, there may be a future need to > > > distinguish object types (e.g., tables vs schemas), which is why > > > specifying TABLE makes sense there. > > > > > > However, for TABLES IN SCHEMA, only tables can be specified, so > > > omitting TABLE keeps the syntax simpler and more intuitive. > > > > > > Let's hear others’ opinions too on this and I'll adjust if there’s a > > > preference for including it. > > > > > > > Nisha, please see pt 1 in [1]. If we plan to support that, then we > > need TABLE keyword, otherwise we are fine. > > > > [1]: https://www.postgresql.org/message-id/CAJpy0uB%3DJxTYXOB7VmrhVLR%2B1PG0%3DTtHuGekaqibOPpo2UBLiQ%40mail.gmail.com > > > > Thank you Shveta for pointing to the discussion. > So, if we were to extend CREATE PUBLICATION to support something like: > "CREATE PUBLICATION pub FOR TABLES, SEQUENCES IN SCHEMA sch1 EXCEPT > (TABLE t1, SEQUENCE s1);" > then, introducing TABLE inside EXCEPT could make sense, but at this > stage we’re not sure how the syntax for supporting SEQUENCES IN SCHEMA > will evolve. The overall grammar may require broader changes rather > than a simple extension. So, we can always introduce keywords like > TABLE or SEQUENCE later, if and when they are actually needed. Just my > thoughts. > It works for me Nisha. I also agree that the 'TABLE' keyword seems redundant in the case you proposed: CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); But I am just worried this might confuse users, as one command requires specifying the TABLE with EXCEPT, while another requires omitting it. But we can first focus on implementation and come back to it later when more people join and share their thoughts. thanks Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
vignesh C <vignesh21@gmail.com>
Дата:
On Wed, 15 Apr 2026 at 14:22, Nisha Moond wrote: > > On Tue, Apr 14, 2026 at 8:46 PM vignesh C wrote: > > > > When an EXCEPT table is specified together with TABLES IN SCHEMA sch1, > > the EXCEPT entry is correctly created: > > postgres=# create publication pub1 for tables in schema sch1 except (sch1.t1); > > CREATE PUBLICATION > > > > postgres=# \dRp+ pub1 > > Publication pub1 > > Owner | All tables | All sequences | Inserts | Updates | Deletes | > > Truncates | Generated columns | Via root | Description > > ---------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------------- > > vignesh | f | f | t | t | t | > > t | none | f | > > Tables from schemas: > > "sch1" > > Except tables: > > "sch1.t1" > > However, after dropping the schema from the publication, the > > previously recorded EXCEPT table entry is still retained: > > postgres=# alter publication pub1 drop TABLES IN SCHEMA sch1 ; > > ALTER PUBLICATION > > postgres=# \dRp+ pub1 > > Publication pub1 > > Owner | All tables | All sequences | Inserts | Updates | Deletes | > > Truncates | Generated columns | Via root | Description > > ---------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------------- > > vignesh | f | f | t | t | t | > > t | none | f | > > Except tables: > > "sch1.t1" > > > > This seems incorrect, because once sch1 is no longer part of the > > publication, retaining "sch1.t1" as an EXCEPT entry no longer has any > > semantic meaning and leaves behind stale catalog state. > > > > This is handled in v1-003 (last) patch along with other ALTER > PUBLICATION related modifications. I was reviewing the patches individually and noticed this. If it is handled in the 003 ignore that comment. Regards, Vignesh
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Tue, Apr 14, 2026 at 5:01 PM vignesh C wrote:
>
> +1 for this.
> Few comments for the first patch:
Thank you Vignesh for the review.
> 1) This should be collected only if except relation was specified, we
> can skip it if it is not specified:
> + /*
> + * Collect explicit table OIDs now, before we
> close the relation
> + * list, so that except-table validation below
> can check for
> + * contradictions without relying on a catalog
> scan that might not
> + * yet see the just-inserted rows.
> + */
> + foreach(lc, rels)
> + {
> + PublicationRelInfo *pri =
> (PublicationRelInfo *) lfirst(lc);
> +
> + explicitrelids = lappend_oid(explicitrelids,
> +
> RelationGetRelid(pri->relation));
> + }
>
Fixed
> 2) Tab completion for except table of that particular schema lists
> other schema, but currently specifying other schema tables is not
> allowed:
> + else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR",
> "TABLES", "IN", "SCHEMA", MatchAny, "EXCEPT", "("))
> + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
>
> Can we list only the tables from the specified schema.
>
Fixed. Required a new query to fetch schema tables.
> 3) Can this check be done at parser itself, it can be done in
> preprocess_pubobj_list parser function to detect the error early:
> + /*
> + * For TABLES IN SCHEMA publications,
> require schema-qualified
> + * names to avoid ambiguity when
> multiple schemas in the
> + * publication have identically-named tables.
> + */
> + foreach(lc, exceptrelations)
> + {
> + PublicationTable *t =
> (PublicationTable *) lfirst(lc);
> +
> + if (t->relation->schemaname == NULL)
> + ereport(ERROR,
> +
> errcode(ERRCODE_INVALID_PARAMETER_VALUE),
> +
> errmsg("table \"%s\" in EXCEPT clause must be schema-qualified",
> +
> t->relation->relname));
> + }
>
Fixed
> 4) This error message does not seems to be conveying the correct error message:
> postgres=# create publication pub1 for tables in schema sch3 except (
> sch3.t1 ) ;
> CREATE PUBLICATION
> postgres=# alter publication pub1 add table sch3.t1 ;
> ERROR: relation "t1" is already member of publication "pub1"
>
> How about an error message like:
> ERROR: table "sch3.t1" cannot be added explicitly because it is listed
> in the EXCEPT clause of schema "sch3" in publication "pub1"
>
Fixed with a bit short error message -
postgres=# alter publication pub8 add table s1.t1;
ERROR: table "s1.t1" cannot be added because it is listed in EXCEPT
clause of publication "pub8"
> 5) This change is not related to this patch:
> @@ -5279,7 +5315,7 @@ foreach my $run (sort keys %pgdump_runs)
> #
> # Either "all_runs" should be set or there should be a
> "like" list,
> # even if it is empty. (This makes the test more
> self-documenting.)
> - if (!defined($tests{$test}->{all_runs})
> + if ( !defined($tests{$test}->{all_runs})
> && !defined($tests{$test}->{like}))
> {
> die "missing \"like\" in test \"$test\"";
>
Fixed
> 6) There is an indentation issue here:
> - pub_except_obj_list opt_pub_except_clause
> + pub_except_obj_list pub_schema_except_obj_list
> + opt_pub_except_clause opt_pub_schema_except_clause
>
Fixed
Please find the updated patches (v2) attached.
Patch-001: addressed above comments
Patch-002: addressed Vignesh's comments from [1]
Patch-003: updated the documentation and also added tab-completion for
the SET TABLES IN SCHEMA EXCEPT
[1] https://www.postgresql.org/message-id/CALDaNm3pBWnJJ9ynVj3KeZ%2BNQQXboU-goObvF9fZ0GYzyuJFhQ%40mail.gmail.com
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Wed, Apr 15, 2026 at 11:18 AM vignesh C wrote:
>
> On Tue, 14 Apr 2026 at 12:00, Nisha Moond wrote:
> >
>
> Few comments for the second patch:
Thanks for the review.
> 1) This patch adds support only for:
> ALTER PUBLICATION pub ADD TABLES IN SCHEMA s EXCEPT (s.t1, s.t2);
>
> But documentation mentions for both add and set:
> @@ -31,7 +31,7 @@ ALTER PUBLICATION class="parameter">name RENAME TO where class="parameter">publication_object is one of:
>
> TABLE class="parameter">table_and_columns [, ... ]
> - TABLES IN SCHEMA { class="parameter">schema_name | CURRENT_SCHEMA } [, ...
> ]
> + TABLES IN SCHEMA { class="parameter">schema_name | CURRENT_SCHEMA } [
> EXCEPT ( class="parameter">except_table_object [, ... ] ) ] [,
> ... ]
>
Fixed the doc descriptions where SET was mentioned in patch-002.
But for the synopsis, I feel it will be unnecessary to first separate
the ADD and SET publication objects like "publication_add_object" and
"publication_set_object" in patch-002 and then remove them in
patch-003. Please let me know if you think otherwise.
> 2) Tab completion missing for:
> alter publication pub1 add TABLES IN SCHEMA sch1
>
Done.
> 3) Currently Set tables in schema sch1 also works partially with the
> second patch without adding the except tables:
> postgres=# alter publication pub1 set tables in schema sch1 except (sch1.t1);
> ALTER PUBLICATION
> postgres=# \dRp+ pub1
> Publication pub1
> Owner | All tables | All sequences | Inserts | Updates | Deletes |
> Truncates | Generated columns | Via root | Description
> ---------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+-------------
> vignesh | f | f | t | t | t |
> t | none | f |
> Tables from schemas:
> "sch1"
>
> Should there be a check here to throw an error:
> +static void
> +AlterPublicationExceptTables(AlterPublicationStmt *stmt,
> + HeapTuple
> tup, List *exceptrelations,
> + List *schemaidlist)
> +{
> + Form_pg_publication pubform = (Form_pg_publication) GETSTRUCT(tup);
> + Oid pubid = pubform->oid;
> +
> + /*
> + * Nothing to do if no EXCEPT entries.
> + */
> + if (!exceptrelations)
> + return;
> +
>
Fixed
> 4) Can this check be done at parser itself, it can be done in
> preprocess_pubobj_list parser function to detect the error early:
> + foreach(lc, exceptrelations)
> + {
> + PublicationTable *t = (PublicationTable *) lfirst(lc);
> +
> + if (t->relation->schemaname == NULL)
> + ereport(ERROR,
> +
> errcode(ERRCODE_INVALID_PARAMETER_VALUE),
> + errmsg("table \"%s\"
> in EXCEPT clause must be schema-qualified",
> +
> t->relation->relname));
> + }
>
Fixed.
All above comments are addressed in v2 attached above.
[1]
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
On Wed, Apr 15, 2026 at 8:15 PM shveta malik wrote: > > On Wed, Apr 15, 2026 at 2:22 PM Nisha Moond wrote: > > > > On Tue, Apr 14, 2026 at 3:22 PM shveta malik wrote: > > > > > > On Tue, Apr 14, 2026 at 3:15 PM Nisha Moond wrote: > > > > > > > > On Tue, Apr 14, 2026 at 1:03 PM Peter Smith wrote: > > > > > > > > > > On Tue, Apr 14, 2026 at 4:30 PM Nisha Moond wrote: > > > > > > > > > > > > Hi hackers, > > > > > > > > > > > > Following earlier work to support EXCEPT for FOR ALL TABLES [1] > > > > > > publications, starting this thread to extend the same capability to > > > > > > schema-level publications (TABLES IN SCHEMA). > > > > > > > > > > Hi Nisha. > > > > > > > > > > +1 for adding this new kind of exclusion clause to CREATE PUBLICATION command. > > > > > > > > > > > > > > > > > Currently, TABLES IN SCHEMA publishes all tables in a schema with no > > > > > > way to exclude a subset. Users who want to skip a few tables must > > > > > > switch to an explicit FOR TABLE list, which loses the convenience of > > > > > > schema-level publishing and requires ongoing maintenance as tables are > > > > > > added. > > > > > > > > > > > > Proposed syntax: > > > > > > ------------------------ > > > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); > > > > > > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > > ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > > > > > > > > Note: Tables in the EXCEPT clause must be schema-qualified to avoid > > > > > > ambiguity and must belong to the published schema; otherwise, an error > > > > > > is raised. > > > > > > > > > > > > > > > > The proposed syntax is almost, but not quite, what I was anticipating. > > > > > IMO the syntax shouldn't just be similar to the FOR ALL TABLES EXCEPT; > > > > > It can be *identical* to it. e.g., your examples are missing the > > > > > 'TABLE' keyword necessary to achieve the same command flexibility. > > > > > > > > > > > > > I intentionally didn’t use the TABLE keyword inside EXCEPT. > > > > IIUC, for FOR ALL TABLES EXCEPT, there may be a future need to > > > > distinguish object types (e.g., tables vs schemas), which is why > > > > specifying TABLE makes sense there. > > > > > > > > However, for TABLES IN SCHEMA, only tables can be specified, so > > > > omitting TABLE keeps the syntax simpler and more intuitive. > > > > > > > > Let's hear others’ opinions too on this and I'll adjust if there’s a > > > > preference for including it. > > > > > > > > > > Nisha, please see pt 1 in [1]. If we plan to support that, then we > > > need TABLE keyword, otherwise we are fine. > > > > > > [1]: https://www.postgresql.org/message-id/CAJpy0uB%3DJxTYXOB7VmrhVLR%2B1PG0%3DTtHuGekaqibOPpo2UBLiQ%40mail.gmail.com > > > > > > > Thank you Shveta for pointing to the discussion. > > So, if we were to extend CREATE PUBLICATION to support something like: > > "CREATE PUBLICATION pub FOR TABLES, SEQUENCES IN SCHEMA sch1 EXCEPT > > (TABLE t1, SEQUENCE s1);" > > then, introducing TABLE inside EXCEPT could make sense, but at this > > stage we’re not sure how the syntax for supporting SEQUENCES IN SCHEMA > > will evolve. The overall grammar may require broader changes rather > > than a simple extension. So, we can always introduce keywords like > > TABLE or SEQUENCE later, if and when they are actually needed. Just my > > thoughts. > > > > It works for me Nisha. I also agree that the 'TABLE' keyword seems > redundant in the case you proposed: > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); > > But I am just worried this might confuse users, as one command > requires specifying the TABLE with EXCEPT, while another requires > omitting it. But we can first focus on implementation and come back to > it later when more people join and share their thoughts. > I agree with Shveta that inconsistency will confuse. We already have FOR ALL TABLES EXCEPT (TABLE ...) [1] And another place is currently introducing FOR ALL SEQUENCES EXCEPT (SEQUENCE ...) [2] IMO, this schema thread should match [1]. I think syntax *consistency* should take priority here. While some keywords may end up being unnecessary in certain cases, having different rules for each EXCEPT variation seems harder to maintain and reason about. I also agree with you that we are not sure how the command syntax might evolve in future. That is another reason why requiring these keywords (like 'TABLE' and 'SEQUENCE') is the best/safest first approach, IMO, because it will be backward-compatible. For example, if it turns out we can make (some of) these keywords optional in future, then user code will still be fine, but if they are absent now, then we cannot make them mandatory in future PostgreSQL versions without breaking user code. ====== [1] https://www.postgresql.org/docs/devel/sql-createpublication.html [2] https://www.postgresql.org/message-id/CANhcyEVSXyQkvmrsOWPdQqnm2J3GMyQQrKhyCJiBQzqs6AvSow%40mail.gmail.com Kind Regards, Peter Smith. Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Thu, Apr 16, 2026 at 5:44 AM Peter Smith wrote: > > On Wed, Apr 15, 2026 at 8:15 PM shveta malik wrote: > > > > On Wed, Apr 15, 2026 at 2:22 PM Nisha Moond wrote: > > > > > > On Tue, Apr 14, 2026 at 3:22 PM shveta malik wrote: > > > > > > > > On Tue, Apr 14, 2026 at 3:15 PM Nisha Moond wrote: > > > > > > > > > > On Tue, Apr 14, 2026 at 1:03 PM Peter Smith wrote: > > > > > > > > > > > > On Tue, Apr 14, 2026 at 4:30 PM Nisha Moond wrote: > > > > > > > > > > > > > > Hi hackers, > > > > > > > > > > > > > > Following earlier work to support EXCEPT for FOR ALL TABLES [1] > > > > > > > publications, starting this thread to extend the same capability to > > > > > > > schema-level publications (TABLES IN SCHEMA). > > > > > > > > > > > > Hi Nisha. > > > > > > > > > > > > +1 for adding this new kind of exclusion clause to CREATE PUBLICATION command. > > > > > > > > > > > > > > > > > > > > Currently, TABLES IN SCHEMA publishes all tables in a schema with no > > > > > > > way to exclude a subset. Users who want to skip a few tables must > > > > > > > switch to an explicit FOR TABLE list, which loses the convenience of > > > > > > > schema-level publishing and requires ongoing maintenance as tables are > > > > > > > added. > > > > > > > > > > > > > > Proposed syntax: > > > > > > > ------------------------ > > > > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); > > > > > > > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > > > ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > > > > > > > > > > Note: Tables in the EXCEPT clause must be schema-qualified to avoid > > > > > > > ambiguity and must belong to the published schema; otherwise, an error > > > > > > > is raised. > > > > > > > > > > > > > > > > > > > The proposed syntax is almost, but not quite, what I was anticipating. > > > > > > IMO the syntax shouldn't just be similar to the FOR ALL TABLES EXCEPT; > > > > > > It can be *identical* to it. e.g., your examples are missing the > > > > > > 'TABLE' keyword necessary to achieve the same command flexibility. > > > > > > > > > > > > > > > > I intentionally didn’t use the TABLE keyword inside EXCEPT. > > > > > IIUC, for FOR ALL TABLES EXCEPT, there may be a future need to > > > > > distinguish object types (e.g., tables vs schemas), which is why > > > > > specifying TABLE makes sense there. > > > > > > > > > > However, for TABLES IN SCHEMA, only tables can be specified, so > > > > > omitting TABLE keeps the syntax simpler and more intuitive. > > > > > > > > > > Let's hear others’ opinions too on this and I'll adjust if there’s a > > > > > preference for including it. > > > > > > > > > > > > > Nisha, please see pt 1 in [1]. If we plan to support that, then we > > > > need TABLE keyword, otherwise we are fine. > > > > > > > > [1]: https://www.postgresql.org/message-id/CAJpy0uB%3DJxTYXOB7VmrhVLR%2B1PG0%3DTtHuGekaqibOPpo2UBLiQ%40mail.gmail.com > > > > > > > > > > Thank you Shveta for pointing to the discussion. > > > So, if we were to extend CREATE PUBLICATION to support something like: > > > "CREATE PUBLICATION pub FOR TABLES, SEQUENCES IN SCHEMA sch1 EXCEPT > > > (TABLE t1, SEQUENCE s1);" > > > then, introducing TABLE inside EXCEPT could make sense, but at this > > > stage we’re not sure how the syntax for supporting SEQUENCES IN SCHEMA > > > will evolve. The overall grammar may require broader changes rather > > > than a simple extension. So, we can always introduce keywords like > > > TABLE or SEQUENCE later, if and when they are actually needed. Just my > > > thoughts. > > > > > > > It works for me Nisha. I also agree that the 'TABLE' keyword seems > > redundant in the case you proposed: > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); > > > > But I am just worried this might confuse users, as one command > > requires specifying the TABLE with EXCEPT, while another requires > > omitting it. But we can first focus on implementation and come back to > > it later when more people join and share their thoughts. > > > > I agree with Shveta that inconsistency will confuse. > > We already have FOR ALL TABLES EXCEPT (TABLE ...) [1] > And another place is currently introducing FOR ALL SEQUENCES EXCEPT > (SEQUENCE ...) [2] > IMO, this schema thread should match [1]. > > I think syntax *consistency* should take priority here. While some > keywords may end up being unnecessary in certain cases, having > different rules for each EXCEPT variation seems harder to maintain and > reason about. > > I also agree with you that we are not sure how the command syntax > might evolve in future. That is another reason why requiring these > keywords (like 'TABLE' and 'SEQUENCE') is the best/safest first > approach, IMO, because it will be backward-compatible. For example, if > it turns out we can make (some of) these keywords optional in future, > then user code will still be fine, but if they are absent now, then we > cannot make them mandatory in future PostgreSQL versions without > breaking user code. > Okay, to maintain consistency in the EXCEPT syntax across publication commands and keeping future compatibility in mind, I’m fine updating the syntax. I’ll share an updated patch soon. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Wed, Apr 15, 2026 at 7:35 AM Peter Smith wrote:
>
> On Tue, Apr 14, 2026 at 7:37 PM Amit Kapila wrote:
> >
> > On Tue, Apr 14, 2026 at 2:05 PM shveta malik wrote:
> > >
> > > On Tue, Apr 14, 2026 at 1:03 PM Peter Smith wrote:
> > > >
> > > > On Tue, Apr 14, 2026 at 4:30 PM Nisha Moond wrote:
> > > > >
> > > > > Hi hackers,
> > > > >
> > > > > Following earlier work to support EXCEPT for FOR ALL TABLES [1]
> > > > > publications, starting this thread to extend the same capability to
> > > > > schema-level publications (TABLES IN SCHEMA).
> > > >
> > > > Hi Nisha.
> > > >
> > > > +1 for adding this new kind of exclusion clause to CREATE PUBLICATION command.
> > > >
> > > > >
> > > > > Currently, TABLES IN SCHEMA publishes all tables in a schema with no
> > > > > way to exclude a subset. Users who want to skip a few tables must
> > > > > switch to an explicit FOR TABLE list, which loses the convenience of
> > > > > schema-level publishing and requires ongoing maintenance as tables are
> > > > > added.
> > > > >
> > > > > Proposed syntax:
> > > > > ------------------------
> > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2);
> > > > > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1);
> > > > > ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1);
> > > > >
> > > > > Note: Tables in the EXCEPT clause must be schema-qualified to avoid
> > > > > ambiguity and must belong to the published schema; otherwise, an error
> > > > > is raised.
> > > > >
> > > >
> > > > The proposed syntax is almost, but not quite, what I was anticipating.
> > > > IMO the syntax shouldn't just be similar to the FOR ALL TABLES EXCEPT;
> > > > It can be *identical* to it. e.g., your examples are missing the
> > > > 'TABLE' keyword necessary to achieve the same command flexibility.
> > > > Furthermore, what is the ambiguity referred to? An excluded table is
> > > > clearly associated with the preceding schema. Can't the code infer the
> > > > schema internally even when it is not provided by the user? Of course,
> > > > the user *can* specify a schema-qualified name if they want to, but I
> > > > didn't see why we are forcing that rule upon them.
> > >
> > > +1. I also feel specifying only the table name is clear enough. Or are
> > > we referring to implementation complexity here?
> > >
> >
> > I think it will add complexity. Consider an example:
> > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2, s3 EXCEPT (t1, t2);
> >
> > So, which schema's exclusion list will these tables should be
> > considered for? Say, if table with name t1 is present in all schemas
> > then shall we exclude from all schemas or just consider it excluded
> > from the first one (s1)?
> >
>
> The exact pattern is already in common usage for row-filters and
> column-lists, yet nobody is confused.
>
> -- all these tables have the same column names
> -- (analogous to multiple schemas having same table names)
> CREATE TABLE t1(c1 int, c2 int);
> CREATE TABLE t2(c1 int, c2 int);
> CREATE TABLE t3(c1 int, c2 int);
>
> -- all tables have a column c1
> -- but this c1 means t3.c1 because the column-list is only for the adjacent t3.
> CREATE PUBLICATION pub1 FOR TABLE t1, t2, t3 (c1);
>
> -- all tables have a column c2
> -- but this c2 means t3.c2 because the row-filter is only for the adjacent t3.
> CREATE PUBLICATION pub2 FOR TABLE t1, t2, t3 WHERE (c2 > 99);
>
> \dRp+
> Publication pub1
> Owner | All tables | All sequences | Inserts | Updates | Deletes |
> Truncates | Generated columns | Via root | Description
> ----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+-------------
> postgres | f | f | t | t | t |
> t | none | f |
> Tables:
> "public.t1"
> "public.t2"
> "public.t3" (c1)
>
> Publication pub2
> Owner | All tables | All sequences | Inserts | Updates | Deletes |
> Truncates | Generated columns | Via root | Description
> ----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+-------------
> postgres | f | f | t | t | t |
> t | none | f |
> Tables:
> "public.t1"
> "public.t2"
> "public.t3" WHERE (c2 > 99)
>
My intention was to avoid potential ambiguity when tables are not
schema-qualified, as mentioned by Amit [1].
That said, PostgreSQL generally does not enforce schema qualification
and relies on search_path [2][3] for object resolution. Users are
typically familiar with this behavior.
Thanks for the example. I’ve updated the syntax to allow tables in the
EXCEPT list without schema qualification.
If a table is specified without a schema, it is resolved against the
immediately preceding schema clause.
Few examples:
CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2 EXCEPT (TABLE t1);
-- table t1 is resolved in schema s2
CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1), s2
EXCEPT (TABLE t2);
-- if s1 does not contain t1, an error is raised: "s1.t1" does not exist
CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2 EXCEPT (TABLE s1.t1, s2.t1);
-- it will create the publication with except list - (s1.t1, s2.t1)
Attached v3 patches with the following updates:
1) Updated syntax to include TABLE keyword as per discussion [1]
CREATE/ALTER PUBLICATION ... FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1, ...);
2) Removed the requirement for schema-qualified table names in the EXCEPT list.
[1] https://www.postgresql.org/message-id/CAA4eK1KbCWBmEXH-rhQjKgNwq%3DonZp8vRR-QkRhPpbKwL-kQdw%40mail.gmail.com
[2] https://www.postgresql.org/docs/current/ddl-schemas.html#DDL-SCHEMAS-PATH
[3] https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-SEARCH-PATH
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Thu, Apr 16, 2026 at 4:24 PM Nisha Moond wrote: > > On Wed, Apr 15, 2026 at 7:35 AM Peter Smith wrote: > > > > On Tue, Apr 14, 2026 at 7:37 PM Amit Kapila wrote: > > > > > > On Tue, Apr 14, 2026 at 2:05 PM shveta malik wrote: > > > > > > > > On Tue, Apr 14, 2026 at 1:03 PM Peter Smith wrote: > > > > > > > > > > On Tue, Apr 14, 2026 at 4:30 PM Nisha Moond wrote: > > > > > > > > > > > > Hi hackers, > > > > > > > > > > > > Following earlier work to support EXCEPT for FOR ALL TABLES [1] > > > > > > publications, starting this thread to extend the same capability to > > > > > > schema-level publications (TABLES IN SCHEMA). > > > > > > > > > > Hi Nisha. > > > > > > > > > > +1 for adding this new kind of exclusion clause to CREATE PUBLICATION command. > > > > > > > > > > > > > > > > > Currently, TABLES IN SCHEMA publishes all tables in a schema with no > > > > > > way to exclude a subset. Users who want to skip a few tables must > > > > > > switch to an explicit FOR TABLE list, which loses the convenience of > > > > > > schema-level publishing and requires ongoing maintenance as tables are > > > > > > added. > > > > > > > > > > > > Proposed syntax: > > > > > > ------------------------ > > > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); > > > > > > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > > ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > > > > > > > > Note: Tables in the EXCEPT clause must be schema-qualified to avoid > > > > > > ambiguity and must belong to the published schema; otherwise, an error > > > > > > is raised. > > > > > > > > > > > > > > > > The proposed syntax is almost, but not quite, what I was anticipating. > > > > > IMO the syntax shouldn't just be similar to the FOR ALL TABLES EXCEPT; > > > > > It can be *identical* to it. e.g., your examples are missing the > > > > > 'TABLE' keyword necessary to achieve the same command flexibility. > > > > > Furthermore, what is the ambiguity referred to? An excluded table is > > > > > clearly associated with the preceding schema. Can't the code infer the > > > > > schema internally even when it is not provided by the user? Of course, > > > > > the user *can* specify a schema-qualified name if they want to, but I > > > > > didn't see why we are forcing that rule upon them. > > > > > > > > +1. I also feel specifying only the table name is clear enough. Or are > > > > we referring to implementation complexity here? > > > > > > > > > > I think it will add complexity. Consider an example: > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2, s3 EXCEPT (t1, t2); > > > > > > So, which schema's exclusion list will these tables should be > > > considered for? Say, if table with name t1 is present in all schemas > > > then shall we exclude from all schemas or just consider it excluded > > > from the first one (s1)? > > > > > > > The exact pattern is already in common usage for row-filters and > > column-lists, yet nobody is confused. > > > > -- all these tables have the same column names > > -- (analogous to multiple schemas having same table names) > > CREATE TABLE t1(c1 int, c2 int); > > CREATE TABLE t2(c1 int, c2 int); > > CREATE TABLE t3(c1 int, c2 int); > > > > -- all tables have a column c1 > > -- but this c1 means t3.c1 because the column-list is only for the adjacent t3. > > CREATE PUBLICATION pub1 FOR TABLE t1, t2, t3 (c1); > > > > -- all tables have a column c2 > > -- but this c2 means t3.c2 because the row-filter is only for the adjacent t3. > > CREATE PUBLICATION pub2 FOR TABLE t1, t2, t3 WHERE (c2 > 99); > > > > \dRp+ > > Publication pub1 > > Owner | All tables | All sequences | Inserts | Updates | Deletes | > > Truncates | Generated columns | Via root | Description > > ----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------------- > > postgres | f | f | t | t | t | > > t | none | f | > > Tables: > > "public.t1" > > "public.t2" > > "public.t3" (c1) > > > > Publication pub2 > > Owner | All tables | All sequences | Inserts | Updates | Deletes | > > Truncates | Generated columns | Via root | Description > > ----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------------- > > postgres | f | f | t | t | t | > > t | none | f | > > Tables: > > "public.t1" > > "public.t2" > > "public.t3" WHERE (c2 > 99) > > > > My intention was to avoid potential ambiguity when tables are not > schema-qualified, as mentioned by Amit [1]. > > That said, PostgreSQL generally does not enforce schema qualification > and relies on search_path [2][3] for object resolution. Users are > typically familiar with this behavior. > > Thanks for the example. I’ve updated the syntax to allow tables in the > EXCEPT list without schema qualification. > If a table is specified without a schema, it is resolved against the > immediately preceding schema clause. > > Few examples: > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2 EXCEPT (TABLE t1); > -- table t1 is resolved in schema s2 Okay, looks good. > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1), s2 > EXCEPT (TABLE t2); > -- if s1 does not contain t1, an error is raised: "s1.t1" does not exist Okay, looks good. > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2 EXCEPT (TABLE s1.t1, s2.t1); > -- it will create the publication with except list - (s1.t1, s2.t1) Okay, I thought we will not be supporting EXCEPT at the end and mixed schemas inside. What will happen if I give: CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2 EXCEPT (TABLE t1, t2); and t1, t2 are present in both the schemas? I feel just like we associate column lists and row filters directly with each table, rather than using a mixed style at the end; we should also allow EXCEPT to be specified alongside each schema. This would avoid added complexity and reduce potential confusion. Thoughts? thanks Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Fri, Apr 24, 2026 at 10:16 AM shveta malik wrote: > > On Thu, Apr 16, 2026 at 4:24 PM Nisha Moond wrote: > > > > On Wed, Apr 15, 2026 at 7:35 AM Peter Smith wrote: > > > > > > On Tue, Apr 14, 2026 at 7:37 PM Amit Kapila wrote: > > > > > > > > On Tue, Apr 14, 2026 at 2:05 PM shveta malik wrote: > > > > > > > > > > On Tue, Apr 14, 2026 at 1:03 PM Peter Smith wrote: > > > > > > > > > > > > On Tue, Apr 14, 2026 at 4:30 PM Nisha Moond wrote: > > > > > > > > > > > > > > Hi hackers, > > > > > > > > > > > > > > Following earlier work to support EXCEPT for FOR ALL TABLES [1] > > > > > > > publications, starting this thread to extend the same capability to > > > > > > > schema-level publications (TABLES IN SCHEMA). > > > > > > > > > > > > Hi Nisha. > > > > > > > > > > > > +1 for adding this new kind of exclusion clause to CREATE PUBLICATION command. > > > > > > > > > > > > > > > > > > > > Currently, TABLES IN SCHEMA publishes all tables in a schema with no > > > > > > > way to exclude a subset. Users who want to skip a few tables must > > > > > > > switch to an explicit FOR TABLE list, which loses the convenience of > > > > > > > schema-level publishing and requires ongoing maintenance as tables are > > > > > > > added. > > > > > > > > > > > > > > Proposed syntax: > > > > > > > ------------------------ > > > > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); > > > > > > > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > > > ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > > > > > > > > > > Note: Tables in the EXCEPT clause must be schema-qualified to avoid > > > > > > > ambiguity and must belong to the published schema; otherwise, an error > > > > > > > is raised. > > > > > > > > > > > > > > > > > > > The proposed syntax is almost, but not quite, what I was anticipating. > > > > > > IMO the syntax shouldn't just be similar to the FOR ALL TABLES EXCEPT; > > > > > > It can be *identical* to it. e.g., your examples are missing the > > > > > > 'TABLE' keyword necessary to achieve the same command flexibility. > > > > > > Furthermore, what is the ambiguity referred to? An excluded table is > > > > > > clearly associated with the preceding schema. Can't the code infer the > > > > > > schema internally even when it is not provided by the user? Of course, > > > > > > the user *can* specify a schema-qualified name if they want to, but I > > > > > > didn't see why we are forcing that rule upon them. > > > > > > > > > > +1. I also feel specifying only the table name is clear enough. Or are > > > > > we referring to implementation complexity here? > > > > > > > > > > > > > I think it will add complexity. Consider an example: > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2, s3 EXCEPT (t1, t2); > > > > > > > > So, which schema's exclusion list will these tables should be > > > > considered for? Say, if table with name t1 is present in all schemas > > > > then shall we exclude from all schemas or just consider it excluded > > > > from the first one (s1)? > > > > > > > > > > The exact pattern is already in common usage for row-filters and > > > column-lists, yet nobody is confused. > > > > > > -- all these tables have the same column names > > > -- (analogous to multiple schemas having same table names) > > > CREATE TABLE t1(c1 int, c2 int); > > > CREATE TABLE t2(c1 int, c2 int); > > > CREATE TABLE t3(c1 int, c2 int); > > > > > > -- all tables have a column c1 > > > -- but this c1 means t3.c1 because the column-list is only for the adjacent t3. > > > CREATE PUBLICATION pub1 FOR TABLE t1, t2, t3 (c1); > > > > > > -- all tables have a column c2 > > > -- but this c2 means t3.c2 because the row-filter is only for the adjacent t3. > > > CREATE PUBLICATION pub2 FOR TABLE t1, t2, t3 WHERE (c2 > 99); > > > > > > \dRp+ > > > Publication pub1 > > > Owner | All tables | All sequences | Inserts | Updates | Deletes | > > > Truncates | Generated columns | Via root | Description > > > ----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------------- > > > postgres | f | f | t | t | t | > > > t | none | f | > > > Tables: > > > "public.t1" > > > "public.t2" > > > "public.t3" (c1) > > > > > > Publication pub2 > > > Owner | All tables | All sequences | Inserts | Updates | Deletes | > > > Truncates | Generated columns | Via root | Description > > > ----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------------- > > > postgres | f | f | t | t | t | > > > t | none | f | > > > Tables: > > > "public.t1" > > > "public.t2" > > > "public.t3" WHERE (c2 > 99) > > > > > > > My intention was to avoid potential ambiguity when tables are not > > schema-qualified, as mentioned by Amit [1]. > > > > That said, PostgreSQL generally does not enforce schema qualification > > and relies on search_path [2][3] for object resolution. Users are > > typically familiar with this behavior. > > > > Thanks for the example. I’ve updated the syntax to allow tables in the > > EXCEPT list without schema qualification. > > If a table is specified without a schema, it is resolved against the > > immediately preceding schema clause. > > > > Few examples: > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2 EXCEPT (TABLE t1); > > -- table t1 is resolved in schema s2 > > Okay, looks good. > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1), s2 > > EXCEPT (TABLE t2); > > -- if s1 does not contain t1, an error is raised: "s1.t1" does not exist > > Okay, looks good. > > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2 EXCEPT (TABLE s1.t1, s2.t1); > > -- it will create the publication with except list - (s1.t1, s2.t1) > > Okay, I thought we will not be supporting EXCEPT at the end and mixed > schemas inside. What will happen if I give: > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2 EXCEPT (TABLE t1, t2); > > and t1, t2 are present in both the schemas? > > I feel just like we associate column lists and row filters directly > with each table, rather than using a mixed style at the end; we should > also allow EXCEPT to be specified alongside each schema. This would > avoid added complexity and reduce potential confusion. Thoughts? One correction: I meant, we should "only" allow EXCEPT to be specified alongside each schema. thanks Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Fri, Apr 24, 2026 at 11:29 AM shveta malik wrote: > > On Fri, Apr 24, 2026 at 10:16 AM shveta malik wrote: > > > > On Thu, Apr 16, 2026 at 4:24 PM Nisha Moond wrote: > > > > > > On Wed, Apr 15, 2026 at 7:35 AM Peter Smith wrote: > > > > > > > > On Tue, Apr 14, 2026 at 7:37 PM Amit Kapila wrote: > > > > > > > > > > On Tue, Apr 14, 2026 at 2:05 PM shveta malik wrote: > > > > > > > > > > > > On Tue, Apr 14, 2026 at 1:03 PM Peter Smith wrote: > > > > > > > > > > > > > > On Tue, Apr 14, 2026 at 4:30 PM Nisha Moond wrote: > > > > > > > > > > > > > > > > Hi hackers, > > > > > > > > > > > > > > > > Following earlier work to support EXCEPT for FOR ALL TABLES [1] > > > > > > > > publications, starting this thread to extend the same capability to > > > > > > > > schema-level publications (TABLES IN SCHEMA). > > > > > > > > > > > > > > Hi Nisha. > > > > > > > > > > > > > > +1 for adding this new kind of exclusion clause to CREATE PUBLICATION command. > > > > > > > > > > > > > > > > > > > > > > > Currently, TABLES IN SCHEMA publishes all tables in a schema with no > > > > > > > > way to exclude a subset. Users who want to skip a few tables must > > > > > > > > switch to an explicit FOR TABLE list, which loses the convenience of > > > > > > > > schema-level publishing and requires ongoing maintenance as tables are > > > > > > > > added. > > > > > > > > > > > > > > > > Proposed syntax: > > > > > > > > ------------------------ > > > > > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); > > > > > > > > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > > > > ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > > > > > > > > > > > > Note: Tables in the EXCEPT clause must be schema-qualified to avoid > > > > > > > > ambiguity and must belong to the published schema; otherwise, an error > > > > > > > > is raised. > > > > > > > > > > > > > > > > > > > > > > The proposed syntax is almost, but not quite, what I was anticipating. > > > > > > > IMO the syntax shouldn't just be similar to the FOR ALL TABLES EXCEPT; > > > > > > > It can be *identical* to it. e.g., your examples are missing the > > > > > > > 'TABLE' keyword necessary to achieve the same command flexibility. > > > > > > > Furthermore, what is the ambiguity referred to? An excluded table is > > > > > > > clearly associated with the preceding schema. Can't the code infer the > > > > > > > schema internally even when it is not provided by the user? Of course, > > > > > > > the user *can* specify a schema-qualified name if they want to, but I > > > > > > > didn't see why we are forcing that rule upon them. > > > > > > > > > > > > +1. I also feel specifying only the table name is clear enough. Or are > > > > > > we referring to implementation complexity here? > > > > > > > > > > > > > > > > I think it will add complexity. Consider an example: > > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2, s3 EXCEPT (t1, t2); > > > > > > > > > > So, which schema's exclusion list will these tables should be > > > > > considered for? Say, if table with name t1 is present in all schemas > > > > > then shall we exclude from all schemas or just consider it excluded > > > > > from the first one (s1)? > > > > > > > > > > > > > The exact pattern is already in common usage for row-filters and > > > > column-lists, yet nobody is confused. > > > > > > > > -- all these tables have the same column names > > > > -- (analogous to multiple schemas having same table names) > > > > CREATE TABLE t1(c1 int, c2 int); > > > > CREATE TABLE t2(c1 int, c2 int); > > > > CREATE TABLE t3(c1 int, c2 int); > > > > > > > > -- all tables have a column c1 > > > > -- but this c1 means t3.c1 because the column-list is only for the adjacent t3. > > > > CREATE PUBLICATION pub1 FOR TABLE t1, t2, t3 (c1); > > > > > > > > -- all tables have a column c2 > > > > -- but this c2 means t3.c2 because the row-filter is only for the adjacent t3. > > > > CREATE PUBLICATION pub2 FOR TABLE t1, t2, t3 WHERE (c2 > 99); > > > > > > > > \dRp+ > > > > Publication pub1 > > > > Owner | All tables | All sequences | Inserts | Updates | Deletes | > > > > Truncates | Generated columns | Via root | Description > > > > ----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------------- > > > > postgres | f | f | t | t | t | > > > > t | none | f | > > > > Tables: > > > > "public.t1" > > > > "public.t2" > > > > "public.t3" (c1) > > > > > > > > Publication pub2 > > > > Owner | All tables | All sequences | Inserts | Updates | Deletes | > > > > Truncates | Generated columns | Via root | Description > > > > ----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------------- > > > > postgres | f | f | t | t | t | > > > > t | none | f | > > > > Tables: > > > > "public.t1" > > > > "public.t2" > > > > "public.t3" WHERE (c2 > 99) > > > > > > > > > > My intention was to avoid potential ambiguity when tables are not > > > schema-qualified, as mentioned by Amit [1]. > > > > > > That said, PostgreSQL generally does not enforce schema qualification > > > and relies on search_path [2][3] for object resolution. Users are > > > typically familiar with this behavior. > > > > > > Thanks for the example. I’ve updated the syntax to allow tables in the > > > EXCEPT list without schema qualification. > > > If a table is specified without a schema, it is resolved against the > > > immediately preceding schema clause. > > > > > > Few examples: > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2 EXCEPT (TABLE t1); > > > -- table t1 is resolved in schema s2 > > > > Okay, looks good. > > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1), s2 > > > EXCEPT (TABLE t2); > > > -- if s1 does not contain t1, an error is raised: "s1.t1" does not exist > > > > Okay, looks good. > > > > > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2 EXCEPT (TABLE s1.t1, s2.t1); > > > -- it will create the publication with except list - (s1.t1, s2.t1) > > > > Okay, I thought we will not be supporting EXCEPT at the end and mixed > > schemas inside. What will happen if I give: > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2 EXCEPT (TABLE t1, t2); > > > > and t1, t2 are present in both the schemas? > > If no schema is specified, tables are resolved against the immediate schema. In this case, s2.t1 and s2.t2 will be used in the EXCEPT list, even if they exist in both s1 and s2. > > I feel just like we associate column lists and row filters directly > > with each table, rather than using a mixed style at the end; we should > > also allow EXCEPT to be specified alongside each schema. This would > > avoid added complexity and reduce potential confusion. Thoughts? > > One correction: I meant, we should "only" allow EXCEPT to be > specified alongside each schema. > I kept this for user convenience to specify the EXCEPT list in one go. But as you mentioned, supporting mixed style adds complexity, as currently, it checks tables against all schemas in the publication (not just those in the command). In further testing, I also noticed below confusing behavior due to allowed mixed style - CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1; ALTER PUBLICATION pub ADD TABLES IN SCHEMA s2 EXCEPT (TABLE s1.t1); -- here, s1.t1 is allowed in EXCEPT because s1 is already part of the publication, even though it’s not in the current command. Let me make the changes to restrict the mixed style. Will share the updated patch soon. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Mon, Apr 27, 2026 at 9:02 AM Nisha Moond wrote: > > On Fri, Apr 24, 2026 at 11:29 AM shveta malik wrote: > > > > On Fri, Apr 24, 2026 at 10:16 AM shveta malik wrote: > > > > > > On Thu, Apr 16, 2026 at 4:24 PM Nisha Moond wrote: > > > > > > > > On Wed, Apr 15, 2026 at 7:35 AM Peter Smith wrote: > > > > > > > > > > On Tue, Apr 14, 2026 at 7:37 PM Amit Kapila wrote: > > > > > > > > > > > > On Tue, Apr 14, 2026 at 2:05 PM shveta malik wrote: > > > > > > > > > > > > > > On Tue, Apr 14, 2026 at 1:03 PM Peter Smith wrote: > > > > > > > > > > > > > > > > On Tue, Apr 14, 2026 at 4:30 PM Nisha Moond wrote: > > > > > > > > > > > > > > > > > > Hi hackers, > > > > > > > > > > > > > > > > > > Following earlier work to support EXCEPT for FOR ALL TABLES [1] > > > > > > > > > publications, starting this thread to extend the same capability to > > > > > > > > > schema-level publications (TABLES IN SCHEMA). > > > > > > > > > > > > > > > > Hi Nisha. > > > > > > > > > > > > > > > > +1 for adding this new kind of exclusion clause to CREATE PUBLICATION command. > > > > > > > > > > > > > > > > > > > > > > > > > > Currently, TABLES IN SCHEMA publishes all tables in a schema with no > > > > > > > > > way to exclude a subset. Users who want to skip a few tables must > > > > > > > > > switch to an explicit FOR TABLE list, which loses the convenience of > > > > > > > > > schema-level publishing and requires ongoing maintenance as tables are > > > > > > > > > added. > > > > > > > > > > > > > > > > > > Proposed syntax: > > > > > > > > > ------------------------ > > > > > > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (s1.t1, s1.t2); > > > > > > > > > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > > > > > ALTER PUBLICATION pub SET TABLES IN SCHEMA s1 EXCEPT (s1.t1); > > > > > > > > > > > > > > > > > > Note: Tables in the EXCEPT clause must be schema-qualified to avoid > > > > > > > > > ambiguity and must belong to the published schema; otherwise, an error > > > > > > > > > is raised. > > > > > > > > > > > > > > > > > > > > > > > > > The proposed syntax is almost, but not quite, what I was anticipating. > > > > > > > > IMO the syntax shouldn't just be similar to the FOR ALL TABLES EXCEPT; > > > > > > > > It can be *identical* to it. e.g., your examples are missing the > > > > > > > > 'TABLE' keyword necessary to achieve the same command flexibility. > > > > > > > > Furthermore, what is the ambiguity referred to? An excluded table is > > > > > > > > clearly associated with the preceding schema. Can't the code infer the > > > > > > > > schema internally even when it is not provided by the user? Of course, > > > > > > > > the user *can* specify a schema-qualified name if they want to, but I > > > > > > > > didn't see why we are forcing that rule upon them. > > > > > > > > > > > > > > +1. I also feel specifying only the table name is clear enough. Or are > > > > > > > we referring to implementation complexity here? > > > > > > > > > > > > > > > > > > > I think it will add complexity. Consider an example: > > > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2, s3 EXCEPT (t1, t2); > > > > > > > > > > > > So, which schema's exclusion list will these tables should be > > > > > > considered for? Say, if table with name t1 is present in all schemas > > > > > > then shall we exclude from all schemas or just consider it excluded > > > > > > from the first one (s1)? > > > > > > > > > > > > > > > > The exact pattern is already in common usage for row-filters and > > > > > column-lists, yet nobody is confused. > > > > > > > > > > -- all these tables have the same column names > > > > > -- (analogous to multiple schemas having same table names) > > > > > CREATE TABLE t1(c1 int, c2 int); > > > > > CREATE TABLE t2(c1 int, c2 int); > > > > > CREATE TABLE t3(c1 int, c2 int); > > > > > > > > > > -- all tables have a column c1 > > > > > -- but this c1 means t3.c1 because the column-list is only for the adjacent t3. > > > > > CREATE PUBLICATION pub1 FOR TABLE t1, t2, t3 (c1); > > > > > > > > > > -- all tables have a column c2 > > > > > -- but this c2 means t3.c2 because the row-filter is only for the adjacent t3. > > > > > CREATE PUBLICATION pub2 FOR TABLE t1, t2, t3 WHERE (c2 > 99); > > > > > > > > > > \dRp+ > > > > > Publication pub1 > > > > > Owner | All tables | All sequences | Inserts | Updates | Deletes | > > > > > Truncates | Generated columns | Via root | Description > > > > > ----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------------- > > > > > postgres | f | f | t | t | t | > > > > > t | none | f | > > > > > Tables: > > > > > "public.t1" > > > > > "public.t2" > > > > > "public.t3" (c1) > > > > > > > > > > Publication pub2 > > > > > Owner | All tables | All sequences | Inserts | Updates | Deletes | > > > > > Truncates | Generated columns | Via root | Description > > > > > ----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------------- > > > > > postgres | f | f | t | t | t | > > > > > t | none | f | > > > > > Tables: > > > > > "public.t1" > > > > > "public.t2" > > > > > "public.t3" WHERE (c2 > 99) > > > > > > > > > > > > > My intention was to avoid potential ambiguity when tables are not > > > > schema-qualified, as mentioned by Amit [1]. > > > > > > > > That said, PostgreSQL generally does not enforce schema qualification > > > > and relies on search_path [2][3] for object resolution. Users are > > > > typically familiar with this behavior. > > > > > > > > Thanks for the example. I’ve updated the syntax to allow tables in the > > > > EXCEPT list without schema qualification. > > > > If a table is specified without a schema, it is resolved against the > > > > immediately preceding schema clause. > > > > > > > > Few examples: > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2 EXCEPT (TABLE t1); > > > > -- table t1 is resolved in schema s2 > > > > > > Okay, looks good. > > > > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1), s2 > > > > EXCEPT (TABLE t2); > > > > -- if s1 does not contain t1, an error is raised: "s1.t1" does not exist > > > > > > Okay, looks good. > > > > > > > > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2 EXCEPT (TABLE s1.t1, s2.t1); > > > > -- it will create the publication with except list - (s1.t1, s2.t1) > > > > > > Okay, I thought we will not be supporting EXCEPT at the end and mixed > > > schemas inside. What will happen if I give: > > > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2 EXCEPT (TABLE t1, t2); > > > > > > and t1, t2 are present in both the schemas? > > > > > If no schema is specified, tables are resolved against the immediate > schema. In this case, s2.t1 and s2.t2 will be used in the EXCEPT list, > even if they exist in both s1 and s2. > > > > I feel just like we associate column lists and row filters directly > > > with each table, rather than using a mixed style at the end; we should > > > also allow EXCEPT to be specified alongside each schema. This would > > > avoid added complexity and reduce potential confusion. Thoughts? > > > > One correction: I meant, we should "only" allow EXCEPT to be > > specified alongside each schema. > > > > I kept this for user convenience to specify the EXCEPT list in one go. > But as you mentioned, supporting mixed style adds complexity, as > currently, it checks tables against all schemas in the publication > (not just those in the command). > > In further testing, I also noticed below confusing behavior due to > allowed mixed style - > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1; > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s2 EXCEPT (TABLE s1.t1); > -- here, s1.t1 is allowed in EXCEPT because s1 is already part of the > publication, even though it’s not in the current command. This case seems further confusing. > > Let me make the changes to restrict the mixed style. Will share the > updated patch soon. > Yes, that will be better approach. thanks Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Mon, Apr 27, 2026 at 9:06 AM shveta malik wrote: > > On Mon, Apr 27, 2026 at 9:02 AM Nisha Moond wrote: > > > > On Fri, Apr 24, 2026 at 11:29 AM shveta malik wrote: > > > > > > > I feel just like we associate column lists and row filters directly > > > > with each table, rather than using a mixed style at the end; we should > > > > also allow EXCEPT to be specified alongside each schema. This would > > > > avoid added complexity and reduce potential confusion. Thoughts? > > > > > > One correction: I meant, we should "only" allow EXCEPT to be > > > specified alongside each schema. > > > > > > > I kept this for user convenience to specify the EXCEPT list in one go. > > But as you mentioned, supporting mixed style adds complexity, as > > currently, it checks tables against all schemas in the publication > > (not just those in the command). > > > > In further testing, I also noticed below confusing behavior due to > > allowed mixed style - > > > > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1; > > ALTER PUBLICATION pub ADD TABLES IN SCHEMA s2 EXCEPT (TABLE s1.t1); > > -- here, s1.t1 is allowed in EXCEPT because s1 is already part of the > > publication, even though it’s not in the current command. > > This case seems further confusing. > > > > > Let me make the changes to restrict the mixed style. Will share the > > updated patch soon. > > > > Yes, that will be better approach. > Please find the attached patches incorporating the above suggestion. The EXCEPT clause now accepts tables only of its adjacent schema and mixed style is not allowed. Few examples : CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1 EXCEPT (TABLE t1), s2 EXCEPT (TABLE t1); -- both s1.t1 and s2.t1 will be added in except list CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1, s2 EXCEPT (TABLE s1.t1, s2.t1); -- ERROR: table "s1.t1" in EXCEPT clause does not belong to schema "s2" -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Hi Nisha.
Some review comments for v4-0001 (docs only).
======
doc/src/sgml/ref/create_publication.sgml
1.
+ TABLES IN SCHEMA { schema_name | CURRENT_SCHEMA } [
EXCEPT ( except_table_object [, ... ] ) ] [,
... ]
It is ambiguous which part does that last ellipsis applies to?
Consider instead:
TABLES IN SCHEMA tables_in_schema [, ... ]
and tables_in_schema is:
{ schema_name | CURRENT_SCHEMA } [ EXCEPT ( except_table_object [, ... ] ) ]
~~~
2.
This clause specifies a list of tables to be excluded from the
- publication.
+ publication. It can be used with both FOR ALL TABLES
+ and FOR TABLES IN SCHEMA.
Saying "both" may imply they can coexist, but they cannot.
SUGGESTION
It can be used with FOR ALL TABLES or FOR
TABLES IN SCHEMA.
~~~
3.
+
+ Create a publication that publishes all changes for all the tables
present in
+ the schema sales, except
+ sales.internal and
sales.drafts:
+
+CREATE PUBLICATION sales_filtered FOR TABLES IN SCHEMA sales EXCEPT
(TABLE sales.internal, sales.drafts);
+
+
+
AFAIK, the tables in the EXCEPT clause do not need to be
schema-qualified, so they should not be written that way in the
programlisting part of this example, because it might give the user
the impression that schema-qualified names are required.
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Hi Nisha. A couple of ad-hoc review comments for v4-0001... ====== src/bin/pg_dump/pg_dump.c dumpPublicationNamespace: 1. + if (!first_except) + appendPQExpBufferStr(query, ")"); The logic seems ok, but the above seems a bit strange, checking 'first_except'. Maybe renaming to 'has_except' (and some small refactoring) would read better? ~~~ 2. IIUC, the 'ALTER PUBLICATION' EXCEPT clause syntax change is not introduced until your patch 0003. So, how does this dump code even work when it relies on that ALTER PUBLICATION? Furthermore, the patch 0003 commit message says 'ALTER PUBLICATION pub SET TABLES', but this dump code is using 'ALTER PUBLICATION pub ADD TABLES' (note ADD v SET). Something seems suspicious... ====== Kind Regards, Peter Smith. Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Wed, Apr 29, 2026 at 11:16 AM Peter Smith wrote:
>
> Hi Nisha.
>
> Some review comments for v4-0001 (docs only).
>
Thank you Peter for the review.
> ======
> doc/src/sgml/ref/create_publication.sgml
>
> 1.
> + TABLES IN SCHEMA { class="parameter">schema_name | CURRENT_SCHEMA } [
> EXCEPT ( class="parameter">except_table_object [, ... ] ) ] [,
> ... ]
>
> It is ambiguous which part does that last ellipsis applies to?
>
> Consider instead:
>
> TABLES IN SCHEMA tables_in_schema [, ... ]
>
> and tables_in_schema is:
> { schema_name | CURRENT_SCHEMA } [ EXCEPT ( except_table_object [, ... ] ) ]
>
> ~~~
Fixed.
>
> 2.
>
> This clause specifies a list of tables to be excluded from the
> - publication.
> + publication. It can be used with both FOR ALL TABLES
> + and FOR TABLES IN SCHEMA.
>
>
> Saying "both" may imply they can coexist, but they cannot.
>
> SUGGESTION
> It can be used with FOR ALL TABLES or FOR
> TABLES IN SCHEMA.
>
> ~~~
Fixed.
>
> 3.
> +
> + Create a publication that publishes all changes for all the tables
> present in
> + the schema sales, except
> + sales.internal and
> sales.drafts:
> +
> +CREATE PUBLICATION sales_filtered FOR TABLES IN SCHEMA sales EXCEPT
> (TABLE sales.internal, sales.drafts);
> +
> +
> +
>
> AFAIK, the tables in the EXCEPT clause do not need to be
> schema-qualified, so they should not be written that way in the
> programlisting part of this example, because it might give the user
> the impression that schema-qualified names are required.
>
Done, matched with nearby examples.
All of the above comments are addressed in v5-0001 patch.
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Wed, Apr 29, 2026 at 12:02 PM Peter Smith wrote: > > Hi Nisha. > > A couple of ad-hoc review comments for v4-0001... > > ====== > src/bin/pg_dump/pg_dump.c > > dumpPublicationNamespace: > > 1. > + if (!first_except) > + appendPQExpBufferStr(query, ")"); > > The logic seems ok, but the above seems a bit strange, checking > 'first_except'. Maybe renaming to 'has_except' (and some small > refactoring) would read better? > > ~~~ Thanks for pointing that out. This also needed updating after the syntax change to EXCEPT (TABLE ...). I’ve used the name "has_except", defaulting it to false for better readability. > > 2. > IIUC, the 'ALTER PUBLICATION' EXCEPT clause syntax change is not > introduced until your patch 0003. So, how does this dump code even > work when it relies on that ALTER PUBLICATION? > > Furthermore, the patch 0003 commit message says 'ALTER PUBLICATION pub > SET TABLES', but this dump code is using 'ALTER PUBLICATION pub ADD > TABLES' (note ADD v SET). Something seems suspicious... > I think there was a slight mix-up in reading the patch messages. The ALTER PUBLICATION ... EXCEPT syntax is introduced in patch-002 for ADD, not patch-003. That said, you’re right. The pg_dump part doesn’t work with patch-001 alone. I missed moving it to patch-002 while splitting the patches. Thanks for catching that; it’s now fixed. Also, patch-003 is for SET (not ADD) and includes handling for cleanup of EXCEPT entries when a schema is dropped. I’ve updated the patch message for clarity. Attached v5 patches with these updates. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Fri, May 15, 2026 at 12:49 PM Peter Smith wrote:
>
> Hi Nisha.
>
> Some review comments for patch v5-0001.
>
Thanks Peter, for the review.
> ======
> src/backend/catalog/pg_publication.c
>
> publication_add_relation:
>
> 2.
> + HeapTuple existing;
>
> Not sure if this is the best name. How about "tup"?
>
Noticed that a "HeapTuple tup;" is already declared, so we can use the
existing one.
> ~~~
>
> 3.
> + bool is_except = existing_form->prexcept;
>
> This variable is used only once. Not sure if that vindicates having it.
>
the is_except value is being used after releasing the tuple and
closing the table since the next step errors out. But I have now
removed existing_form and directly extracted the value instead.
> ~~~
>
> 8.
> + list_free(schemaRels);
> + }
> + else
> + result = list_concat(result, schemaRels);
>
> Why is 'schemaRels' only being freed when there is an EXCEPT?
>
IIUC, In the EXCEPT case, relid is an Oid, so lfirst_oid() copies the
integer value from the cell, and lappend_oid() stores that value into
a new cell in result. That means result does not reference schemaRels
cells after the loop, so list_free(schemaRels) is safe.
In the else branch, list_concat() directly transfers schemaRels cells
into result. So freeing schemaRels there would corrupt the result.
> ======
> src/backend/parser/gram.y
>
> 14.
> - | ColId opt_column_list OptWhereClause
> + | ColId opt_column_list OptWhereClause opt_pub_except_clause
> {
> $$ = makeNode(PublicationObjSpec);
> $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
> + $$->except_tables = $4;
>
> This seems suspicious. You cannot have an EXCEPT clause when there is
> a column list or a WHERE clause, so what is this scenario? Maybe the
> "$$->except_tables = $4;" needs to be moved to the 'else' block?
>
This handles cases where multi-schema continuation is used along with
an EXCEPT clause, e.g.:
create publication pub1 for tables in schema public, s1 except (table t1);
-- without the above, the EXCEPT clause would be silently ignored.
Now, I agree that the above case can also be handled by moving
"$$->except_tables = $4;" into the else branch. But then EXCEPT would
again get silently ignored for table continuations with a column-list
or where clause, e.g.,:
postgres=# create publication pub2 for table t1, t2 (c1) except (table t1);
CREATE PUBLICATION
The idea here is to collect the EXCEPT list whenever it is specified
for such continuation cases, and then explicitly raise an error in
preprocess_pubobj_list() if a table publication object contains an
EXCEPT list.
> ~~~
>
> 16.
> + if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA)
> + {
> + if (eobj->pubtable->relation->schemaname == NULL)
> + eobj->pubtable->relation->schemaname = pubobj->name;
> + else if (strcmp(eobj->pubtable->relation->schemaname,
> + pubobj->name) != 0)
> + ereport(ERROR,
> + errcode(ERRCODE_SYNTAX_ERROR),
> + errmsg("table \"%s.%s\" in EXCEPT clause does not belong to schema \"%s\"",
> + eobj->pubtable->relation->schemaname,
> + eobj->pubtable->relation->relname,
> + pubobj->name),
> + parser_errposition(eobj->location));
>
> 16a.
> Introducing some more variables (like 'eobj_schemaname' and
> 'eobj_relname') would simplify this code quite a bit.
>
Done.
> ~
>
> 16b.
> Should make use of the recently committed function that gets
> fully-qualified rel names so you can use "%s" instead of "%s.%s".
>
We cannot use RelationGetQualifiedRelationName() in the grammar, so I
used quote_qualified_identifier() instead.
~~~~
Addressed all other comments as suggested. Please find the updated v6
patches attached.
Patch-0001: updated as per the above comments.
Patch-0002 and Patch-0003: adjusted for the Patch-0001 changes and
some code simplification in tab-complete part.
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Hi Nisha.
Here are some review comments for patch v6-0001.
======
src/backend/catalog/pg_publication.c
GetTopMostAncestorInPublication:
1.
+GetTopMostAncestorInPublication(Oid puboid, List *ancestors,
+ int *ancestor_level, List *except_pubids)
I am having dificulty understanding this function. There needs to be a
description what does the input parameter 'except_pubids' mean. The
param name doesn't tell me anything much -- just that it is a list of
pubids that "something" (what?) is excluded from. And how does that
relate to the 'ancestors'?
~~~
2.
{
aschemaPubids = GetSchemaPublications(get_rel_namespace(ancestor));
- if (list_member_oid(aschemaPubids, puboid))
+ if (list_member_oid(aschemaPubids, puboid) &&
+ !list_member_oid(except_pubids, puboid))
Is this new code in the right place? I'm not 100% sure of the
'except_pubids' details, but shouldn't it be checked sooner? e.g. if
we know already that this pubid is no good
(!list_member_oid(except_pubids, puboid)) then what is the point to
even assign/check aschemaPubids?
~~~
3.
+ if (is_except)
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("table \"%s\" cannot be added because it is excluded from
publication \"%s\"",
+ RelationGetQualifiedRelationName(targetrel),
+ pub->name)));
+ else
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("relation \"%s\" is already member of publication \"%s\"",
+ RelationGetRelationName(targetrel), pub->name)));
Fully qualified 'targetrel' in the first error, but not in the second? Is it OK?
~~~
GetAllSchemaPublicationRelations:
4.
+ List *exceptlist = NIL;
The varname is a bit vague; it is a list of "what"? Maybe say
'except_relids' or similar.
======
src/backend/replication/pgoutput/pgoutput.c
get_rel_sync_entry:
5.
+ /*
+ * For the schema EXCEPT check, we must look up the top-most ancestor
+ * rather than the relation itself. check_publication_add_relation()
+ * prevents individual partitions from appearing in the EXCEPT clause,
+ * so only a root (non-partition) table can have prexcept = true.
+ * Using the partition's own OID would always return NIL and miss the
+ * exclusion.
+ */
+ Oid root_relid = am_partition ?
+ llast_oid(get_partition_ancestors(relid)) : relid;
+
+ schemaExceptPubids = GetRelationExcludedPublications(root_relid);
5a.
The varname 'schemaExceptPubids' seems ambiguous. It sounds like it is
pubids that have EXCEPT SCHEMA. In the future the ALL TABLES may
introduce "EXCEPT SCHEMA", but currently there is no such thing.
Meanwhile, here I think it means "EXCEPT TABLE", so IMO that varname
needs to indicate the meaning better.
~
5b.
Actually, this is becoming a GENERAL comment. There too many ways that
these EXCEPT tables are getting named, and it is causing confusion:
- except_pubids
- exceptlist
- exceptrelations
- exceptrels
- except_relid
- except_tables
- schemaExceptPubids
Can we standardize on some common names, to make all the code more consistent?
~
5c.
Previously, the result of 'get_partition_ancestors' was being freed,
but now it is not. I'm not sure how importatnt that is, because I
found other examples in PG source code also not freeing...
======
src/bin/psql/tab-complete.in.c
6.
+ else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR", "TABLES",
"IN", "SCHEMA", MatchAny, "EXCEPT", "(", "TABLE", MatchAnyN) &&
ends_with(prev_wd, ','))
+ COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
I'm not sure if this is working as intended.
When testing for multiple except tables I get results like:
----
test_pub=# create publication pub1 for tables IN SCHEMA myschema
EXCEPT ( TABLE WITH (
test_pub=# create publication pub1 for tables IN SCHEMA myschema
except ( table
test_pub=# create publication pub1 for tables IN SCHEMA myschema
except ( table myschema.t
myschema.t1 myschema.t2 myschema.t3
test_pub=# create publication pub1 for tables IN SCHEMA myschema
except ( table myschema.t1,
information_schema. myschema. public. t1
t2 t3
----
Note: it is offering suggstions for schema names outside of the
"myschema". Should this code be calling
Query_for_list_of_tables_in_schema instead of
Query_for_list_of_tables?
======
src/test/regress/sql/publication.sql
7.
---- Tests for publications with SEQUENCES
+---------------------------------------------
+-- EXCEPT tests for TABLES IN SCHEMA
+---------------------------------------------
+SET client_min_messages = 'ERROR';
It looks like a previous comment for the SEQUENCES tests has been
accidentally removed.
I should be put back, and made more prominent like the other big comments.
e.g.
---------------------------------------------
-- Tests for publications with SEQUENCES
---------------------------------------------
~~~
8.
+RESET client_min_messages;
+DROP TABLE pub_test.testpub_tbl_s1, pub_test.testpub_tbl_s2;
+DROP TABLE pub_test.testpub_parted_s CASCADE;
+DROP TABLE testpub_nopk, testpub_tbl_s1;
+DROP PUBLICATION testpub_schema_except1, testpub_schema_except2,
testpub_schema_except_multi;
+
Add a "Cleanup" comment.
======
Kind Regards,
Peter Smith.
Fujitsu Australia.
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Fri, May 22, 2026 at 7:57 AM Peter Smith wrote:
>
> Hi Nisha.
>
> Here are some review comments for patch v6-0001.
>
Thanks for the review. All comments are addressed in v7. Please find
responses below for a few of the comments.
> ======
> src/backend/catalog/pg_publication.c
>
> GetTopMostAncestorInPublication:
>
> 1.
> +GetTopMostAncestorInPublication(Oid puboid, List *ancestors,
> + int *ancestor_level, List *except_pubids)
>
> I am having dificulty understanding this function. There needs to be a
> description what does the input parameter 'except_pubids' mean. The
> param name doesn't tell me anything much -- just that it is a list of
> pubids that "something" (what?) is excluded from. And how does that
> relate to the 'ancestors'?
>
Updated the function comments to explain except_pubids.
> ~~~
>
> 2.
> {
> aschemaPubids = GetSchemaPublications(get_rel_namespace(ancestor));
> - if (list_member_oid(aschemaPubids, puboid))
> + if (list_member_oid(aschemaPubids, puboid) &&
> + !list_member_oid(except_pubids, puboid))
>
> Is this new code in the right place? I'm not 100% sure of the
> 'except_pubids' details, but shouldn't it be checked sooner? e.g. if
> we know already that this pubid is no good
> (!list_member_oid(except_pubids, puboid)) then what is the point to
> even assign/check aschemaPubids?
>
except_pubids represents the set of publication OIDs from which the
root relation has been explicitly excluded via EXCEPT (TABLE ...).
But yes, we can check it before computing schemaPubids. Fixed.
> ~~~
>
> 3.
> + if (is_except)
> + ereport(ERROR,
> + (errcode(ERRCODE_DUPLICATE_OBJECT),
> + errmsg("table \"%s\" cannot be added because it is excluded from
> publication \"%s\"",
> + RelationGetQualifiedRelationName(targetrel),
> + pub->name)));
> + else
> + ereport(ERROR,
> + (errcode(ERRCODE_DUPLICATE_OBJECT),
> + errmsg("relation \"%s\" is already member of publication \"%s\"",
> + RelationGetRelationName(targetrel), pub->name)));
>
> Fully qualified 'targetrel' in the first error, but not in the second? Is it OK?
>
IMO, we should use fully qualified names in both cases. Though the
second error is not part of this patch, I’ve updated it as well.
Please let me know if you think otherwise.
> ======
> src/backend/replication/pgoutput/pgoutput.c
>
> get_rel_sync_entry:
>
...
>
> 5b.
> Actually, this is becoming a GENERAL comment. There too many ways that
> these EXCEPT tables are getting named, and it is causing confusion:
> - except_pubids
> - exceptlist
> - exceptrelations
> - exceptrels
> - except_relid
> - except_tables
> - schemaExceptPubids
>
> Can we standardize on some common names, to make all the code more consistent?
>
I have now used the "except_" prefix consistently for all names to
avoid confusion. Also updated the naming in all places as below:
except_rel_names: parse-level table names in EXCEPT
except_rels: internal relations in the EXCEPT list (opened/accessed)
except_relids: list of relation OIDs wherever used
except_pubids: publication OIDs from which a given relation (or its
root) is excluded
> ~
>
> 5c.
> Previously, the result of 'get_partition_ancestors' was being freed,
> but now it is not. I'm not sure how importatnt that is, because I
> found other examples in PG source code also not freeing...
>
Sorry, this was mistakenly removed in v6 while cleaning up the code,
and I did not verify it against the older version. Fixed now.
> ======
> src/bin/psql/tab-complete.in.c
>
> 6.
> + else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR", "TABLES",
> "IN", "SCHEMA", MatchAny, "EXCEPT", "(", "TABLE", MatchAnyN) &&
> ends_with(prev_wd, ','))
> + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
>
> I'm not sure if this is working as intended.
>
> When testing for multiple except tables I get results like:
> ----
> test_pub=# create publication pub1 for tables IN SCHEMA myschema
> EXCEPT ( TABLE WITH (
> test_pub=# create publication pub1 for tables IN SCHEMA myschema
> except ( table
> test_pub=# create publication pub1 for tables IN SCHEMA myschema
> except ( table myschema.t
> myschema.t1 myschema.t2 myschema.t3
> test_pub=# create publication pub1 for tables IN SCHEMA myschema
> except ( table myschema.t1,
> information_schema. myschema. public. t1
> t2 t3
> ----
>
> Note: it is offering suggstions for schema names outside of the
> "myschema". Should this code be calling
> Query_for_list_of_tables_in_schema instead of
> Query_for_list_of_tables?
>
For this case, I don't think it's really possible to keep suggesting
after a comma. Even if we handle a fixed number of comma-separated
entries, the same problem reappears with the next entry.
Query_for_list_of_tables_in_schema needs a correct schema reference,
but with each comma the relative offset changes, so there is no single
fixed prev*_wd that can reliably point to the schema across all
entries.
But I see, the current call to Query_for_list_of_tables is clearly
incorrect here. I have now suppressed suggestions after a comma,
instead of showing incorrect suggestions.
Thoughts?
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Fri, May 22, 2026 at 11:00 AM Peter Smith wrote: > > Hi Nisha. > > Here are some review comments for patch v6-0002. > Thanks for the review. All comments are addressed in v7. Please find responses below for a few of the comments. > > EXCEPT > > 5. > + > + EXCEPT ( class="parameter">except_table_object [, ... ] > ) > + > + > + Specifies tables to be excluded from a schema-level publication entry. > + This clause may be used with ADD TABLES IN SCHEMA > + and not with DROP TABLES IN SCHEMA. Each named > + table must belong to the schema specified in the same > + TABLES IN SCHEMA clause. Table names may be > + schema-qualified or unqualified; unqualified names are implicitly > + qualified with the schema named in the same clause. See > + for further details on the > + semantics of EXCEPT. > + > + > + > + > > 5a. > Oh! If this EXCEPT part was previously missing even for the "FOR ALL > TABLES", then IMO that is a separate bug that should be in another > thread and patched/fixed asap, then your patch should just make small > changes to to it. > Agree. I'll make a separate patch for it and start a thread. > ====== > src/backend/commands/publicationcmds.c > > AlterPublicationSchemas: > > 7. > + /* > + * Increment the command counter so that is_schema_publication() in > + * GetExcludedPublicationTables() can see the just-inserted schema > + * rows when AlterPublicationExceptTables runs next. > + */ > + CommandCounterIncrement(); > > Should this cut/paste common code be done afterwards just if > stmt->action == AP_AddObjects/SetObjects ? > Agree, fixed. > ~~~ > > AlterPublicationExceptTables: > > 8. > + /* > + * This function handles EXCEPT entries for schema-level publications > + * only. For FOR ALL TABLES publications, EXCEPT entries are already > + * processed by AlterPublicationTables(). > + */ > + if (schemaidlist == NIL && !is_schema_publication(pubid)) > + return; > > Huh? It seems contrary to the function comment that was also talking > about "FOR ALL TABLES". > Corrected the function comments. It is for only schema publications. > Should this function really be called something different like > 'AlterPublicationSchemaExceptTables'? > Done. Renamed as suggested. > ~~~ > > 12. > + /* > + * For FOR ALL TABLES, EXCEPT entries are processed by > + * AlterPublicationTables(), so merge them in. For TABLES IN SCHEMA, > + * they are handled separately by AlterPublicationExceptTables(). > + */ > + if (stmt->for_all_tables) > + relations = list_concat(relations, exceptrelations); > AlterPublicationTables(stmt, tup, relations, pstate->p_sourcetext, > schemaidlist != NIL); > AlterPublicationSchemas(stmt, tup, schemaidlist); > + AlterPublicationExceptTables(stmt, tup, exceptrelations, schemaidlist); > > Would it be simpler if AlterPublicationExceptTables was merged (or > delegated from) the AlterPublicationSchemas? > +1, fixed. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Tue, May 26, 2026 at 11:27 AM Peter Smith wrote: > > Hi Nisha. > > Some review comments for patch v6-0003. > Thanks for the review. All comments are addressed in v7. Please find responses below for a few of the comments. > > 3. > The EXCEPT clause can be used with > - ADD TABLES IN SCHEMA to exclude specific tables from a > + ADD TABLES IN SCHEMA and > + SET TABLES IN SCHEMA to exclude specific tables from a > schema-level publication. EXCEPT is not supported with > DROP TABLES IN SCHEMA; instead, dropping a schema from > the publication automatically removes all of its associated > > 3a. > This whole description section seems arranged in a confusing way IMO. > Anyway, it is not all the fault of the current patch. But I don't > think it should be talking about "SET TABLES IN SCHEMA" here because > that was all mentioned already in the earlier "third variant" > paragraph. > Right. it seems repeating. Removed "SET TABLES IN SCHEMA" related info. > ~ > > 3b. > That last sentence all about EXCEPT with DROP TABLES IN SCHEMA seems > redundant to me. It is not allowed by the synopsis, so there is no > possible confusion about it being supported. Isn't it better to just > say nothing? > Okay, that makes sense. Fixed. > ~~~ > > 4b. > This description about EXCEPT is missing talking about FOR ALL TABLES > EXCEPT, but IIRC I already reported that in a previous review. > Yes, we can handle this in a separate patch. > ~~~ > > PublicationDropSchemas: > > 12. > + /* > + * Collect prexcept rows for tables belonging to this schema before > + * removing the schema entry. GetExcludedPublicationTables relies on > + * is_schema_publication(), which scans pg_publication_namespace; if > + * this is the last schema in the publication, performDeletion() below > + * would remove that row and make is_schema_publication() return > + * false, tripping the assertion. > + */ > > What assertion? > The assertion is Assert(GetPublication(pubid)->alltables || is_schema_publication(pubid)) in GetExcludedPublicationTables(). I’ve trimmed the comment a bit, as it felt slightly over-explained. ~~~~ Please find the updated patch-set v7 attached. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Hi Nisha.
Some review comments for patch v7-0001.
======
src/backend/catalog/pg_publication.c
GetTopMostAncestorInPublication:
1.
- else
+ else if (!list_member_oid(except_pubids, puboid))
{
aschemaPubids = GetSchemaPublications(get_rel_namespace(ancestor));
IIUC this `except_pubids` and `puboid` are not changing, so you do not
need to be doing this member check every loop iteration. Is it better
to assign some variable up-front?
e.g.
bool check_schemas = !list_member_oid(except_pubids, puboid);
~~~
publication_add_relation:
2.
+ if (is_except)
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("relation \"%s\" cannot be added because it is excluded from
publication \"%s\"",
+ RelationGetQualifiedRelationName(targetrel),
+ pub->name)));
I am unsure about the changed wording from "table" to "relation". IIUC
we say "relation" when it could be either a table or a sequence. So
maybe "table" is correct for your patch;l OTHOH this should change to
"relation" by Shlok's EXCEPT SEQUENCE patch [1].
~~~
3.
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("relation \"%s\" is already member of publication \"%s\"",
+ RelationGetQualifiedRelationName(targetrel), pub->name)));
IMO making everything fully qualified like this would be a good
change, but doing it here perhaps does not belong in your patch. I
have resurrected this question in the other thread [2], which would
affect not only this statement. but many others. Please post your
opinion about this on that other thread.
======
src/backend/commands/publicationcmds.c
ObjectsInPublicationToOids:
4.
static void
ObjectsInPublicationToOids(List *pubobjspec_list, ParseState *pstate,
- List **rels, List **exceptrels, List **schemas)
+ List **rels, List **except_rel_names, List **schemas)
Is `except_rel_names` an accurate name? IMO it makes it sound like
it's a list of char* names, but IIUC that is not the case; aren't
these PublicationTable objects? Would something like
`except_pubtables` be more correct?
~~~
CreatePublication:
5.
- List *exceptrelations = NIL;
+ List *except_rel_names = NIL;
Same doubts about this `except_rel_names` variable name.
~~~
AlterPublication:
6.
List *relations = NIL;
- List *exceptrelations = NIL;
+ List *except_rel_names = NIL;
Same doubts about this `except_rel_names` variable name.
======
src/backend/replication/pgoutput/pgoutput.c
get_rel_sync_entry:
7.
+ if (am_partition)
+ {
+ List *part_ancestors = get_partition_ancestors(relid);
+
+ root_relid = llast_oid(part_ancestors);
+ list_free(part_ancestors);
I think just call this `ancestors` (not `part_ancestors`) for
consistency with other code in the same function.
======
src/bin/psql/tab-complete.in.c
On Thu, May 28, 2026 at 9:27 PM Nisha Moond wrote:
>
> On Fri, May 22, 2026 at 7:57 AM Peter Smith wrote:
...
> > 6.
> > + else if (Matches("CREATE", "PUBLICATION", MatchAny, "FOR", "TABLES",
> > "IN", "SCHEMA", MatchAny, "EXCEPT", "(", "TABLE", MatchAnyN) &&
> > ends_with(prev_wd, ','))
> > + COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tables);
> >
> > I'm not sure if this is working as intended.
> >
> > When testing for multiple except tables I get results like:
> > ----
> > test_pub=# create publication pub1 for tables IN SCHEMA myschema
> > EXCEPT ( TABLE WITH (
> > test_pub=# create publication pub1 for tables IN SCHEMA myschema
> > except ( table
> > test_pub=# create publication pub1 for tables IN SCHEMA myschema
> > except ( table myschema.t
> > myschema.t1 myschema.t2 myschema.t3
> > test_pub=# create publication pub1 for tables IN SCHEMA myschema
> > except ( table myschema.t1,
> > information_schema. myschema. public. t1
> > t2 t3
> > ----
> >
> > Note: it is offering suggstions for schema names outside of the
> > "myschema". Should this code be calling
> > Query_for_list_of_tables_in_schema instead of
> > Query_for_list_of_tables?
> >
>
> For this case, I don't think it's really possible to keep suggesting
> after a comma. Even if we handle a fixed number of comma-separated
> entries, the same problem reappears with the next entry.
> Query_for_list_of_tables_in_schema needs a correct schema reference,
> but with each comma the relative offset changes, so there is no single
> fixed prev*_wd that can reliably point to the schema across all
> entries.
>
> But I see, the current call to Query_for_list_of_tables is clearly
> incorrect here. I have now suppressed suggestions after a comma,
> instead of showing incorrect suggestions.
> Thoughts?
>
8.
REPLY: Yeah, I don't have any good ideas how to fix this, or if a fix
is even possible, but I agree that doing nothing is better than doing
the wrong thing.
~~~
9.
BTW, the current code is not able to handle multiple schemas.
So, this works:
test_pub=# CREATE PUBLICATION pub1 for TABLES IN SCHEMA myschema
EXCEPT ( TABLE WITH (
but, this doesn't do anything:
test_pub=# CREATE PUBLICATION pub1 for TABLES IN SCHEMA public, myschema
======
[1] Shlok EXCEPT -
https://www.postgresql.org/message-id/flat/CAHut%2BPsUrYmbZ996ZybjMWvpW_ufXB8WM94pdvAPyzQpoe%2BHRA%40mail.gmail.com#579d9b99c4f620602085cc59ff0e2b7d
[2] schema-qualified messages -
https://www.postgresql.org/message-id/CAHut%2BPvWoOyLKFb627Ch%2BXg3TYHuHdaOZ_XmxYgKVYdOzpqFsw%40mail.gmail.com
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Hi Nisha.
Some review comments for patch v7-0002.
======
src/backend/commands/publicationcmds.c
1.
+static void AlterPublicationSchemas(AlterPublicationStmt *stmt,
+ HeapTuple tup, List *schemaidlist,
+ List *except_rel_names);
+static void AlterPublicationSchemaExceptTables(AlterPublicationStmt *stmt,
+ HeapTuple tup,
+ List *except_rel_names,
+ List *schemaidlist);
Maybe the same doubts about the `except_rel_names` parameter/variable
are continued into this patch. See patch 0001 where I first queried
this.
======
src/bin/pg_dump/t/002_pg_dump.pl
2.
+ 'CREATE PUBLICATION pub12' => {
+ create_order => 50,
+ create_sql =>
+ 'CREATE PUBLICATION pub12 FOR TABLES IN SCHEMA dump_test EXCEPT
(TABLE test_table, dump_test.test_second_table);',
+ regexp => qr/^
+ \QCREATE PUBLICATION pub12 WITH (publish = 'insert, update, delete,
truncate');\E
+ /xm,
+ like => { %full_runs, section_post_data => 1, },
+ },
+
+ 'ALTER PUBLICATION pub12 ADD TABLES IN SCHEMA dump_test EXCEPT
(TABLE test_table, dump_test.test_second_table)'
+ => {
+ regexp => qr/^
+ \QALTER PUBLICATION pub12 ADD TABLES IN SCHEMA dump_test EXCEPT
(TABLE ONLY test_table, TABLE ONLY test_second_table);\E
+ /xm,
+ like => { %full_runs, section_post_data => 1, },
+ },
I found those hard to read at first. How about just changing the test
title of the ALTER parts
BEFORE
+ 'ALTER PUBLICATION pub12 ADD TABLES IN SCHEMA dump_test EXCEPT
(TABLE test_table, dump_test.test_second_table)'
SUGGESTION
+ 'CREATE PUBLICATION pub12 test continues ...'
(2 places like this)
======
src/test/regress/expected/publication.out
3.
+-- DROP TABLES IN SCHEMA also removes associated EXCEPT entries
+ALTER PUBLICATION testpub_alter_except DROP TABLES IN SCHEMA pub_test;
+\dRp+ testpub_alter_except
+ Publication
testpub_alter_except
+ Owner | All tables | All sequences | Inserts |
Updates | Deletes | Truncates | Generated columns | Via root |
Description
+--------------------------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+-------------
+ regress_publication_user | f | f | t | t
| t | t | none | f |
+Except tables:
+ "pub_test.testpub_tbl_s1"
+
Isn't this showing a BUG, because after the DROP the "Except tables"
are still listed.
~~~
4.
+-- ADD: unqualified name is implicitly qualified with the schema, not public
+ALTER PUBLICATION testpub_alter_except ADD TABLES IN SCHEMA pub_test
EXCEPT (TABLE testpub_tbl_s2);
+\dRp+ testpub_alter_except
+ Publication
testpub_alter_except
+ Owner | All tables | All sequences | Inserts |
Updates | Deletes | Truncates | Generated columns | Via root |
Description
+--------------------------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+-------------
+ regress_publication_user | f | f | t | t
| t | t | none | f |
+Tables from schemas:
+ "pub_test"
+Except tables:
+ "pub_test.testpub_tbl_s1"
+ "pub_test.testpub_tbl_s2"
+
Isn't this showing the same BUG as the previous test, because "s1" is
still in the "Except tables" list, even though it was not part of the
EXCEPT.
~~~
5.
+-- ADD: multiple excepted tables using unqualified names
+ALTER PUBLICATION testpub_alter_except DROP TABLES IN SCHEMA pub_test;
+ALTER PUBLICATION testpub_alter_except ADD TABLES IN SCHEMA pub_test
EXCEPT (TABLE testpub_tbl_s1, testpub_tbl_s2);
+ERROR: relation "pub_test.testpub_tbl_s1" cannot be added because it
is excluded from publication "testpub_alter_except"
Isn't this showing the same BUG again, because "s1" was already in the
EXCEPT list when it should not be.
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Hi Nisha.
Review comments for v8-0001 and v8-0002.
======
git apply gives warnings.
1.
git apply ../patches_misc/v8-0001-Support-EXCEPT-clause-for-schema-level-publicatio.patch
../patches_misc/v8-0001-Support-EXCEPT-clause-for-schema-level-publicatio.patch:176:
space before tab in indent.
errmsg("relation \"%s\" is
already member of publication \"%s\"",
warning: 1 line adds whitespace errors.
======
src/bin/psql/tab-complete.in.c
On Sat, May 30, 2026 at 2:32 PM Nisha Moond wrote:
>
...
> > 9.
> > BTW, the current code is not able to handle multiple schemas.
> >
> > So, this works:
> > test_pub=# CREATE PUBLICATION pub1 for TABLES IN SCHEMA myschema
> > EXCEPT ( TABLE WITH (
> >
> > but, this doesn't do anything:
> > test_pub=# CREATE PUBLICATION pub1 for TABLES IN SCHEMA public, myschema
> >
>
> I think the above preserves the existing behavior. Currently, we do
> not suggest "WITH (" after the second schema onwards. To support this
> properly, we would also need to handle "WITH (" suggestions for
> subsequent schema entries.
>
> I’ve created a top-up patch (patch-002) for this. I can merge it if we
> want to change the current behavior. Let me know your thoughts.
2.
Some scenarios are improved, but others do not work (either newly
broken or maybe they have been?).
TBH, I am unsure if the added complexity of patch 0002 was worth it. I
am going to pass on this for now and wait for other opinions.
e.g.
Good: (suggests schemas to use)
test_pub=# CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA
CURRENT_SCHEMA information_schema myschema public
Bad: (does not suggest more schema to use)
test_pub=# CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA public,
Good: (completes names of known schema)
test_pub=# CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA my
becomes
test_pub=# CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA myschema
Bad: (does not complete names of known schema)
test_pub=# CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA public, my
Good: (suggest EXCEPT with single schema)
test_pub=# CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA myschema
EXCEPT ( TABLE WITH (
Good: (suggest EXCEPT with multi schema)
test_pub=# CREATE PUBLICATION pub1 for TABLES IN SCHEMA public, myschema
EXCEPT ( TABLE WITH (
Bad: (doesn't work if the FOR TABLE precedes TABLES IN SCHEMA)
test_pub=# CREATE PUBLICATION pub1 FOR TABLE mytab, TABLES IN
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Hi Nisha.
Some review comments for patch v8-0003.
======
src/backend/commands/publicationcmds.c
AlterPublicationSchemaExceptTables:
1.
+ /*
+ * EXCEPT is not meaningful with DROP: dropping a schema from a
+ * publication already removes all its except entries via cascade, and
+ * there is no sensible interpretation of "drop only the except entry but
+ * keep the schema".
+ */
Is that backwards? I think you mean :
SUGGESTION
* Dropping a schema from a publication removes all its EXCEPT entries via
* cascade. The concept of "drop all schema tables from the publication EXCEPT
* these ones" is not supported.
======
src/bin/pg_dump/t/002_pg_dump.pl
2.
On Sat, May 30, 2026 at 2:32 PM Nisha Moond wrote:
...
> I don't see any existing "..test continues..." pattern, so I changed it as -
> 'CREATE PUBLICATION pub11 - ADD TABLES IN SCHEMA EXCEPT dump'
>
> Thoughts?
I've since found that there is a way to combine multiple regex within
a single test. Doing it like below is a cleaner way to write these
multi-statement tests.
SUGGESTION (note /xms instead of /xm)
'CREATE PUBLICATION pub11' => {
create_order => 50,
create_sql =>
'CREATE PUBLICATION pub11 FOR TABLES IN SCHEMA dump_test
EXCEPT (TABLE test_table);',
regexp => qr/^
\QCREATE PUBLICATION pub11 WITH (publish = 'insert,
update, delete, truncate');\E
.*?
\QALTER PUBLICATION pub11 ADD TABLES IN SCHEMA dump_test
EXCEPT (TABLE ONLY test_table);\E
/xms,
like => { %full_runs, section_post_data => 1, },
},
(ditto for the pub12 test)
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Hi Nisha.
Some review comments for patch v8-0004.
======
src/backend/commands/publicationcmds.c
AlterPublicationSchemaExceptTables:
1.
+ /* Collect OIDs of the desired new EXCEPT list. */
+ foreach_ptr(PublicationRelInfo, pri, rels)
+ {
+ newexceptrelids = lappend_oid(newexceptrelids,
+ RelationGetRelid(pri->relation));
+ }
Block braces {} not needed.
~~~
2.
+ if (!OidIsValid(proid))
+ continue; /* already gone */
+
+ ObjectAddressSet(obj, PublicationRelRelationId, proid);
+ performDeletion(&obj, DROP_CASCADE, 0);
SUGGESTION
if (OidIsValid(proid))
{
ObjectAddressSet(obj, PublicationRelRelationId, proid);
performDeletion(&obj, DROP_CASCADE, 0);
}
======
src/test/subscription/t/037_except.pl
3.
I think you had used the SQL exactly as I previously suggested, but I
made a mistake:
It should say "SELECT count(*)" instead of "SELECT a".
So it returns either 0 or 1 row.
e.g. #1
$result =
$node_subscriber->safe_psql('postgres',
"SELECT count(*) FROM sch1.tab_excluded WHERE a = 7");
is($result, qq(1),
'ALTER ... SET TABLES IN SCHEMA EXCEPT: newly included table is replicated'
);
$result =
$node_subscriber->safe_psql('postgres',
"SELECT count(*) FROM sch1.tab_published WHERE a = 7");
is($result, qq(0),
'ALTER ... SET TABLES IN SCHEMA EXCEPT: now-excluded table is not
replicated'
);
e.g. #2
$result =
$node_subscriber->safe_psql('postgres',
"SELECT count(*) FROM sch1.tab_published WHERE a = 8");
is($result, qq(1),
'ALTER ... SET TABLES IN SCHEMA (no EXCEPT): tab_published
replicated after except list cleared'
);
$result =
$node_subscriber->safe_psql('postgres',
"SELECT count(*) FROM sch1.tab_excluded WHERE a = 8");
is($result, qq(1),
'ALTER ... SET TABLES IN SCHEMA (no EXCEPT): tab_excluded
replicated after except list cleared'
);
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Mon, Jun 1, 2026 at 12:54 PM Peter Smith wrote:
>
> Hi Nisha.
>
> Review comments for v8-0001 and v8-0002.
>
Thanks for the review.
> ======
> git apply gives warnings.
>
> 1.
> git apply ../patches_misc/v8-0001-Support-EXCEPT-clause-for-schema-level-publicatio.patch
> ../patches_misc/v8-0001-Support-EXCEPT-clause-for-schema-level-publicatio.patch:176:
> space before tab in indent.
> errmsg("relation \"%s\" is
> already member of publication \"%s\"",
> warning: 1 line adds whitespace errors.
>
> ======
> src/bin/psql/tab-complete.in.c
>
> On Sat, May 30, 2026 at 2:32 PM Nisha Moond wrote:
> >
> ...
> > > 9.
> > > BTW, the current code is not able to handle multiple schemas.
> > >
> > > So, this works:
> > > test_pub=# CREATE PUBLICATION pub1 for TABLES IN SCHEMA myschema
> > > EXCEPT ( TABLE WITH (
> > >
> > > but, this doesn't do anything:
> > > test_pub=# CREATE PUBLICATION pub1 for TABLES IN SCHEMA public, myschema
> > >
> >
> > I think the above preserves the existing behavior. Currently, we do
> > not suggest "WITH (" after the second schema onwards. To support this
> > properly, we would also need to handle "WITH (" suggestions for
> > subsequent schema entries.
> >
> > I’ve created a top-up patch (patch-002) for this. I can merge it if we
> > want to change the current behavior. Let me know your thoughts.
>
> 2.
> Some scenarios are improved, but others do not work (either newly
> broken or maybe they have been?).
>
I tested these scenarios on HEAD (without this patch), and most of
them already exist today. (See inline below).
> TBH, I am unsure if the added complexity of patch 0002 was worth it. I
> am going to pass on this for now and wait for other opinions.
>
> e.g.
>
> Good: (suggests schemas to use)
> test_pub=# CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA
> CURRENT_SCHEMA information_schema myschema public
>
Not introduced by this patch; it is existing behavior.
> Bad: (does not suggest more schema to use)
> test_pub=# CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA public,
>
Not introduced by this patch; it is existing behavior.
> Good: (completes names of known schema)
> test_pub=# CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA my
> becomes
> test_pub=# CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA myschema
>
Not introduced by this patch; it is existing behavior.
> Bad: (does not complete names of known schema)
> test_pub=# CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA public, my
>
Not introduced by this patch; it is existing behavior.
> Good: (suggest EXCEPT with single schema)
> test_pub=# CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA myschema
> EXCEPT ( TABLE WITH (
>
This behavior is introduced by v8-0001.
> Good: (suggest EXCEPT with multi schema)
> test_pub=# CREATE PUBLICATION pub1 for TABLES IN SCHEMA public, myschema
> EXCEPT ( TABLE WITH (
>
This behavior is introduced by v8-0002.
> Bad: (doesn't work if the FOR TABLE precedes TABLES IN SCHEMA)
> test_pub=# CREATE PUBLICATION pub1 FOR TABLE mytab, TABLES IN
Not introduced by this patch; it is existing behavior.
~~~
All of the above behavior is consistent with HEAD. Only the "EXCEPT
(TABLE" suggestions are introduced by patches 0001 and 0002.
I'm also not sure the added complexity is justified just for the
"EXCEPT (TABLE" suggestion, especially since suggestions after commas
are generally not supported in most existing cases.
I'll drop patch-0002 for now and we can revisit it later if others
have opinions on it.
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Mon, Jun 1, 2026 at 12:56 PM Peter Smith wrote:
>
> Hi Nisha.
>
> Some review comments for patch v8-0003.
>
Thanks for the
> ======
> src/backend/commands/publicationcmds.c
>
> AlterPublicationSchemaExceptTables:
>
> 1.
> + /*
> + * EXCEPT is not meaningful with DROP: dropping a schema from a
> + * publication already removes all its except entries via cascade, and
> + * there is no sensible interpretation of "drop only the except entry but
> + * keep the schema".
> + */
>
> Is that backwards? I think you mean :
>
> SUGGESTION
> * Dropping a schema from a publication removes all its EXCEPT entries via
> * cascade. The concept of "drop all schema tables from the publication EXCEPT
> * these ones" is not supported.
Fixed as suggested in v9.
> ======
> src/bin/pg_dump/t/002_pg_dump.pl
>
> 2.
> On Sat, May 30, 2026 at 2:32 PM Nisha Moond wrote:
> ...
> > I don't see any existing "..test continues..." pattern, so I changed it as -
> > 'CREATE PUBLICATION pub11 - ADD TABLES IN SCHEMA EXCEPT dump'
> >
> > Thoughts?
>
> I've since found that there is a way to combine multiple regex within
> a single test. Doing it like below is a cleaner way to write these
> multi-statement tests.
>
> SUGGESTION (note /xms instead of /xm)
> 'CREATE PUBLICATION pub11' => {
> create_order => 50,
> create_sql =>
> 'CREATE PUBLICATION pub11 FOR TABLES IN SCHEMA dump_test
> EXCEPT (TABLE test_table);',
> regexp => qr/^
> \QCREATE PUBLICATION pub11 WITH (publish = 'insert,
> update, delete, truncate');\E
> .*?
> \QALTER PUBLICATION pub11 ADD TABLES IN SCHEMA dump_test
> EXCEPT (TABLE ONLY test_table);\E
> /xms,
> like => { %full_runs, section_post_data => 1, },
> },
>
> (ditto for the pub12 test)
>
Thanks for the suggestion. I've updated the test accordingly in v9.
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Mon, Jun 1, 2026 at 12:59 PM Peter Smith wrote:
>
> Hi Nisha.
>
> Some review comments for patch v8-0004.
>
Thanks for the review.
> ======
> src/backend/commands/publicationcmds.c
>
> AlterPublicationSchemaExceptTables:
>
> 1.
> + /* Collect OIDs of the desired new EXCEPT list. */
> + foreach_ptr(PublicationRelInfo, pri, rels)
> + {
> + newexceptrelids = lappend_oid(newexceptrelids,
> + RelationGetRelid(pri->relation));
> + }
>
> Block braces {} not needed.
>
Fixed.
> ~~~
>
> 2.
> + if (!OidIsValid(proid))
> + continue; /* already gone */
> +
> + ObjectAddressSet(obj, PublicationRelRelationId, proid);
> + performDeletion(&obj, DROP_CASCADE, 0);
>
> SUGGESTION
> if (OidIsValid(proid))
> {
> ObjectAddressSet(obj, PublicationRelRelationId, proid);
> performDeletion(&obj, DROP_CASCADE, 0);
> }
>
Fixed. A similar pattern was also used in PublicationDropSchemas(),
and I have fixed that as well.
> ======
> src/test/subscription/t/037_except.pl
>
> 3.
> I think you had used the SQL exactly as I previously suggested, but I
> made a mistake:
> It should say "SELECT count(*)" instead of "SELECT a".
>
> So it returns either 0 or 1 row.
>
> e.g. #1
> $result =
> $node_subscriber->safe_psql('postgres',
> "SELECT count(*) FROM sch1.tab_excluded WHERE a = 7");
> is($result, qq(1),
> 'ALTER ... SET TABLES IN SCHEMA EXCEPT: newly included table is replicated'
> );
> $result =
> $node_subscriber->safe_psql('postgres',
> "SELECT count(*) FROM sch1.tab_published WHERE a = 7");
> is($result, qq(0),
> 'ALTER ... SET TABLES IN SCHEMA EXCEPT: now-excluded table is not
> replicated'
> );
>
> e.g. #2
> $result =
> $node_subscriber->safe_psql('postgres',
> "SELECT count(*) FROM sch1.tab_published WHERE a = 8");
> is($result, qq(1),
> 'ALTER ... SET TABLES IN SCHEMA (no EXCEPT): tab_published
> replicated after except list cleared'
> );
> $result =
> $node_subscriber->safe_psql('postgres',
> "SELECT count(*) FROM sch1.tab_excluded WHERE a = 8");
> is($result, qq(1),
> 'ALTER ... SET TABLES IN SCHEMA (no EXCEPT): tab_excluded
> replicated after except list cleared'
> );
>
Thanks for pointing that out; I overlooked your earlier suggestion.
I've now updated as suggested.
Attached is the updated v9 patch set.
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Zsolt Parragi <zsolt.parragi@percona.com>
Дата:
Hello In this simple script: CREATE SCHEMA s; CREATE TABLE s.a(i int); CREATE TABLE s.b(i int); CREATE PUBLICATION p FOR TABLES IN SCHEMA s EXCEPT (TABLE s.b); SELECT * FROM pg_publication_tables WHERE pubname = 'p'; SELECT * FROM pg_get_publication_tables(ARRAY['p'], 's.b'::regclass); Shouldn't the second select return an empty list? Currently it returns one row for s.b. And I think there's also a bug with CREATE PUBLICATION with IN SCHEMA CURRENT_SCHEMA: CREATE SCHEMA s1; CREATE TABLE s1.a(i int); CREATE TABLE public.x(i int); CREATE TABLE public.onlypub(i int); -- exists only in public, not in s1 CREATE PUBLICATION pn FOR TABLES IN SCHEMA s1 EXCEPT (TABLE public.x); -- error out, good SET search_path = s1, public; CREATE PUBLICATION pn2 FOR TABLES IN SCHEMA s1 EXCEPT (TABLE onlypub); -- error out, good SET search_path = s1, public; SELECT current_schema(); -- s1 CREATE PUBLICATION pc FOR TABLES IN SCHEMA CURRENT_SCHEMA EXCEPT (TABLE public.x); -- doesn't error out CREATE PUBLICATION pc4 FOR TABLES IN SCHEMA CURRENT_SCHEMA EXCEPT (TABLE onlypub); -- also doesn't error out
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Wed, Jun 3, 2026 at 2:51 AM Zsolt Parragi wrote: > > Hello > Hi, thanks for the tests. > In this simple script: > > CREATE SCHEMA s; > CREATE TABLE s.a(i int); > CREATE TABLE s.b(i int); > CREATE PUBLICATION p FOR TABLES IN SCHEMA s EXCEPT (TABLE s.b); > > SELECT * FROM pg_publication_tables WHERE pubname = 'p'; > SELECT * FROM pg_get_publication_tables(ARRAY['p'], 's.b'::regclass); > > Shouldn't the second select return an empty list? Currently it returns > one row for s.b. > Yes, it is a bug. The issue was that pg_get_publication_tables() could not distinguish between prexcept=true and prexcept=false. A reference note: This worked fine for FOR ALL TABLES publications because entries in pg_publication_rel always had prexcept=false, so the presence of an entry implied the table was not published. With non-ALL TABLES publications, a table can now have both prexcept=true (explicitly excluded) and prexcept=false (excluded from a schema publication). Fixed. > And I think there's also a bug with CREATE PUBLICATION with IN SCHEMA > CURRENT_SCHEMA: > > CREATE SCHEMA s1; > CREATE TABLE s1.a(i int); > CREATE TABLE public.x(i int); > CREATE TABLE public.onlypub(i int); -- exists only in public, not in s1 > > CREATE PUBLICATION pn FOR TABLES IN SCHEMA s1 EXCEPT (TABLE public.x); > -- error out, good > SET search_path = s1, public; > CREATE PUBLICATION pn2 FOR TABLES IN SCHEMA s1 EXCEPT (TABLE onlypub); > -- error out, good > SET search_path = s1, public; > SELECT current_schema(); -- s1 > CREATE PUBLICATION pc FOR TABLES IN SCHEMA CURRENT_SCHEMA EXCEPT > (TABLE public.x); -- doesn't error out > CREATE PUBLICATION pc4 FOR TABLES IN SCHEMA CURRENT_SCHEMA EXCEPT > (TABLE onlypub); -- also doesn't error out > Yes, this is a bug. The CURRENT_SCHEMA case was missed when the patch was updated to allow only immediate schema tables in the EXCEPT clause. Attached are v10 patches with fixes for both issues. I also added the missing tab-completion for CURRENT_SCHEMA and added regression tests in publication.sql covering both scenarios. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Zsolt Parragi <zsolt.parragi@percona.com>
Дата:
Hello! Thanks, I can confirm the fixes work. I did some more testing. I think I see two problems with ALTER TABLE ... SET SCHEMA: 1. CREATE SCHEMA s; CREATE SCHEMA other; CREATE TABLE s.t(i int); CREATE PUBLICATION p FOR TABLES IN SCHEMA s EXCEPT (TABLE s.t); ALTER TABLE s.t SET SCHEMA other; ALTER PUBLICATION p ADD TABLES IN SCHEMA other; -- shouldn't s.t be there? SELECT schemaname, tablename FROM pg_publication_tables WHERE pubname='p' ORDER BY 1,2; 2. CREATE SCHEMA s; CREATE SCHEMA other; CREATE TABLE s.t(i int); CREATE PUBLICATION p FOR TABLES IN SCHEMA s EXCEPT (TABLE s.t); ALTER TABLE s.t SET SCHEMA other; ALTER PUBLICATION p DROP TABLES IN SCHEMA s; -- should it still be there? it isn't without the alter set schema SELECT pr.prrelid::regclass AS rel, pub.pubname, pr.prexcept FROM pg_publication_rel pr JOIN pg_publication pub ON pub.oid=pr.prpubid;
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Sun, Jun 7, 2026 at 2:09 AM Zsolt Parragi wrote: > > Hello! > > Thanks, I can confirm the fixes work. > > I did some more testing. I think I see two problems with ALTER TABLE > ... SET SCHEMA: > Thanks for reporting this case. The current patches did not handle schema changes for excluded tables. Hou-san also reported the same design issue off-list to me. After considering, I chose to follow behavior similar to existing FOR ALL TABLES publications to handle schema-switch cases. Today, if a table excluded via EXCEPT is dropped, the corresponding prexcept entry is removed, and recreating a table with the same name does not automatically restore the exclusion. I applied the same principle to schema changes: once an excluded table moves out of the schema, the exclusion is removed. For example, consider the following cases: CREATE PUBLICATION p FOR TABLES IN SCHEMA s1 EXCEPT (TABLE s1.t); case-1: Table moves from s1 to s2: ALTER TABLE s1.t SET SCHEMA s2; -- The exclusion entry s1.t is removed. case-2: Table moves back from s2 to s1: ALTER TABLE s2.t SET SCHEMA s1; -- The table is published again. The exclusion is not restored automatically; the user must specify it again. case-3: If s2 is also part of publication p -- The behavior remains the same. Moving the table between schemas does not recreate the exclusion entry. IOW, once the exclusion is broken by a schema move (similar to a drop), it must be re-established explicitly by the user. The attached patch implements this behavior. I've also updated the docs to describe it. I also considered two alternatives: 1) Reject the schema change: Error out if a table with a prexcept entry is moved between schemas. This feels overly restrictive. 2) Make exclusions schema-aware: Add a prexceptschema column and store the schema OID along with the exclusion entry. The exclusion would only apply while the table remains in that schema, allowing it to be restored automatically if the table moves back later. IMO it complicates the design. Thoughts? > 1. > > CREATE SCHEMA s; > CREATE SCHEMA other; > CREATE TABLE s.t(i int); > CREATE PUBLICATION p FOR TABLES IN SCHEMA s EXCEPT (TABLE s.t); > ALTER TABLE s.t SET SCHEMA other; > ALTER PUBLICATION p ADD TABLES IN SCHEMA other; > -- shouldn't s.t be there? > SELECT schemaname, tablename FROM pg_publication_tables WHERE > pubname='p' ORDER BY 1,2; > Do you mean other.t should be there? This is now fixed. When t is moved to schema other, the exclusion is removed and the table is published through p. postgres=# SELECT schemaname, tablename FROM pg_publication_tables WHERE pubname='p' ORDER BY 1,2; schemaname | tablename ------------+----------- other | t > > 2. > > CREATE SCHEMA s; > CREATE SCHEMA other; > CREATE TABLE s.t(i int); > CREATE PUBLICATION p FOR TABLES IN SCHEMA s EXCEPT (TABLE s.t); > ALTER TABLE s.t SET SCHEMA other; > ALTER PUBLICATION p DROP TABLES IN SCHEMA s; > -- should it still be there? it isn't without the alter set schema > SELECT pr.prrelid::regclass AS rel, pub.pubname, pr.prexcept > FROM pg_publication_rel pr JOIN pg_publication pub ON pub.oid=pr.prpubid; > Fixed. Now, when s.t is moved out of schema s, it is removed from publication p's exclusion list. Later, if schema s is dropped from publication p, the exclusion entries associated with s are removed as well, and s.t is no longer present there. Attached are the updated v11 patches. Patch 001 has the changes discussed above; patches 002 and 003 are unchanged. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Zsolt Parragi <zsolt.parragi@percona.com>
Дата:
> Do you mean other.t should be there? Yes, that was a typo in my example. > After considering, I chose to follow behavior similar to existing FOR > ALL TABLES publications to handle schema-switch cases. Today, if a > table excluded via EXCEPT is dropped, the corresponding prexcept entry > is removed, and recreating a table with the same name does not > automatically restore the exclusion. > > I applied the same principle to schema changes: once an excluded table > moves out of the schema, the exclusion is removed. I'm not that sure about the analogy. DROP TABLE is a destructive operation, executing DROP TABLE and then CREATE TABLE won't automatically bring back the data. With this approach, two cheap ALTER TABLE ... SET SCHEMA statements can clear an EXCEPT clause without the proper permissions. But I'm not sure what's the best solution for this. The v11 approach is at least more consistent than the previous behavior. > 1) Reject the schema change: Error out if a table with a prexcept > entry is moved between schemas. This feels overly restrictive. It is restrictive, but maybe it's the better solution? Or alternatively, maybe it should require proper permissions to remove the except clause? Another thing that could improve this if we would print out a warning that the statement caused a change in the publication? But then that's also a question for the preexisting drop table case.
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Hi Nisha.
Some review comments for v11-0001.
(I had no new review comments for v11-0002, v11-0003)
======
doc/src/sgml/ref/create_publication.sgml
1.
+
+ For FOR TABLES IN SCHEMA publications, the
+ EXCEPT clause is schema-scoped: the exclusion applies
+ only in the context of the schema to which it was attached. If a table
+ listed in the EXCEPT clause is later moved to a
+ different schema using ALTER TABLE ... SET SCHEMA,
+ the exclusion is removed. The table will then be published if its new
+ schema is part of a publication. If the table is moved back to
+ the original schema, the exclusion is not restored; the user must
+ re-establish it explicitly using ALTER PUBLICATION.
+ Dropping a table always removes it from the EXCEPT
+ list regardless of publication type.
+
1a.
I felt this should be moved up to be the 2nd paragraph of the "EXCEPT"
part. Subsequent information about
inheritance/partitions/multi-publications is common for both EXCEPTS.
~
1b.
All that info about "If a table..." seemed more relevant to ALTER
PUBLICATION than to CREATE PUBLICATION, so I didn't think we needed
those details here.
======
src/backend/commands/publicationcmds.c
RemovePublicationExceptForRelation:
2.
+/*
+ * Remove any EXCEPT clause entries for a relation from schema publications.
+ * Called when a table changes schema (ALTER TABLE ... SET SCHEMA), so that
+ * a schema-scoped exclusion does not silently follow the table to its new
+ * schema. FOR ALL TABLES publications are skipped because their EXCEPT
+ * clause is publication-scoped, not schema-scoped, so that exclusion should
+ * persist regardless of what schema the table is in.
+ */
Instead of saying "FOR ALL TABLES publications are skipped", rephrase
that to be something like: "This problem does not apply to FOR ALL
TABLES publications because..."
Anyway, I think you can remove that note from the function comment,
and instead put it here:
+ if (!is_schema_publication(pubid))
+ continue;
~~~
3.
+{
+ List *pubids;
+ ListCell *lc;
+ ObjectAddress obj;
+
+ pubids = GetRelationExcludedPublications(relid);
+
+ foreach(lc, pubids)
Using a `foreach_oid` loop might be tidier here.
======
src/backend/commands/tablecmds.c
4.
table_close(classRel, RowExclusiveLock);
+
+ /*
+ * Remove any EXCEPT clause entries for this relation from schema
+ * publications. A schema-scoped exclusion is no longer meaningful once
+ * the table moves to a different schema.
+ */
+ if (rel->rd_rel->relkind == RELKIND_RELATION ||
+ rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
+ RemovePublicationExceptForRelation(RelationGetRelid(rel));
Should this code be put prior to the table_close, where the other
dependent stuff is also removed?
======
src/backend/parser/gram.y
5.
+ /* For TABLES_IN_CUR_SCHEMA: leave except_tables for execution time */
Isn't this repeating exactly what you already said in the other
comment ("For TABLES_IN_CUR_SCHEMA the schema name is not yet
known...")?
======
src/test/regress/sql/publication.sql
6.
+-- test for EXCEPT clause with schema publication (bug: excluded
table was incorrectly returned)
+SELECT * FROM test_gpt(ARRAY['pub_schema_except'],
'gpt_test_sch.tbl_sch'); -- no result (excluded)
+SELECT * FROM test_gpt(ARRAY['pub_schema_except'],
'gpt_test_sch.tbl_sch2'); -- one row (included via schema)
+
Is that "(bug: ...)" comment necessary?
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Wed, Jun 10, 2026 at 3:06 AM Zsolt Parragi wrote: > > > Do you mean other.t should be there? > > Yes, that was a typo in my example. > > > After considering, I chose to follow behavior similar to existing FOR > > ALL TABLES publications to handle schema-switch cases. Today, if a > > table excluded via EXCEPT is dropped, the corresponding prexcept entry > > is removed, and recreating a table with the same name does not > > automatically restore the exclusion. > > > > I applied the same principle to schema changes: once an excluded table > > moves out of the schema, the exclusion is removed. > > I'm not that sure about the analogy. DROP TABLE is a destructive > operation, executing DROP TABLE and then CREATE TABLE won't > automatically bring back the data. > > With this approach, two cheap ALTER TABLE ... SET SCHEMA statements > can clear an EXCEPT clause without the proper permissions. > We already have similar behavior today. A non-publication owner can run ALTER TABLE ... SET SCHEMA and remove a table from a FOR TABLES IN SCHEMA publication without any warning or publication-level permission check. > But I'm not sure what's the best solution for this. The v11 approach > is at least more consistent than the previous behavior. > > > 1) Reject the schema change: Error out if a table with a prexcept > > entry is moved between schemas. This feels overly restrictive. > > It is restrictive, but maybe it's the better solution? Or > alternatively, maybe it should require proper permissions to remove > the except clause? > My concern is that introducing a permission check only for the EXCEPT case would create an inconsistency: one type of schema move affecting publication behavior would require publication ownership, while another would not. That said, I'm okay with restricting schema changes for tables in an EXCEPT list if others feel that's the right behavior. Let's wait for feedback from others. > Another thing that could improve this if we would print out a warning > that the statement caused a change in the publication? But then that's > also a question for the preexisting drop table case. > Right, As also mentioned above, ALTER TABLE changes that affect publication membership currently do not emit any notice or warning, so I'm not sure we need one here either. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Wed, Jun 10, 2026 at 10:07 AM Peter Smith wrote: > > Hi Nisha. > > Some review comments for v11-0001. > > (I had no new review comments for v11-0002, v11-0003) > Thanks for the review. I've addressed all the comments as suggested and attached the updated v12 patch set. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Hi Nisha.
Some review comments for the v12 patches.
//////
v12-0001
======
doc/src/sgml/ref/create_publication.sgml
1.
This clause specifies a list of tables to be excluded from the
- publication.
+ publication. It can be used with FOR ALL TABLES or
+ FOR TABLES IN SCHEMA.
+
+
+ For FOR TABLES IN SCHEMA publications, the
+ EXCEPT clause is schema-scoped: the exclusion applies
+ only within the schema to which it was attached. For
+ FOR ALL TABLES publications, the exclusion applies to
+ the table regardless of the schema it is in.
For that 2nd para, I think it ought to avoid words like "attached"
when talking about tables because attaching has a special meaning.
Also, I don't really understand what the 2nd sentence is trying to
say. FOR ALL TABLES exclusions will exclude the *named* tables. Yes,
those named tables might be in any schema (by fully-qualifying the
name), but that's not the same as saying "regardless of the schema".
So, IMO we can throw away that 2nd sentence, and just keep the
simplified 1st one. Since what remains is now very short, probably
just combine both paragraphs.
SUGGESTION
This clause specifies a list of tables to be excluded from the
publication. It can be used with FOR ALL TABLES or
FOR TABLES IN SCHEMA. For FOR TABLES IN
SCHEMA, the exclusion applies only to tables in the schema
associated with the EXCEPT.
======
src/backend/commands/publicationcmds.c
RemovePublicationExceptForRelation:
2.
+ if (OidIsValid(proid))
+ {
+ ObjectAddressSet(obj, PublicationRelRelationId, proid);
+ performDeletion(&obj, DROP_CASCADE, 0);
+ }
Variable `obj` can be declared right here; it's the only place using it.
//////////
v12-0002
======
doc/src/sgml/ref/alter_publication.sgml
1.
+
+ For FOR TABLES IN SCHEMA publications, the
+ EXCEPT clause is schema-scoped. If a table listed in
+ the EXCEPT clause is later moved to a different schema
+ using ALTER TABLE ... SET SCHEMA, the exclusion is
+ removed; the table will then be published if its new schema is part of a
+ publication. If the table is subsequently moved back to the original
+ schema, the exclusion is not restored, and must be re-established
+ explicitly using ALTER PUBLICATION. Dropping a table
+ always removes it from the EXCEPT clause,
regardless of
+ publication type.
+
I think the sentence "If the table is subsequently moved back..." is
overkill, and does not need to be said. The prior info "the exclusion
is removed" already tells me the exclusion is gone, and I think is
reasonable to assume "removed" means that it is gone for good, with no
ambiguity that it might magically come back.
YMMV. Leave it as-is if you prefer.
//////////
v12-0003
No comments.
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Amit Kapila <amit.kapila16@gmail.com>
Дата:
On Thu, Jun 11, 2026 at 2:24 AM Zsolt Parragi wrote:
>
> > Let's wait for feedback from others.
>
> Yes, I think that's the best approach for this question.
>
> > Right, As also mentioned above, ALTER TABLE changes that affect
> > publication membership currently do not emit any notice or warning, so
> > I'm not sure we need one here either.
>
> My idea was to make this change both for existing cases and new cases
> in this patch, so it would be consistent, but that wasn't exactly
> clear in my previous email, sorry about that. Similarly to how cascade
> reports additional objects being dropped.
>
IIUC, the objects here we are talking about are removed because of
their dependency type AUTO at least the existing case of 'drop table'.
So, I think the current behavior suggested by Nisha sounds correct and
consistent with the pre-existing 'drop table' case. Also, we display
such case at DEBUG2 level, see following code in dependency.c:
if (extra->flags & (DEPFLAG_AUTO |
DEPFLAG_INTERNAL |
DEPFLAG_PARTITION |
DEPFLAG_EXTENSION))
{
/*
* auto-cascades are reported at DEBUG2, not msglevel. We don't
* try to combine them with the regular message because the
* results are too confusing when client_min_messages and
* log_min_messages are different.
*/
ereport(DEBUG2,
(errmsg_internal("drop auto-cascades to %s",
We can consider displaying such a message for schema cases, if not
already there.
--
With Regards,
Amit Kapila.
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Amit Kapila <amit.kapila16@gmail.com>
Дата:
On Thu, Jun 11, 2026 at 12:17 PM Peter Smith wrote: > > ////////// > v12-0002 > > ====== > doc/src/sgml/ref/alter_publication.sgml > > 1. > + > + For FOR TABLES IN SCHEMA publications, the > + EXCEPT clause is schema-scoped. If a table listed in > + the EXCEPT clause is later moved to a different schema > + using ALTER TABLE ... SET SCHEMA, the exclusion is > + removed; the table will then be published if its new schema is part of a > + publication. If the table is subsequently moved back to the original > + schema, the exclusion is not restored, and must be re-established > + explicitly using ALTER PUBLICATION. Dropping a table > + always removes it from the EXCEPT clause, > regardless of > + publication type. > + > > > I think the sentence "If the table is subsequently moved back..." is > overkill, and does not need to be said. The prior info "the exclusion > is removed" already tells me the exclusion is gone, and I think is > reasonable to assume "removed" means that it is gone for good, with no > ambiguity that it might magically come back. > > YMMV. Leave it as-is if you prefer. > I feel it is okay to keep the proposed sentence to avoid any ambiguity by the user to consider the schema-scope state is symmetric. -- With Regards, Amit Kapila.
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Mon, Jun 15, 2026 at 11:38 AM Amit Kapila wrote:
>
> On Thu, Jun 11, 2026 at 2:24 AM Zsolt Parragi wrote:
> >
> > > Let's wait for feedback from others.
> >
> > Yes, I think that's the best approach for this question.
> >
> > > Right, As also mentioned above, ALTER TABLE changes that affect
> > > publication membership currently do not emit any notice or warning, so
> > > I'm not sure we need one here either.
> >
> > My idea was to make this change both for existing cases and new cases
> > in this patch, so it would be consistent, but that wasn't exactly
> > clear in my previous email, sorry about that. Similarly to how cascade
> > reports additional objects being dropped.
> >
>
> IIUC, the objects here we are talking about are removed because of
> their dependency type AUTO at least the existing case of 'drop table'.
> So, I think the current behavior suggested by Nisha sounds correct and
> consistent with the pre-existing 'drop table' case. Also, we display
> such case at DEBUG2 level, see following code in dependency.c:
>
> if (extra->flags & (DEPFLAG_AUTO |
> DEPFLAG_INTERNAL |
> DEPFLAG_PARTITION |
> DEPFLAG_EXTENSION))
> {
> /*
> * auto-cascades are reported at DEBUG2, not msglevel. We don't
> * try to combine them with the regular message because the
> * results are too confusing when client_min_messages and
> * log_min_messages are different.
> */
> ereport(DEBUG2,
> (errmsg_internal("drop auto-cascades to %s",
>
> We can consider displaying such a message for schema cases, if not
> already there.
>
The DROP TABLE case is handled automatically via dependency cascade,
so we already get above DEBUG2 log. However, when a table is moved to
a different schema, no such log is emitted because schema changes are
outside the scope of dependency cascade processing.
In v13, I added a DEBUG2 message when a table is removed from the
exclusion list due to a schema change.
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Mon, Jun 15, 2026 at 11:50 AM Amit Kapila wrote: > > On Thu, Jun 11, 2026 at 12:17 PM Peter Smith wrote: > > > > ////////// > > v12-0002 > > > > ====== > > doc/src/sgml/ref/alter_publication.sgml > > > > 1. > > + > > + For FOR TABLES IN SCHEMA publications, the > > + EXCEPT clause is schema-scoped. If a table listed in > > + the EXCEPT clause is later moved to a different schema > > + using ALTER TABLE ... SET SCHEMA, the exclusion is > > + removed; the table will then be published if its new schema is part of a > > + publication. If the table is subsequently moved back to the original > > + schema, the exclusion is not restored, and must be re-established > > + explicitly using ALTER PUBLICATION. Dropping a table > > + always removes it from the EXCEPT clause, > > regardless of > > + publication type. > > + > > > > > > I think the sentence "If the table is subsequently moved back..." is > > overkill, and does not need to be said. The prior info "the exclusion > > is removed" already tells me the exclusion is gone, and I think is > > reasonable to assume "removed" means that it is gone for good, with no > > ambiguity that it might magically come back. > > > > YMMV. Leave it as-is if you prefer. > > > > I feel it is okay to keep the proposed sentence to avoid any ambiguity > by the user to consider the schema-scope state is symmetric. > Okay, I have kept this para as-it-is. The other comments on v12-0001 from [1] have also been addressed. Please find the updated v13 patches attached. [1] https://www.postgresql.org/message-id/CAHut%2BPv-GA1oGa6%2Bnwn_5AVhBg8NuJThQVUzqhQPXJge49jnew%40mail.gmail.com -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
On Mon, Jun 15, 2026 at 9:31 PM Nisha Moond wrote:
>
> On Mon, Jun 15, 2026 at 11:50 AM Amit Kapila wrote:
> >
> > On Thu, Jun 11, 2026 at 12:17 PM Peter Smith wrote:
> > >
> > > //////////
> > > v12-0002
> > >
> > > ======
> > > doc/src/sgml/ref/alter_publication.sgml
> > >
> > > 1.
> > > +
> > > + For FOR TABLES IN SCHEMA publications, the
> > > + EXCEPT clause is schema-scoped. If a table listed in
> > > + the EXCEPT clause is later moved to a different schema
> > > + using ALTER TABLE ... SET SCHEMA, the exclusion is
> > > + removed; the table will then be published if its new schema is part of a
> > > + publication. If the table is subsequently moved back to the original
> > > + schema, the exclusion is not restored, and must be re-established
> > > + explicitly using ALTER PUBLICATION. Dropping a table
> > > + always removes it from the EXCEPT clause,
> > > regardless of
> > > + publication type.
> > > +
> > >
> > >
> > > I think the sentence "If the table is subsequently moved back..." is
> > > overkill, and does not need to be said. The prior info "the exclusion
> > > is removed" already tells me the exclusion is gone, and I think is
> > > reasonable to assume "removed" means that it is gone for good, with no
> > > ambiguity that it might magically come back.
> > >
> > > YMMV. Leave it as-is if you prefer.
> > >
> >
> > I feel it is okay to keep the proposed sentence to avoid any ambiguity
> > by the user to consider the schema-scope state is symmetric.
> >
>
> Okay, I have kept this para as-it-is.
>
This discussion about the impact of ALTER TABLE ... SET SCHEMA made me
wonder what happens for the existing PG19 case of FOR ALL TABLES
EXCEPT (TABLE ...)
It turns out to be quite different:
======
test_pub=# CREATE SCHEMA myschema;
CREATE SCHEMA
test_pub=# CREATE TABLE t1(A INT);
CREATE TABLE
test_pub=# CREATE TABLE t2(A INT);
CREATE TABLE
test_pub=# CREATE TABLE myschema.myt1(A INT);
CREATE TABLE
test_pub=# CREATE PUBLICATION pub1 FOR ALL TABLES EXCEPT (TABLE myschema.myt1);
CREATE PUBLICATION
test_pub=# \d myschema.myt1
Table "myschema.myt1"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
a | integer | | |
Excluded from publications:
"pub1"
test_pub=# \dRp+ pub1
Publication pub1
Owner | All tables | All sequences | Inserts | Updates | Deletes |
Truncates | Generated columns | Via root | Descri
ption
----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+-------
------
postgres | t | f | t | t | t |
t | none | f |
Except tables:
"myschema.myt1"
test_pub=# ALTER TABLE myschema.myt1 SET SCHEMA public;
ALTER TABLE
test_pub=# \d myt1
Table "public.myt1"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
a | integer | | |
Excluded from publications:
"pub1"
test_pub=# \dRp+ pub1
Publication pub1
Owner | All tables | All sequences | Inserts | Updates | Deletes |
Truncates | Generated columns | Via root | Descri
ption
----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+-------
------
postgres | t | f | t | t | t |
t | none | f |
Except tables:
"public.myt1"
======
This experiment shows that moving the table did *not* remove the exclusion.
It is kind of "explainable" in hindsight because the exclusion is by
table OID, not name, so it follows the table around when it is moved.
I don't think this is what a user would expect, given that they
explicitly asked to exclude it from a different schema.
Is it a PG19 exclusion bug?
Is it behaviour that needs more documenting?
~
IMO it seemed like a bug of the PG19 FOR ALL TABLES EXCEPT, because it
is the opposite of what the new FOR TABLES IN SCHEMA EXCEPT patch
does:
"If a table listed in the EXCEPT clause is later
moved to a different schema using ALTER TABLE ... SET
SCHEMA, the exclusion is removed;"
Thoughts?
======
Kind Regards,
Peter Smith.
Fujitsu Australia.
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
On Tue, Jun 16, 2026 at 2:36 PM Amit Kapila wrote: > > On Tue, Jun 16, 2026 at 6:52 AM Peter Smith wrote: > > > > This discussion about the impact of ALTER TABLE ... SET SCHEMA made me > > wonder what happens for the existing PG19 case of FOR ALL TABLES > > EXCEPT (TABLE ...) > > > > It turns out to be quite different: > > > > ====== > > > > test_pub=# CREATE SCHEMA myschema; > > CREATE SCHEMA > > test_pub=# CREATE TABLE t1(A INT); > > CREATE TABLE > > test_pub=# CREATE TABLE t2(A INT); > > CREATE TABLE > > test_pub=# CREATE TABLE myschema.myt1(A INT); > > CREATE TABLE > > test_pub=# CREATE PUBLICATION pub1 FOR ALL TABLES EXCEPT (TABLE myschema.myt1); > > CREATE PUBLICATION > > test_pub=# \d myschema.myt1 > > Table "myschema.myt1" > > Column | Type | Collation | Nullable | Default > > --------+---------+-----------+----------+--------- > > a | integer | | | > > Excluded from publications: > > "pub1" > > > > test_pub=# \dRp+ pub1 > > Publication pub1 > > Owner | All tables | All sequences | Inserts | Updates | Deletes | > > Truncates | Generated columns | Via root | Descri > > ption > > ----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------- > > ------ > > postgres | t | f | t | t | t | > > t | none | f | > > Except tables: > > "myschema.myt1" > > > > test_pub=# ALTER TABLE myschema.myt1 SET SCHEMA public; > > ALTER TABLE > > test_pub=# \d myt1 > > Table "public.myt1" > > Column | Type | Collation | Nullable | Default > > --------+---------+-----------+----------+--------- > > a | integer | | | > > Excluded from publications: > > "pub1" > > > > test_pub=# \dRp+ pub1 > > Publication pub1 > > Owner | All tables | All sequences | Inserts | Updates | Deletes | > > Truncates | Generated columns | Via root | Descri > > ption > > ----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------- > > ------ > > postgres | t | f | t | t | t | > > t | none | f | > > Except tables: > > "public.myt1" > > > > ====== > > > > This experiment shows that moving the table did *not* remove the exclusion. > > > > It is kind of "explainable" in hindsight because the exclusion is by > > table OID, not name, so it follows the table around when it is moved. > > I don't think this is what a user would expect, given that they > > explicitly asked to exclude it from a different schema. > > > > Is it a PG19 exclusion bug? > > > > Is it behaviour that needs more documenting? > > > > ~ > > > > IMO it seemed like a bug of the PG19 FOR ALL TABLES EXCEPT, because it > > is the opposite of what the new FOR TABLES IN SCHEMA EXCEPT patch > > does: > > "If a table listed in the EXCEPT clause is later > > moved to a different schema using ALTER TABLE ... SET > > SCHEMA, the exclusion is removed;" > > > > No, I don't think this is a bug for PG19 and the new behaviour for > PG20 is intentional and required because in this case, the EXCEPT > clause is schema-scoped, so once schema is changed, the table should > be removed from the exclusion list. OTOH, in PG19, the exclusion list > follows the table-level exclusion based on its OID as we can see in > the example provided by you. I think we can consider adding a line for > this in docs if you and others feel that such explicit mention can > avoid ambiguity around this. How about something like the following as > a separate para in EXCEPT clause description: Once a table is > excluded, the exclusion applies to that table itself, regardless of > its name or schema. Renaming the table or moving it to another schema > with ALTER TABLE ... SET SCHEMA does not cancel the > exclusion." > OK. The explanatory text LGTM. What's the next step? Should I create a new thread/patch to deal with this? ====== Kind Regards. Peter Smith Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Some review comments for v13-0001.
======
doc/src/sgml/ref/create_publication.sgml
1.
Marks the publication as one that replicates changes for all tables in
the specified list of schemas, including tables created in the future.
+ Tables listed in the EXCEPT clause for a given schema
+ are excluded from the publication.
Given Amit's suggestion [1] to modify the EXCEPT text for FOR ALL
TABLES, perhaps there also needs to be an equivalent note for ALL
TABLES IN SCHEMA. Maybe wait to see what happens [1], then you can use
similar wording.
======
src/backend/commands/publicationcmds.c
RemovePublicationExceptForRelation:
2.
+/*
+ * Remove any EXCEPT clause entries for a relation from schema publications.
+ * Called when a table changes schema (ALTER TABLE ... SET SCHEMA), so that
+ * a schema-scoped exclusion does not silently follow the table to its new
+ * schema.
+ */
+void
+RemovePublicationExceptForRelation(Oid relid, Oid oldNspOid, Oid newNspOid)
+{
There's nothing about that function name to indicate it is only for
SCHEMA publications.
There must be a better -- e.g. 'MaybeRemoveExclusionFromSchemaPub', or
whatever...
~~~
3.
+ ereport(DEBUG2,
+ errmsg_internal("auto-drop exclusion of table %s from publication
%s: table moved to schema %s",
+ quote_qualified_identifier(get_namespace_name(oldNspOid),
+ get_rel_name(relid)),
+ get_publication_name(pubid, false),
+ quote_identifier(get_namespace_name(newNspOid))));
Even though this is a debugging message, for consistency, we might as
well quote everything the same as normal messages do:
"auto-drop exclusion of table \"%s\" from publication \"%s\": table
moved to schema \"%s\""
======
[1] https://www.postgresql.org/message-id/CAA4eK1J_QP8CXCshaCy_01ALQQrDSzoTHfXKcAbjiEvV-RkOOw%40mail.gmail.com
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Tue, Jun 16, 2026 at 1:53 PM Peter Smith wrote:
>
> Some review comments for v13-0001.
>
> ======
> doc/src/sgml/ref/create_publication.sgml
>
> 1.
>
> Marks the publication as one that replicates changes for all tables in
> the specified list of schemas, including tables created in the future.
> + Tables listed in the EXCEPT clause for a given schema
> + are excluded from the publication.
>
>
> Given Amit's suggestion [1] to modify the EXCEPT text for FOR ALL
> TABLES, perhaps there also needs to be an equivalent note for ALL
> TABLES IN SCHEMA. Maybe wait to see what happens [1], then you can use
> similar wording.
>
Okay, noted. Let's first wait for the conclusion on this.
> ======
> src/backend/commands/publicationcmds.c
>
> RemovePublicationExceptForRelation:
>
> 2.
> +/*
> + * Remove any EXCEPT clause entries for a relation from schema publications.
> + * Called when a table changes schema (ALTER TABLE ... SET SCHEMA), so that
> + * a schema-scoped exclusion does not silently follow the table to its new
> + * schema.
> + */
> +void
> +RemovePublicationExceptForRelation(Oid relid, Oid oldNspOid, Oid newNspOid)
> +{
>
> There's nothing about that function name to indicate it is only for
> SCHEMA publications.
> There must be a better -- e.g. 'MaybeRemoveExclusionFromSchemaPub', or
> whatever...
>
I've renamed it to RemoveSchemaPubExceptForRel to keep it consistent
with the neighboring function names. Let me know if it works.
> ~~~
>
> 3.
> + ereport(DEBUG2,
> + errmsg_internal("auto-drop exclusion of table %s from publication
> %s: table moved to schema %s",
> + quote_qualified_identifier(get_namespace_name(oldNspOid),
> + get_rel_name(relid)),
> + get_publication_name(pubid, false),
> + quote_identifier(get_namespace_name(newNspOid))));
>
> Even though this is a debugging message, for consistency, we might as
> well quote everything the same as normal messages do:
>
> "auto-drop exclusion of table \"%s\" from publication \"%s\": table
> moved to schema \"%s\""
>
Fixed.
~~~
Also added a test as per Zsolt's suggestion at [1].
I moved all documentation changes into a separate 0004 patch to make
doc review easier.
Please find the attached v14 patches.
[1] https://www.postgresql.org/message-id/CAN4CZFPZnckA9-MPt6xj1QsRQTVKs3ZoKgdZ%2BQG1xa%3D%3DUD46Xw%40mail.gmail.com
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Amit Kapila <amit.kapila16@gmail.com>
Дата:
On Tue, Jun 16, 2026 at 12:06 PM Peter Smith wrote: > > On Tue, Jun 16, 2026 at 2:36 PM Amit Kapila wrote: > > > > No, I don't think this is a bug for PG19 and the new behaviour for > > PG20 is intentional and required because in this case, the EXCEPT > > clause is schema-scoped, so once schema is changed, the table should > > be removed from the exclusion list. OTOH, in PG19, the exclusion list > > follows the table-level exclusion based on its OID as we can see in > > the example provided by you. I think we can consider adding a line for > > this in docs if you and others feel that such explicit mention can > > avoid ambiguity around this. How about something like the following as > > a separate para in EXCEPT clause description: Once a table is > > excluded, the exclusion applies to that table itself, regardless of > > its name or schema. Renaming the table or moving it to another schema > > with ALTER TABLE ... SET SCHEMA does not cancel the > > exclusion." > > > > OK. The explanatory text LGTM. > > What's the next step? Should I create a new thread/patch to deal with this? > WFM. -- With Regards, Amit Kapila.
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Hi Nisha.
Some review comments for v14-0001.
======
src/test/regress/sql/publication.sql
1.
+-- ALTER TABLE ... SET SCHEMA on a table excluded by a schema publication:
+-- the schema-scoped exclusion is no longer meaningful once the table moves
+-- out of its schema, so the exclution is auto-dropped.
1a.
typo: /exclution/exclusion/
~
1b.
Exclusions cannot be "dropped" (at least, not by a user with the DROP
command). So even though this is correct for what is happening
internally, maybe from the user PoV it is better to say something like
"auto-removed" or just "removed".
(Same comment may also apply to the DEBUG logging when this happened).
~~~
2.
+-- Restore so the existing cleanup below still works
+ALTER TABLE public.testpub_tbl_s2 SET SCHEMA pub_test;
+DROP PUBLICATION testpub_schema_except_setsch;
Why not just fix the cleanup code? It's not "existing cleanup" anyway
-- it's part of this same patch.
////////////////////
Some review comments for v14-0004.
======
doc/src/sgml/ref/alter_publication.sgml:
1.
used with a publication defined with FOR TABLE or
FOR TABLES IN SCHEMA, replaces the list of tables/schemas
in the publication with the specified list; the existing tables or schemas
- that were present in the publication will be removed.
+ that were present in the publication will be removed. When
+ SET TABLES IN SCHEMA is used with an
+ EXCEPT clause, the excluded tables for each schema are
+ replaced with the specified list; if EXCEPT is omitted
+ for a schema, any existing exclusions for that schema are cleared.
"are cleared" or "are removed"... not sure what is better. Maybe
"cleared" is fine.
~~~
2.
+
+ The EXCEPT clause can be used with
+ ADD TABLES IN SCHEMA to exclude specific tables from a
+ schema-level publication.
+
+
This is talking about the 'ADD' variant. So really, it belongs as part
of that 2nd para: "The first two variants modify..." because that is
where ADD is discussed.
~~~
3.
+
+ EXCEPT
+
+
+ When used with ADD TABLES IN SCHEMA
+ or SET TABLES IN SCHEMA, specifies
+ tables to be excluded from the publication. Each named
+ table must belong to the schema specified in the same
+ TABLES IN SCHEMA clause. Table names may be
+ schema-qualified or unqualified; unqualified names are implicitly
+ qualified with the schema named in the same clause. See
+ for further details on the
+ semantics of EXCEPT.
+
+
+ For FOR TABLES IN SCHEMA publications, the
+ EXCEPT clause is schema-scoped. If a table listed in
+ the EXCEPT clause is later moved to a different schema
+ using ALTER TABLE ... SET SCHEMA, the exclusion is
+ removed; the table will then be published if its new schema is part of a
+ publication. If the table is subsequently moved back to the original
+ schema, the exclusion is not restored, and must be re-established
+ explicitly using ALTER PUBLICATION. Dropping a table
+ always removes it from the EXCEPT clause,
regardless of
+ publication type.
+
+
+
3a.
TBH, I lost track of what the final decision was about keeping this EXCEPT part.
IIUC, you wanted to defer a decision until later, but I did not
understand the plan:
a) Should the EXCEPT part be present for now, but consider removing it later?
b) Should the EXCEPT part be absent for now, but consider adding it later?
I prefer what you have done, but either way, we need to ensure Shlok's
thread uses the same approach.
~
3b.
I think that last "Dropping a table..." sentence should be a separate
, unrelated to renaming/moving tables. Also, you don't need to
say "regardless of publication type" -- that would be the assumption
unless you say otherwise.
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
On Tue, Jun 16, 2026 at 9:08 PM Amit Kapila wrote: > > On Tue, Jun 16, 2026 at 12:06 PM Peter Smith wrote: > > > > On Tue, Jun 16, 2026 at 2:36 PM Amit Kapila wrote: > > > > > > No, I don't think this is a bug for PG19 and the new behaviour for > > > PG20 is intentional and required because in this case, the EXCEPT > > > clause is schema-scoped, so once schema is changed, the table should > > > be removed from the exclusion list. OTOH, in PG19, the exclusion list > > > follows the table-level exclusion based on its OID as we can see in > > > the example provided by you. I think we can consider adding a line for > > > this in docs if you and others feel that such explicit mention can > > > avoid ambiguity around this. How about something like the following as > > > a separate para in EXCEPT clause description: Once a table is > > > excluded, the exclusion applies to that table itself, regardless of > > > its name or schema. Renaming the table or moving it to another schema > > > with ALTER TABLE ... SET SCHEMA does not cancel the > > > exclusion." > > > > > > > OK. The explanatory text LGTM. > > > > What's the next step? Should I create a new thread/patch to deal with this? > > > > WFM. > Done. See new thread/patch [1]. ====== [1] https://www.postgresql.org/message-id/flat/CAHut%2BPvQ5BqnawCQd6r1tqqd%2BiAJC-CuRY8wscuXSrpHGUzofA%40mail.gmail.com Kind Regards, Peter Smith. Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Wed, Jun 17, 2026 at 7:24 AM Peter Smith wrote: > > Hi Nisha. > > Some review comments for v14-0001. > > ====== > src/test/regress/sql/publication.sql > > 1. > +-- ALTER TABLE ... SET SCHEMA on a table excluded by a schema publication: > +-- the schema-scoped exclusion is no longer meaningful once the table moves > +-- out of its schema, so the exclution is auto-dropped. > > 1a. > typo: /exclution/exclusion/ > > ~ > > 1b. > Exclusions cannot be "dropped" (at least, not by a user with the DROP > command). So even though this is correct for what is happening > internally, maybe from the user PoV it is better to say something like > "auto-removed" or just "removed". > > (Same comment may also apply to the DEBUG logging when this happened). > > ~~~ > > 2. > +-- Restore so the existing cleanup below still works > +ALTER TABLE public.testpub_tbl_s2 SET SCHEMA pub_test; > +DROP PUBLICATION testpub_schema_except_setsch; > > Why not just fix the cleanup code? It's not "existing cleanup" anyway > -- it's part of this same patch. > I restored it here because patches 002 and 003 add tests that depend on pub_test.testpub_tbl_s2. I agree the earlier comments were confusing and made it look like it was only for cleanup purposes. I've reworded the comments, but kept the restore so the ALTER PUBLICATION tests can be added smoothly. > //////////////////// > > Some review comments for v14-0004. > > ====== > > doc/src/sgml/ref/alter_publication.sgml: > > 1. > used with a publication defined with FOR TABLE or > FOR TABLES IN SCHEMA, replaces the list of tables/schemas > in the publication with the specified list; the existing tables or schemas > - that were present in the publication will be removed. > + that were present in the publication will be removed. When > + SET TABLES IN SCHEMA is used with an > + EXCEPT clause, the excluded tables for each schema are > + replaced with the specified list; if EXCEPT is omitted > + for a schema, any existing exclusions for that schema are cleared. > > "are cleared" or "are removed"... not sure what is better. Maybe > "cleared" is fine. > okay, retained "cleared". > ~~~ > > 2. > + > + The EXCEPT clause can be used with > + ADD TABLES IN SCHEMA to exclude specific tables from a > + schema-level publication. > + > + > > This is talking about the 'ADD' variant. So really, it belongs as part > of that 2nd para: "The first two variants modify..." because that is > where ADD is discussed. > Done. > ~~~ > > 3. > + > + EXCEPT > + > + > + When used with ADD TABLES IN SCHEMA > + or SET TABLES IN SCHEMA, specifies > + tables to be excluded from the publication. Each named > + table must belong to the schema specified in the same > + TABLES IN SCHEMA clause. Table names may be > + schema-qualified or unqualified; unqualified names are implicitly > + qualified with the schema named in the same clause. See > + for further details on the > + semantics of EXCEPT. > + > + > + For FOR TABLES IN SCHEMA publications, the > + EXCEPT clause is schema-scoped. If a table listed in > + the EXCEPT clause is later moved to a different schema > + using ALTER TABLE ... SET SCHEMA, the exclusion is > + removed; the table will then be published if its new schema is part of a > + publication. If the table is subsequently moved back to the original > + schema, the exclusion is not restored, and must be re-established > + explicitly using ALTER PUBLICATION. Dropping a table > + always removes it from the EXCEPT clause, > regardless of > + publication type. > + > + > + > > 3a. > TBH, I lost track of what the final decision was about keeping this EXCEPT part. > IIUC, you wanted to defer a decision until later, but I did not > understand the plan: > a) Should the EXCEPT part be present for now, but consider removing it later? > b) Should the EXCEPT part be absent for now, but consider adding it later? > > I prefer what you have done, but either way, we need to ensure Shlok's > thread uses the same approach. > I chose (a), keeping EXCEPT part for now so others can provide feedback and help us reach a consensus on how the documentation should be updated. > ~ > > 3b. > I think that last "Dropping a table..." sentence should be a separate > , unrelated to renaming/moving tables. Also, you don't need to > say "regardless of publication type" -- that would be the assumption > unless you say otherwise. > Fixed. --- Attached are the updated patches v15. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Hi Nisha. No further comments for patches v15-0001,0002,0003. But, here are some comments for v15-0004. ====== doc/src/sgml/ref/alter_publication.sgml 1. + + For FOR TABLES IN SCHEMA publications, the + EXCEPT clause is schema-scoped. If a table listed in + the EXCEPT clause is later moved to a different schema + using ALTER TABLE ... SET SCHEMA, the exclusion is + removed; the table will then be published if its new schema is part of a + publication. If the table is subsequently moved back to the original + schema, the exclusion is not restored, and must be re-established + explicitly using ALTER PUBLICATION. + IIRC the recent commit 77b6dd9 that explained about moving tables to other schemas, was only on the CREATE PUBLICATION page; not on the ALTER PUBLICATION page. So either: (a) maybe this entire paragraph is not needed, or (b) keep it, but then the behaviour for FOR ALL TABLES also needs to be described here ====== doc/src/sgml/ref/alter_publication.sgml 2. Once a table is excluded, the exclusion applies to that table regardless of its name or schema. Renaming the table or moving it to another schema using ALTER TABLE ... SET SCHEMA does not remove the exclusion. ~~ The recent commit 77b6dd9 added the above text to the CREATE PUBLICATION page. But, that was correct only for "FOR ALL TABLES" -- after your patch we can't say that unconditionally anymore. Also, since that is mentioned on the CREATE PUBLICATION page, I guess we need to say something similar about ALL TABLES IN SCHEMA ... EXCEPT in the same paragraph. So, maybe something like below: SUGGESTION Once a table is excluded under FOR ALL TABLES, the exclusion applies to that table, the exclusion applies to that table regardless of its name or schema. Renaming the table or moving it to another schema using ALTER TABLE ... SET SCHEMA does not remove the exclusion. However, for FOR TABLES IN SCHEMA, because the EXCEPT is schema-scoped, moving a schema-excluded table to another schema does remove the exclusion. ====== Kind Regards, Peter Smith. Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Mon, Jun 22, 2026 at 7:46 AM Peter Smith wrote: > > Hi Nisha. > > No further comments for patches v15-0001,0002,0003. > > But, here are some comments for v15-0004. > > ====== > doc/src/sgml/ref/alter_publication.sgml > > 1. > + > + For FOR TABLES IN SCHEMA publications, the > + EXCEPT clause is schema-scoped. If a table listed in > + the EXCEPT clause is later moved to a different schema > + using ALTER TABLE ... SET SCHEMA, the exclusion is > + removed; the table will then be published if its new schema is part of a > + publication. If the table is subsequently moved back to the original > + schema, the exclusion is not restored, and must be re-established > + explicitly using ALTER PUBLICATION. > + > > IIRC the recent commit 77b6dd9 that explained about moving tables to > other schemas, was only on the CREATE PUBLICATION page; not on the > ALTER PUBLICATION page. > > So either: > (a) maybe this entire paragraph is not needed, or > (b) keep it, but then the behaviour for FOR ALL TABLES also needs to > be described here > > ====== > doc/src/sgml/ref/alter_publication.sgml > > 2. > Once a table is excluded, the exclusion applies to that table > regardless of its name or schema. Renaming the table or moving it to > another schema using ALTER TABLE ... SET SCHEMA does not remove the > exclusion. > > ~~ > > The recent commit 77b6dd9 added the above text to the CREATE > PUBLICATION page. But, that was correct only for "FOR ALL TABLES" -- > after your patch we can't say that unconditionally anymore. Also, > since that is mentioned on the CREATE PUBLICATION page, I guess we > need to say something similar about ALL TABLES IN SCHEMA ... EXCEPT in > the same paragraph. > > So, maybe something like below: > > SUGGESTION > Once a table is excluded under FOR ALL TABLES, the > exclusion applies to that table, the exclusion applies to that table > regardless of its name or schema. Renaming the table or moving it to > another schema using ALTER TABLE ... SET SCHEMA > does not remove the exclusion. However, for FOR TABLES IN > SCHEMA, because the EXCEPT is > schema-scoped, moving a schema-excluded table to another schema does > remove the exclusion. > Based on the changes in commit 77b6dd9, I re-analyzed the pointed-out paragraph. On reconsideration, I think the schema-move behavior is really a property of EXCEPT itself rather than ALTER PUBLICATION. So we can keep it only in the CREATE PUBLICATION documentation and drop it from ALTER PUBLICATION to avoid duplication. We already have a cross-reference in ALTER PUBLICATION: "See CREATE PUBLICATION for further details on the semantics of EXCEPT", so users still have a clear path to the detailed behavior description. I modified your suggestion slightly to keep the information from the removed paragraph intact. Attached updated patches v16. No changes in 0001 to 0003. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
On Tue, Jun 23, 2026 at 12:49 AM Nisha Moond wrote: > ... > > Based on the changes in commit 77b6dd9, I re-analyzed the pointed-out paragraph. > > On reconsideration, I think the schema-move behavior is really a > property of EXCEPT itself rather than ALTER PUBLICATION. So we can > keep it only in the CREATE PUBLICATION documentation and drop it from > ALTER PUBLICATION to avoid duplication. > We already have a cross-reference in ALTER PUBLICATION: "See CREATE > PUBLICATION for further details on the semantics of EXCEPT", so users > still have a clear path to the detailed behavior description. > I modified your suggestion slightly to keep the information from the > removed paragraph intact. > > Attached updated patches v16. No changes in 0001 to 0003. > Hi Nisha. Thanks for all the changes. I don't have any more review comments at this time. ====== Kind Regards, Peter Smith. Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Mon, Jun 22, 2026 at 6:20 PM Nisha Moond wrote:
>
> Attached updated patches v16. No changes in 0001 to 0003.
>
Thanks Nisha. I have resumed review of patch. I have not goen through
complete patch yet, but please find a few initial comments:
1)
I get this during compilation:
pgoutput.c:2232:45: warning: declaration of ‘except_pubids’ shadows a
previous local [-Wshadow=compatible-local]
2232 | List *except_pubids = NIL;
| ^~~~~~~~~~~~~
pgoutput.c:2100:29: note: shadowed declaration is here
2100 | List *except_pubids;
2)
I am checking the flow:
get_rel_sync_entry-->GetTopMostAncestorInPublication
@@ -2267,7 +2290,8 @@ get_rel_sync_entry(PGOutputData *data, Relation relation)
ancestor = GetTopMostAncestorInPublication(pub->oid,
ancestors,
- &level);
+ &level,
+ except_pubids);
a)
For what all publications, flow will come to above point. I guess it
can come for a explict table pub or a schema pub. For a schmea pub,
except_pubids make sense but not for a explicit-table pub alone.
Please add a comment atop GetTopMostAncestorInPublication call here to
explain
the scenario adn then the need of except_pubids.
b)
We have got except_pubids in the begining of the function as:
except_pubids = GetRelationExcludedPublications(root_relid);
Now inside GetTopMostAncestorInPublication(), we are keeping
'except_pubids' as constant while moving through all the ancestors. We
are fetching GetRelationIncludedPublications and GetSchemaPublications
for each ancestor but are not computing
GetRelationExcludedPublications for each ancestor. It may not be
obvious (for many new readers) why 'except_pubids' is not fetched
again for each ancestor. Please add a comment there (perhaps because
EXCEPT list can not have any partition and can have only root)
3)
The error message below and its associated validation logic are
duplicated in three places:
"cannot appear in both the table list and the EXCEPT clause"
Do you think we could factor this into a small helper function and
reuse it everywhere? That would make the code more modular and
simplify future changes to validation or error messages.
thanks
Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Wed, Jul 1, 2026 at 3:46 PM shveta malik wrote: > > On Wed, Jul 1, 2026 at 3:37 PM Nisha Moond wrote: > > > > > > Besides the above comments, I found and fixed a few additional issues > > during further testing: > > 1) Fixed an issue where UPDATE/DELETE on an excluded table without > > replica identity was still blocked. e.g., > > > > postgres=# create publication pub_h2 for tables in schema s1 except ( table t1); > > postgres=# update s1.t1 set c1=3 where c1=1; > > ERROR: cannot update table "t1" because it does not have a replica > > identity and publishes updates > > HINT: To enable updating the table, set REPLICA IDENTITY using ALTER TABLE. > > > > Excluded tables should not be treated as published for update/delete checks. > > Nisha, this bug was introduced by your patch or does it exist in 'ALL > TABLES Except TABLE' too? > The same case for 'ALL TABLES Except Table' was already handled correctly as part of that feature (Ref -RelationBuildPublicationDesc()). The bug was only in my patch where I missed handling it earlier. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Thu, Jul 2, 2026 at 10:21 AM Nisha Moond wrote: > > On Wed, Jul 1, 2026 at 3:46 PM shveta malik wrote: > > > > On Wed, Jul 1, 2026 at 3:37 PM Nisha Moond wrote: > > > > > > > > > Besides the above comments, I found and fixed a few additional issues > > > during further testing: > > > 1) Fixed an issue where UPDATE/DELETE on an excluded table without > > > replica identity was still blocked. e.g., > > > > > > postgres=# create publication pub_h2 for tables in schema s1 except ( table t1); > > > postgres=# update s1.t1 set c1=3 where c1=1; > > > ERROR: cannot update table "t1" because it does not have a replica > > > identity and publishes updates > > > HINT: To enable updating the table, set REPLICA IDENTITY using ALTER TABLE. > > > > > > Excluded tables should not be treated as published for update/delete checks. > > > > Nisha, this bug was introduced by your patch or does it exist in 'ALL > > TABLES Except TABLE' too? > > > > The same case for 'ALL TABLES Except Table' was already handled > correctly as part of that feature (Ref > -RelationBuildPublicationDesc()). The bug was only in my patch where I > missed handling it earlier. > Okay, then we are good. A few comments: 1) postgres=# alter publication pub1 add table s2.t1; ERROR: table "s2.t1" cannot be added because it is excluded from publication "pub1" It will be good to add hint in above error. Suggestion: ERROR: cannot add table "s2.t1" to publication "pub1" DETAIL: Table "s2.t1" is currently in EXCEPT list HINT: Change EXCEPT list using ALTER PUBLICATION ..SET TABLES IN SCHEMA .. EXCEPT Please rephrase above as needed. Look earlier such messages/hints already added for ALL TABLES. From the user's perspective, it seems slightly odd that if he has excluded a table from publication, he can not add it back using 'add table'. Was this point discussed earlier? 2) Currently: postgres=# alter publication pub1 drop table s2.t1; ERROR: relation "t1" is not part of the publication s2.t1 is EXCEPT list here. Should we have below error for this case rather than above generic error, it will be more intuitive for user. Plus both add and drop table commands will have similar error-style for EXCEPT list. Thoughts? ERROR: cannot drop table "s2.t1" from publication "pub1" DETAIL: Table "s2.t1" is currently in EXCEPT list HINT: Change EXCEPT list using ALTER PUBLICATION ..SET TABLES IN SCHEMA .. EXCEPT 3) Please see below test: --Setting Except list for pub1 which has all tables of s2 included: alter publication pub1 set tables in schema s2 EXCEPT ( TABLE t1, t2); --pg_publication_rel entries: pubname | schema_name | table_name | prexcept --------+-------------+------------+--------- pub1 | s2 | t1 | t pub1 | s2 | t2 | t --Then added a partition: alter publication pub1 add table s2.tab_part_1_p2; --pg_publication_rel entries: pubname | schema_name | table_name | prexcept --------+-------------+---------------+--------- pub1 | s2 | t1 | t pub1 | s2 | t2 | t pub1 | s2 | tab_part_1_p2 | f --Then changed pub1 to exclude tab_root (parent of tab_part_1_p2) as well: alter publication pub1 set tables in schema s2 EXCEPT ( TABLE t1, t2, tab_root); --pg_publication_rel entries: pubname | schema_name | table_name | prexcept --------+-------------+------------+--------- pub1 | s2 | t1 | t pub1 | s2 | t2 | t pub1 | s2 | tab_root | t Note theoutput above, tab_part_1_p2 is removed internally as part of earlier command since its parent tab_root is now excluded. --Now add parition back, it allowed to add it: alter publication pub1 add table s2.tab_part_1_p2; pg_publication_rel entries: pubname | schema_name | table_name | prexcept --------+-------------+---------------+--------- pub1 | s2 | t1 | t pub1 | s2 | t2 | t pub1 | s2 | tab_root | t pub1 | s2 | tab_part_1_p2 | f FOR ALL TABLES publicaiton, if root is excluded, there is no way publication can have parition included independently. Same should hold true here. Thoughts? thanks Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Amit Kapila <amit.kapila16@gmail.com>
Дата:
On Wed, Jul 1, 2026 at 3:54 PM shveta malik wrote: > > On Wed, Jul 1, 2026 at 3:42 PM Nisha Moond wrote: > > > > During tests, I found one behavior that needs discussion: > > > > Consider a partition hierarchy where the root table is in schema s2, a > > child partition is in schema s1, and the publication includes both > > schemas but excludes only the root table. > > This is the exact scenario I had in mind when reviewing > 'get_rel_sync_entry-->GetTopMostAncestorInPublication' flow, thus I > suggested adding comments about intentionally fetching the 'Exclude > list' only for the Root. I was about to test it in my next review > cycle. > > The first thought is that if root is excluded, the partition should > also be excluded to maintain consistency with the 'ALL TABLES Except > ROOT' behaviour. But then it needs to be documented too. > +1. It is good to be consistent here with similar ALL TABLES case. BTW, as we can't exclude the child table explicitly, this anyway seems like the only option because otherwise, users won't have any way to exclude the child table. -- With Regards, Amit Kapila.
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Thu, Jul 2, 2026 at 2:19 PM shveta malik wrote: > > A few comments: > > 1) > postgres=# alter publication pub1 add table s2.t1; > ERROR: table "s2.t1" cannot be added because it is excluded from > publication "pub1" > > It will be good to add hint in above error. > > Suggestion: > ERROR: cannot add table "s2.t1" to publication "pub1" > DETAIL: Table "s2.t1" is currently in EXCEPT list > HINT: Change EXCEPT list using ALTER PUBLICATION ..SET TABLES IN > SCHEMA .. EXCEPT > > Please rephrase above as needed. Look earlier such messages/hints > already added for ALL TABLES. > Updated the error as suggested, with a slight change in DETAIL message. > From the user's perspective, it seems slightly odd that if he has > excluded a table from publication, he can not add it back using 'add > table'. Was this point discussed earlier? > This hasn't been discussed yet. I kept the current behavior, as IMO, it is hard to tell whether the user is trying to re-include a table or whether the ADD is unintended and should be blocked. To avoid ambiguity, I think EXCEPT entries should be modified only through the EXCEPT (...) clause itself, such as ALTER PUBLICATION ... ADD/SET ... EXCEPT(TABLE ...), or by omitting EXCEPT in the SET case. This would also keep the behavior of ADD TABLE and DROP TABLE aligned, as both would operate only on the include list without touching the EXCEPT list. I think this also aligns with FOR ALL TABLES, where ADD TABLE is disallowed, so the EXCEPT list can only be modified through SET .. EXCEPT (...). Thoughts? > 2) > Currently: > postgres=# alter publication pub1 drop table s2.t1; > ERROR: relation "t1" is not part of the publication > > s2.t1 is EXCEPT list here. > > Should we have below error for this case rather than above generic > error, it will be more intuitive for user. Plus both add and drop > table commands will have similar error-style for EXCEPT list. > Thoughts? > > ERROR: cannot drop table "s2.t1" from publication "pub1" > DETAIL: Table "s2.t1" is currently in EXCEPT list > HINT: Change EXCEPT list using ALTER PUBLICATION ..SET TABLES IN > SCHEMA .. EXCEPT > Makes sense. Fixed. > 3) > Please see below test: > > --Setting Except list for pub1 which has all tables of s2 included: > alter publication pub1 set tables in schema s2 EXCEPT ( TABLE t1, t2); > > --pg_publication_rel entries: > pubname | schema_name | table_name | prexcept > --------+-------------+------------+--------- > pub1 | s2 | t1 | t > pub1 | s2 | t2 | t > > > --Then added a partition: > alter publication pub1 add table s2.tab_part_1_p2; > > --pg_publication_rel entries: > pubname | schema_name | table_name | prexcept > --------+-------------+---------------+--------- > pub1 | s2 | t1 | t > pub1 | s2 | t2 | t > pub1 | s2 | tab_part_1_p2 | f > > > --Then changed pub1 to exclude tab_root (parent of tab_part_1_p2) as well: > > alter publication pub1 set tables in schema s2 EXCEPT ( TABLE t1, t2, tab_root); > > --pg_publication_rel entries: > pubname | schema_name | table_name | prexcept > --------+-------------+------------+--------- > pub1 | s2 | t1 | t > pub1 | s2 | t2 | t > pub1 | s2 | tab_root | t > > Note theoutput above, tab_part_1_p2 is removed internally as part of > earlier command since its parent tab_root is now excluded. > > --Now add parition back, it allowed to add it: > alter publication pub1 add table s2.tab_part_1_p2; > > pg_publication_rel entries: > pubname | schema_name | table_name | prexcept > --------+-------------+---------------+--------- > pub1 | s2 | t1 | t > pub1 | s2 | t2 | t > pub1 | s2 | tab_root | t > pub1 | s2 | tab_part_1_p2 | f > > > FOR ALL TABLES publicaiton, if root is excluded, there is no way > publication can have parition included independently. Same should hold > true here. Thoughts? Right, based on the discussion at [1], since we follow "all partitions are excluded if the root is excluded", a partition child should not be allowed to be added when its partition root is already excluded from the publication. Fixed. Such an operation will now raise an error: postgres=# alter publication pub2 add table t_part_p1; ERROR: cannot add table "public.t_part_p1" to publication "pub2" DETAIL: Partition ancestor "public.t_part" of table "public.t_part_p1" is currently listed in the EXCEPT clause of the publication. HINT: Change EXCEPT list using ALTER PUBLICATION ... SET TABLES IN SCHEMA ... EXCEPT. ~~~ Attached are the updated patches v18. [1] https://www.postgresql.org/message-id/CAA4eK1%2BNmQRjSHPLr0X8YBuC6joivFqgsY3_qJ5-RnuuwNGkRQ%40mail.gmail.com -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Thu, Jul 2, 2026 at 2:34 PM Amit Kapila wrote: > > On Wed, Jul 1, 2026 at 3:54 PM shveta malik wrote: > > > > On Wed, Jul 1, 2026 at 3:42 PM Nisha Moond wrote: > > > > > > During tests, I found one behavior that needs discussion: > > > > > > Consider a partition hierarchy where the root table is in schema s2, a > > > child partition is in schema s1, and the publication includes both > > > schemas but excludes only the root table. > > > > This is the exact scenario I had in mind when reviewing > > 'get_rel_sync_entry-->GetTopMostAncestorInPublication' flow, thus I > > suggested adding comments about intentionally fetching the 'Exclude > > list' only for the Root. I was about to test it in my next review > > cycle. > > > > The first thought is that if root is excluded, the partition should > > also be excluded to maintain consistency with the 'ALL TABLES Except > > ROOT' behaviour. But then it needs to be documented too. > > > > +1. It is good to be consistent here with similar ALL TABLES case. > BTW, as we can't exclude the child table explicitly, this anyway seems > like the only option because otherwise, users won't have any way to > exclude the child table. > I've updated the related comments in v18 and also updated the CREATE PUBLICATION docs to clarify this behavior. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Fri, Jul 3, 2026 at 10:15 PM Nisha Moond wrote: > > On Thu, Jul 2, 2026 at 2:19 PM shveta malik wrote: > > > > A few comments: > > > > 1) > > postgres=# alter publication pub1 add table s2.t1; > > ERROR: table "s2.t1" cannot be added because it is excluded from > > publication "pub1" > > > > It will be good to add hint in above error. > > > > Suggestion: > > ERROR: cannot add table "s2.t1" to publication "pub1" > > DETAIL: Table "s2.t1" is currently in EXCEPT list > > HINT: Change EXCEPT list using ALTER PUBLICATION ..SET TABLES IN > > SCHEMA .. EXCEPT > > > > Please rephrase above as needed. Look earlier such messages/hints > > already added for ALL TABLES. > > > > Updated the error as suggested, with a slight change in DETAIL message. > > > From the user's perspective, it seems slightly odd that if he has > > excluded a table from publication, he can not add it back using 'add > > table'. Was this point discussed earlier? > > > > This hasn't been discussed yet. > > I kept the current behavior, as IMO, it is hard to tell whether the > user is trying to re-include a table or whether the ADD is unintended > and should be blocked. To avoid ambiguity, I think EXCEPT entries > should be modified only through the EXCEPT (...) clause itself, such > as ALTER PUBLICATION ... ADD/SET ... EXCEPT(TABLE ...), or by omitting > EXCEPT in the SET case. > > This would also keep the behavior of ADD TABLE and DROP TABLE aligned, > as both would operate only on the include list without touching the > EXCEPT list. > I think this also aligns with FOR ALL TABLES, where ADD TABLE is > disallowed, so the EXCEPT list can only be modified through SET .. > EXCEPT (...). > > Thoughts? Okay. Makes sense. > > > 2) > > Currently: > > postgres=# alter publication pub1 drop table s2.t1; > > ERROR: relation "t1" is not part of the publication > > > > s2.t1 is EXCEPT list here. > > > > Should we have below error for this case rather than above generic > > error, it will be more intuitive for user. Plus both add and drop > > table commands will have similar error-style for EXCEPT list. > > Thoughts? > > > > ERROR: cannot drop table "s2.t1" from publication "pub1" > > DETAIL: Table "s2.t1" is currently in EXCEPT list > > HINT: Change EXCEPT list using ALTER PUBLICATION ..SET TABLES IN > > SCHEMA .. EXCEPT > > > > Makes sense. Fixed. > > > 3) > > Please see below test: > > > > --Setting Except list for pub1 which has all tables of s2 included: > > alter publication pub1 set tables in schema s2 EXCEPT ( TABLE t1, t2); > > > > --pg_publication_rel entries: > > pubname | schema_name | table_name | prexcept > > --------+-------------+------------+--------- > > pub1 | s2 | t1 | t > > pub1 | s2 | t2 | t > > > > > > --Then added a partition: > > alter publication pub1 add table s2.tab_part_1_p2; > > > > --pg_publication_rel entries: > > pubname | schema_name | table_name | prexcept > > --------+-------------+---------------+--------- > > pub1 | s2 | t1 | t > > pub1 | s2 | t2 | t > > pub1 | s2 | tab_part_1_p2 | f > > > > > > --Then changed pub1 to exclude tab_root (parent of tab_part_1_p2) as well: > > > > alter publication pub1 set tables in schema s2 EXCEPT ( TABLE t1, t2, tab_root); > > > > --pg_publication_rel entries: > > pubname | schema_name | table_name | prexcept > > --------+-------------+------------+--------- > > pub1 | s2 | t1 | t > > pub1 | s2 | t2 | t > > pub1 | s2 | tab_root | t > > > > Note theoutput above, tab_part_1_p2 is removed internally as part of > > earlier command since its parent tab_root is now excluded. > > > > --Now add parition back, it allowed to add it: > > alter publication pub1 add table s2.tab_part_1_p2; > > > > pg_publication_rel entries: > > pubname | schema_name | table_name | prexcept > > --------+-------------+---------------+--------- > > pub1 | s2 | t1 | t > > pub1 | s2 | t2 | t > > pub1 | s2 | tab_root | t > > pub1 | s2 | tab_part_1_p2 | f > > > > > > FOR ALL TABLES publicaiton, if root is excluded, there is no way > > publication can have parition included independently. Same should hold > > true here. Thoughts? > > Right, based on the discussion at [1], since we follow "all partitions > are excluded if the root is excluded", a partition child should not be > allowed to be added when its partition root is already excluded from > the publication. > Fixed. Such an operation will now raise an error: > > postgres=# alter publication pub2 add table t_part_p1; > ERROR: cannot add table "public.t_part_p1" to publication "pub2" > DETAIL: Partition ancestor "public.t_part" of table > "public.t_part_p1" is currently listed in the EXCEPT clause of the > publication. > HINT: Change EXCEPT list using ALTER PUBLICATION ... SET TABLES IN > SCHEMA ... EXCEPT. > ~~~ Okay, looks good. thanks Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Hi Nisha.
Some review comments for v18.
//////////
Patch v18-0001
//////////
src/backend/catalog/pg_publication.c
1.
+ /*
+ * A partition cannot be independently included when any of its partition
+ * ancestors is in this publication's EXCEPT list. Doing so would leave
+ * the catalog inconsistent (root excluded, partition explicitly included)
+ * and the ancestor-cascade rule would silently override the include at
+ * replication time. Individual partitions cannot appear in EXCEPT
+ * (rejected above), so this check only applies to non-EXCEPT adds.
+ */
+ if (!pri->except && targetrel->rd_rel->relispartition)
It might be tidier to deal with partitions in one place.
SUGGESTION
if (targetrel->rd_rel->relispartition)
{
if (pri->except)
{
/* If in EXCEPT clause, must be root partitioned table */
...
} else {
/* If not in EXCEPT clause, check ancestors are not excluded */
...
}
}
~~~
2.
+ errmsg("cannot add table \"%s\" to publication \"%s\"",
+ RelationGetQualifiedRelationName(targetrel),
+ get_publication_name(pubid, false)),
+ errdetail("Partition ancestor \"%s\" of table \"%s\" is currently
listed in the EXCEPT clause of the publication.",
"Partition ancestor .. of table" sounded odd.
How about:
errmsg: cannot add partition \"%s\" to ...
errdetail: Ancestor \"%s\" of partition \"%s\" is currently ...
~~~
publication_add_relation:
3.
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("cannot add table \"%s\" to publication \"%s\"",
+ RelationGetQualifiedRelationName(targetrel),
+ pub->name),
+ errdetail("Table \"%s\" is currently listed in the EXCEPT clause of
the publication.",
The table was already named in the errmsg. It seemed redundant to name
it again in the errdetail.
SUGGESTION
errdetail("The table is currently listed in the EXCEPT clause of the
publication.")
======
src/backend/commands/publicationcmds.c
4.
+ ereport(ERROR,
+ errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("table \"%s\" cannot appear in both the table list and the
EXCEPT clause",
+ RelationGetQualifiedRelationName(pri->relation)));
Do we need to name the clauses in this errmsg? Users can see what they typed.
SUGGESTION
errmsg("table \"%s\" cannot be both published and excluded")
//////////
Patch v18-0003
//////////
src/backend/commands/publicationcmds.c
PublicationDropTables:
1.
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("cannot drop table \"%s\" from publication \"%s\"",
+ RelationGetQualifiedRelationName(rel),
+ get_publication_name(pubid, false)),
+ errdetail("Table \"%s\" is currently listed in the EXCEPT clause of
the publication.",
+ RelationGetQualifiedRelationName(rel)),
+ errhint("Change EXCEPT list using ALTER PUBLICATION ... SET TABLES
IN SCHEMA ... EXCEPT.")));
1a.
(Same as above review comment for patch 0001).
The table was already named in the errmsg. It seemed redundant to name
it again in the errdetail.
SUGGESTION
errdetail("The table is currently listed in the EXCEPT clause of the
publication.")
~
1b.
Why hint to change the except list -- who says the EXCEPT list is wrong?
It seemed more like a user error to me if they are trying to drop
something from a publication when it is already excluded. Why does
this need any hint at all?
======
src/test/regress/sql/publication.sql
2.
I did not recognise the distinction in the test comments between
"fail:" and "error:".
~~~
3.
+-- error: ALTER PUBLICATION ... DROP TABLE on an excluded table is rejected
+-- with an EXCEPT-specific error; an EXCEPT entry is not a member.
I don't think you need to say "an EXCEPT entry is not a member." --
what does that mean, other than to redundantly say an excluded table
is a table that is excluded?
//////////
Patch v18-0004
//////////
doc/src/sgml/ref/create_publication.sgml
1.
For partitioned tables, only the root partitioned table may be specified
in EXCEPT. Doing so excludes the root table and
- all of its partitions from replication. The optional
+ all of its partitions from replication, even any partition that lives
+ in a schema which is itself included in the publication.
BEFORE
For partitioned tables, only the root partitioned table may be
specified in EXCEPT. Doing so excludes the root table and all of its
partitions from replication, even any partition that lives in a schema
which is itself included in the publication.
SUGGESTION #1
For partitioned tables, only the root partitioned table may be
specified in EXCEPT. Excluding the root table automatically excludes
all of its partitions from replication, including those in schemas
that are otherwise included in the publication.
SUGGESTION #2 (TI doubt you even needed to mention about other schemas)
For partitioned tables, only the root partitioned table may be
specified in EXCEPT. Excluding the root table automatically excludes
all of its partitions from replication, including those that would
otherwise be included in the publication.
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Tue, Jul 7, 2026 at 4:31 AM Peter Smith wrote: > > Hi Nisha. > > Bug: The current patch is allowing conflicting exclusion lists... > > ====== > > Background: > > It's always been possible for CREATE PUBLICATION to specify the same > schema or same table multiple times. > > test_pub=# CREATE SCHEMA MYSCHEMA; > CREATE SCHEMA > test_pub=# CREATE TABLE T1(A INT); > CREATE TABLE > test_pub=# CREATE TABLE MYSCHEMA.T2(A INT); > CREATE TABLE > test_pub=# CREATE TABLE MYSCHEMA.T3(A INT); > CREATE TABLE > > // same table multiple times is OK > test_pub=# CREATE PUBLICATION PUB3 FOR TABLE T1,T1,T1,T1; > CREATE PUBLICATION > > // same schema multiple times is OK > test_pub=# CREATE PUBLICATION PUB1 FOR TABLES IN SCHEMA MYSCHEMA, > MYSCHEMA, MYSCHEMA; > CREATE PUBLICATION > > ~~~ > > But, this behaviour is only allowed if there are no specification > conflicts. e.g. You can't have multiple tables with column lists: > > test_pub=# CREATE PUBLICATION PUB4 FOR TABLE T1,T1(A),T1,T1; > ERROR: conflicting or redundant column lists for table "t1" > > ====== > > Bug: > > IMO similar restrictions and a similar error message needs to happen > for clashing schema exclusions. Specifying the same schema multiple > times is fine, but it must be disallowed if there are conflicting > exclusion lists. > +1. Good Catch. > For example, the command below currently works, but it should not: > > test_pub=# CREATE PUBLICATION PUB2 FOR TABLES IN SCHEMA MYSCHEMA > EXCEPT (TABLE T2), MYSCHEMA EXCEPT (TABLE T3), MYSCHEMA; > CREATE PUBLICATION > > test_pub=# \dRp+ PUB2 > Publication pub2 > Owner | All tables | All sequences | Inserts | Updates | Deletes | > Truncates | Generated columns | Via root | Descri > ption > ----------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------- > ------ > postgres | f | f | t | t | t | > t | none | f | > Tables from schemas: > "myschema" > Except tables: > "myschema.t2" > "myschema.t3" > > ====== > Kind Regards, > Peter Smith. > Fujitsu Australia > >
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Amit Kapila <amit.kapila16@gmail.com>
Дата:
On Tue, Jul 7, 2026 at 4:13 PM shveta malik wrote: > > On Tue, Jul 7, 2026 at 2:31 PM shveta malik wrote: > > > > On Fri, Jul 3, 2026 at 10:15 PM Nisha Moond wrote: > > > > > > > > > postgres=# alter publication pub2 add table t_part_p1; > > > ERROR: cannot add table "public.t_part_p1" to publication "pub2" > > > DETAIL: Partition ancestor "public.t_part" of table > > > "public.t_part_p1" is currently listed in the EXCEPT clause of the > > > publication. > > > HINT: Change EXCEPT list using ALTER PUBLICATION ... SET TABLES IN > > > SCHEMA ... EXCEPT. > > > ~~~ > > > > Thanks. Do you think we should restrict this case too? To me, this > > seems like another variation of the above where conflicting entries > > are given at the time of sub-creation itself. The root is excluded but > > parittion is included . > > > > postgres=# create publication pub1 for table s2.tab_part_1, tables in > > schema s2 except (table tab_root); > > CREATE PUBLICATION > > postgres=# \dRp+ > > Publication pub1 > > Owner | All tables | All sequences | Inserts | Updates | Deletes | > > Truncates | Generated columns | Via root | Description > > --------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------------- > > shveta | f | f | t | t | t | t > > | none | f | > > Tables: > > "s2.tab_part_1" > > Tables from schemas: > > "s2" > > Except tables: > > "s2.tab_root" > > > > Since alter is blocked for above case while create-sub is not, > If a combination is not supported in ALTER, we should disallow the same in CREATE as well. So, +1 to restrict the case you reported. > I had a > look at the new check added in check_publication_add_relation > > a) The check introduced in this function for partitions/ancestors is > sufficient for cases where an except-list is already present, but not > for cases where we are in the process of adding one. Thus the > create-sub scenario above is not covered by this. > > b) Also the new check in check_publication_add_relation() gets and > traverses complete list of ancestors > > + List *ancestors = get_partition_ancestors(relid); > + > + foreach_oid(ancestor, ancestors) > > Isn't getting root (llast_oid(ancestors)) and checking that alone in > EXCEPT list will suffice? Or am I missing something? > I think this should be possible because we allow only root tables in the EXCEPT list. If so, and we are planning to change as per your suggestion then we should add a comment as to why checking only last is okay here. -- With Regards, Amit Kapila.
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
Nisha, the patch (testing wise) is okay, but some code-optimization might help. I am stuck on reveiw of GetTopMostAncestorInPublication() and all its callers. 1) caller 1: pub_rf_contains_invalid_column(): It is not understood why pub_rf_contains_invalid_column() does not pass 'exceptPubids' to GetTopMostAncestorInPublication(). Perhaps a comment will help. IIUC, a parittion (for which we are trying to verify row-filter expression) can not co-exist in a subscription where its ROOT is already excluded. This assumption will be true once you address the issue of CREATE SUB (in [1]) sent in my previous email. After that, this will still need a comment. 2) Both caller 2 (get_rel_sync_entry) and caller 3 (is_table_publishable_in_publication) are trying to see if partition should be considered as included in publication and thus are trying to see if ROOT is excluded. But the implementation is very different. The get_rel_sync_entry() does that by passing except_pubids to GetTopMostAncestorInPublication(). This except_pubids was computed for topmost ROOT of the parition in the caller and then it skips checking pg_pub_namepspace if given pubid is part of except_pubids arguement. While is_table_publishable_in_publication() does that by selecting topmost ancestor incuded in a given pubid using GetTopMostAncestorInPublication(), without consulting/computing except_pubids. And then later checks if the ancestor returned by GetTopMostAncestorInPublication() is in pg_publicaiton_rel with 'prexcept' true. IMO, GetTopMostAncestorInPublication() should itself be inclusive of logic where it filters out the table (does not return it as result) if ROOT is excluded. And even we should not be passing an argument for that (this is my initial thought). By making such a logic, we need not to bother about all the callers to see if caller has correct logic to deal with output of GetTopMostAncestorInPublication(). Can you think on this line and check the feasibility. 3) I have yet to reveiw pub_contains_invalid_column, but I have a initial understanding, that it will be similar to the case of pub_rf_contains_invalid_column. Please verify on your end. [1]: https://www.postgresql.org/message-id/CAJpy0uAuL7SqowL7T6HCELuVUr5ubwoGsjV1SQQRCXGme5L%3DpA%40mail.gmail.com thanks Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Tue, Jul 7, 2026 at 8:40 AM shveta malik wrote: > > On Tue, Jul 7, 2026 at 4:31 AM Peter Smith wrote: > > > > Hi Nisha. > > > > Bug: The current patch is allowing conflicting exclusion lists... > > > > ====== > > > > Background: > > > > It's always been possible for CREATE PUBLICATION to specify the same > > schema or same table multiple times. > > > > test_pub=# CREATE SCHEMA MYSCHEMA; > > CREATE SCHEMA > > test_pub=# CREATE TABLE T1(A INT); > > CREATE TABLE > > test_pub=# CREATE TABLE MYSCHEMA.T2(A INT); > > CREATE TABLE > > test_pub=# CREATE TABLE MYSCHEMA.T3(A INT); > > CREATE TABLE > > > > // same table multiple times is OK > > test_pub=# CREATE PUBLICATION PUB3 FOR TABLE T1,T1,T1,T1; > > CREATE PUBLICATION > > > > // same schema multiple times is OK > > test_pub=# CREATE PUBLICATION PUB1 FOR TABLES IN SCHEMA MYSCHEMA, > > MYSCHEMA, MYSCHEMA; > > CREATE PUBLICATION > > > > ~~~ > > > > But, this behaviour is only allowed if there are no specification > > conflicts. e.g. You can't have multiple tables with column lists: > > > > test_pub=# CREATE PUBLICATION PUB4 FOR TABLE T1,T1(A),T1,T1; > > ERROR: conflicting or redundant column lists for table "t1" > > > > ====== > > > > Bug: > > > > IMO similar restrictions and a similar error message needs to happen > > for clashing schema exclusions. Specifying the same schema multiple > > times is fine, but it must be disallowed if there are conflicting > > exclusion lists. > > > > +1. Good Catch. > Thanks for the bug report. I've fixed it and attached the fix as a separate top-up patch, v19-0002. Until v18, schema qualification checks for EXCEPT tables were split between two places: 1) TABLES IN SCHEMA (EXCEPT TABLE ); -- the schema qualification check was performed in gram.y, since all required information was available during parsing. 2) TABLES IN SCHEMA CURRENT_SCHEMA (EXCEPT TABLE ); -- CURRENT_SCHEMA is resolved only at execution time, so the schema qualification and eligibility checks were performed there. The reported bug also affects cases such as: CREATE PUBLICATION PUB2 FOR TABLES IN SCHEMA MYSCHEMA EXCEPT (TABLE T2), CURRENT_SCHEMA EXCEPT (TABLE T3); -- where CURRENT_SCHEMA = myschema. Correct handling of this case requires the checks to be performed after schema resolution, i.e., at execution time. To reduce duplicate code, I moved the schema qualification and eligibility checks for both cases to execution time and removed the corresponding processing from gram.y. Since this changes a fair amount of code, I've kept it as a separate patch (v19-0002) to make review easier. Depending on the feedback, we can optimize the implementation or move parts of it back into gram.y before merging it into patch 0001. ~~~ Attached is the v19 patch set. -- Also Addressed all comments from Peter at [1] and Shveta at [2]. -- The code optimization suggestions from Shveta at [3] are still pending. I'm evaluating them and plan to address them in the next version. ~~~ [1] https://www.postgresql.org/message-id/CAHut%2BPt-%2B6Q4-kmhqCZ2_FpaNRR%3DhaJk-GK1eEyTXcTTDnRnXA%40mail.gmail.com [2] https://www.postgresql.org/message-id/CAJpy0uAuL7SqowL7T6HCELuVUr5ubwoGsjV1SQQRCXGme5L%3DpA%40mail.gmail.com [3] https://www.postgresql.org/message-id/CAJpy0uA_d-K-f94d-9Xw66Fqv7gdSGBYGzi9YcybtuEkYdQocQ%40mail.gmail.com -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Mon, Jul 6, 2026 at 1:25 PM Peter Smith wrote: > > Hi Nisha. > > Some review comments for v18. > > ////////// > Patch v18-0001 > ////////// ... > > ~ > > 1b. > Why hint to change the except list -- who says the EXCEPT list is wrong? > > It seemed more like a user error to me if they are trying to drop > something from a publication when it is already excluded. Why does > this need any hint at all? Okay, I see your point. The intent of the hint was to guide users who are actually trying to remove a table from the EXCEPT list by pointing them to SET. I've reworded it to: HINT: Use ALTER PUBLICATION ... SET TABLES IN SCHEMA ... EXCEPT to drop the table from the EXCEPT list. Hopefully this is clearer and more helpful. Let me know if this works, or if you still think no hint is the better option. > > ====== > src/test/regress/sql/publication.sql > > 2. > I did not recognise the distinction in the test comments between > "fail:" and "error:". > Fixed. I now use "fail" consistently throughout. ... > > ////////// > Patch v18-0004 > ////////// > > doc/src/sgml/ref/create_publication.sgml > > 1. > > For partitioned tables, only the root partitioned table may be specified > in EXCEPT. Doing so excludes the root table and > - all of its partitions from replication. The optional > + all of its partitions from replication, even any partition that lives > + in a schema which is itself included in the publication. > > BEFORE > For partitioned tables, only the root partitioned table may be > specified in EXCEPT. Doing so excludes the root table and all of its > partitions from replication, even any partition that lives in a schema > which is itself included in the publication. > > SUGGESTION #1 > For partitioned tables, only the root partitioned table may be > specified in EXCEPT. Excluding the root table automatically excludes > all of its partitions from replication, including those in schemas > that are otherwise included in the publication. > > SUGGESTION #2 (TI doubt you even needed to mention about other schemas) > For partitioned tables, only the root partitioned table may be > specified in EXCEPT. Excluding the root table automatically excludes > all of its partitions from replication, including those that would > otherwise be included in the publication. > I lean towards Suggestion #1, as not publishing a table/partition when its schema is published without any exception is a non-obvious case and should be stated explicitly. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Wed, Jul 8, 2026 at 11:58 AM Amit Kapila wrote: > > On Tue, Jul 7, 2026 at 4:13 PM shveta malik wrote: > > > > On Tue, Jul 7, 2026 at 2:31 PM shveta malik wrote: > > > > > > On Fri, Jul 3, 2026 at 10:15 PM Nisha Moond wrote: > > > > > > > > > > > > postgres=# alter publication pub2 add table t_part_p1; > > > > ERROR: cannot add table "public.t_part_p1" to publication "pub2" > > > > DETAIL: Partition ancestor "public.t_part" of table > > > > "public.t_part_p1" is currently listed in the EXCEPT clause of the > > > > publication. > > > > HINT: Change EXCEPT list using ALTER PUBLICATION ... SET TABLES IN > > > > SCHEMA ... EXCEPT. > > > > ~~~ > > > > > > Thanks. Do you think we should restrict this case too? To me, this > > > seems like another variation of the above where conflicting entries > > > are given at the time of sub-creation itself. The root is excluded but > > > parittion is included . > > > > > > postgres=# create publication pub1 for table s2.tab_part_1, tables in > > > schema s2 except (table tab_root); > > > CREATE PUBLICATION > > > postgres=# \dRp+ > > > Publication pub1 > > > Owner | All tables | All sequences | Inserts | Updates | Deletes | > > > Truncates | Generated columns | Via root | Description > > > --------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------------- > > > shveta | f | f | t | t | t | t > > > | none | f | > > > Tables: > > > "s2.tab_part_1" > > > Tables from schemas: > > > "s2" > > > Except tables: > > > "s2.tab_root" > > > > > > > Since alter is blocked for above case while create-sub is not, > > > > If a combination is not supported in ALTER, we should disallow the > same in CREATE as well. So, +1 to restrict the case you reported. > Fixed in v19. > > I had a > > look at the new check added in check_publication_add_relation > > > > a) The check introduced in this function for partitions/ancestors is > > sufficient for cases where an except-list is already present, but not > > for cases where we are in the process of adding one. Thus the > > create-sub scenario above is not covered by this. > > > > b) Also the new check in check_publication_add_relation() gets and > > traverses complete list of ancestors > > > > + List *ancestors = get_partition_ancestors(relid); > > + > > + foreach_oid(ancestor, ancestors) > > > > Isn't getting root (llast_oid(ancestors)) and checking that alone in > > EXCEPT list will suffice? Or am I missing something? > > > > I think this should be possible because we allow only root tables in > the EXCEPT list. If so, and we are planning to change as per your > suggestion then we should add a comment as to why checking only last > is okay here. > Agreed; I implemented the suggested optimization and added comments explaining why checking only the last element is sufficient. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Wed, Jul 8, 2026 at 2:58 PM shveta malik wrote: > > On Wed, Jul 8, 2026 at 2:22 PM shveta malik wrote: > > > > Nisha, the patch (testing wise) is okay, but some code-optimization > > might help. I am stuck on reveiw of GetTopMostAncestorInPublication() > > and all its callers. > > Thanks, Shveta. > > 1) > > caller 1: pub_rf_contains_invalid_column(): > > > > It is not understood why pub_rf_contains_invalid_column() does not > > pass 'exceptPubids' to GetTopMostAncestorInPublication(). Perhaps a > > comment will help. IIUC, a parittion (for which we are trying to > > verify row-filter expression) can not co-exist in a subscription where > > its ROOT is already excluded. This assumption will be true once you > > address the issue of CREATE SUB (in [1]) sent in my previous email. > > After that, this will still need a comment. > > You're right. Neither pub_rf_contains_invalid_column() nor pub_contains_invalid_column() depends on GetTopMostAncestorInPublication(), since RelationBuildPublicationDesc() already prepares puboids after excluding GetRelationExcludedPublications(). This follows the same approach used for the FOR ALL TABLES case. With your suggestion below, the except_pubids argument is no longer needed, so I don't think any additional comments are necessary. > > 2) > > Both caller 2 (get_rel_sync_entry) and caller 3 > > (is_table_publishable_in_publication) are trying to see if partition > > should be considered as included in publication and thus are trying to > > see if ROOT is excluded. But the implementation is very different. > > > > The get_rel_sync_entry() does that by passing except_pubids to > > GetTopMostAncestorInPublication(). This except_pubids was computed for > > topmost ROOT of the parition in the caller and then it skips checking > > pg_pub_namepspace if given pubid is part of except_pubids arguement. > > > > While is_table_publishable_in_publication() does that by selecting > > topmost ancestor incuded in a given pubid using > > GetTopMostAncestorInPublication(), without consulting/computing > > except_pubids. And then later checks if the ancestor returned by > > GetTopMostAncestorInPublication() is in pg_publicaiton_rel with > > 'prexcept' true. > > > > IMO, GetTopMostAncestorInPublication() should itself be inclusive of > > logic where it filters out the table (does not return it as result) if > > ROOT is excluded. And even we should not be passing an argument for > > that (this is my initial thought). By making such a logic, we need not > > to bother about all > > the callers to see if caller has correct logic to deal with output of > > GetTopMostAncestorInPublication(). Can you think on this line and > > check the feasibility. > > > > I thought more on this. Do you think we can do this? > > GetTopMostAncestorInPublication() is already accepting a list of > ancestors in a ordered fashion, root at the end. We get root from this > ancestor list, check if root is in pg_publication_rel with > except=true. If so, we skip the rest of the logic and return > InvalidOid from GetTopMostAncestorInPublication(). > > The 'except_pubids' argument is not required. Callers need not to have > special logic to send this arguement or to have extra-processing on > output as done by is_table_publishable_in_publication() currently. > Let me know if I have missed anything. The suggested optimization looks reasonable to me. I verified the test cases for both callers (2 and 3) and finalized the changes. During verification, I found it easy to miss cross-schema partition cases i.e., when the partition root is excluded from one schema while a child partition belongs to another included schema. To cover this, I added tests in patch 0001 that tests both get_rel_sync_entry() and is_table_publishable_in_publication(). Attached is the v20 patch set. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Thu, Jul 9, 2026 at 2:53 PM shveta malik wrote: > > > > > To reduce duplicate code, I moved the schema > > qualification and eligibility checks for both cases to execution time >> and removed the corresponding processing from gram.y. > > > > Since this changes a fair amount of code, I've kept it as a separate > > patch (v19-0002) to make review easier. Depending on the feedback, we > > can optimize the implementation or move parts of it back into gram.y > > before merging it into patch 0001. > > ~~~ > > > > Nisha, > > - * Also flattens except_tables from TABLES IN SCHEMA nodes into the list so > - * that ObjectsInPublicationToOids() sees them as top-level > EXCEPT_TABLE entries. > + * The except_tables attached to TABLES IN SCHEMA nodes are left in place; > + * ObjectsInPublicationToOids() qualifies names, validates schema membership, > + * and flattens them once the schema OID is known. > > Can you please explain what does 'flatten' mean here. > Each TABLES IN SCHEMA ... EXCEPT (...) entry stores its own nested list of EXCEPT tables. Flatten means collecting the PublicationTable from each nested list into a single top-level except_pubtables list, giving it the same structure as a FOR TABLE list that can be passed directly to OpenTableList(). I've reworded the comment. We can also remove it if it seems unnecessary here. > The flatten logic here is added by your patch001 only, it is not an > existing logic. To me (in my initial round of review), it seems okay > if we moved it to ObjectsInPublicationToOids(). The only thing is that > the one error (table in EXCEPT clause does not belong to schema) which > is possible to get at the parsing stage will now be emitted during > pub-creation stage. Yes, the logic was introduced in patch 0001 itself. I just highlighted it for the case you mentioned, where the error is deferred instead of being raised at parse time. > But since it will keep the entire logic of > except-list verification at one place and considering that > creat/alter-pub is not so frequent operation, I am fine with it. But > lets see if others have any comment here. > My thought was the same: to keep the logic in one place for now. Let's see if others have any opinions on it as well. > ~~ > > I had a quick look at the changes: > > + * Include the ONLY-ness of this entry in its signature. EXCEPT > + * (TABLE parent) excludes parent and its inheritance children, > + * while EXCEPT (TABLE ONLY parent) excludes only parent itself. > > I think this will unconditionally apply to paritioned tables as well > but for paritioned table, EXCEPT doc says that ONLY and * has no > effect, but here it shows the effect: > > Thsi gives error: > postgres=# CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA public EXCEPT > (TABLE ONLY tab_root), TABLES IN SCHEMA public EXCEPT (TABLE > tab_root); > ERROR: 42P17: schema "public" specified with conflicting EXCEPT lists > LOCATION: ProcessSchemaExceptTables, publicationcmds.c:299 > > While this does not: > postgres=# CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA public EXCEPT > (TABLE tab_root), TABLES IN SCHEMA public EXCEPT (TABLE tab_root); > CREATE PUBLICATION > > But I also checked column-list errors and found that even if columns > are exact sames, we get error: > > postgres=# CREATE PUBLICATION PUB4 FOR TABLE T1(i), T1(i); > ERROR: 42710: conflicting or redundant column lists for table "t1" > LOCATION: OpenTableList, publicationcmds.c:2312 > > While this works: > postgres=# CREATE PUBLICATION PUB4 FOR TABLE T1, T1; > CREATE PUBLICATION > > This makes me think that even introducing the smartness of identifying > ONLY in case of inherited tables and distinguishing it from > parititoned tables is not required. We can just change your error > message to 'conflicting or redundant EXCEPT lists for schmea "s1"' and > throw error in all cases where schmea with except list repeats without > actually comparing them. Does this sound reasonable? > Yes, that works for me as we have FOR TABLES example to follow. I've made the changes in v20. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Some review comments for v20-0001.
======
src/backend/catalog/pg_publication.c
check_publication_add_relation:
1.
+ else
+ {
+ /*
+ * If not in EXCEPT clause, a partition cannot be independently
+ * included when its partition root is in this publication's
+ * EXCEPT list. Doing so would leave the catalog inconsistent
+ * (root excluded, partition explicitly included) and the
+ * ancestor-cascade rule would silently override the include at
+ * replication time.
+ *
+ * Only the root of a partition hierarchy can ever appear in an
+ * EXCEPT clause (a partition itself is rejected just above), so
+ * checking any intermediate ancestor cannot find a match; the
+ * root is the only one worth a catalog lookup.
+ */
+ Oid root = llast_oid(get_partition_ancestors(relid));
+ HeapTuple atup;
+
+ atup = SearchSysCache2(PUBLICATIONRELMAP,
+ ObjectIdGetDatum(root),
+ ObjectIdGetDatum(pubid));
+ if (HeapTupleIsValid(atup))
+ {
+ bool root_except = ((Form_pg_publication_rel) GETSTRUCT(atup))->prexcept;
+
+ ReleaseSysCache(atup);
+
+ if (root_except)
+ ereport(ERROR,
+ (errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("cannot add partition \"%s\" to publication \"%s\"",
+ RelationGetQualifiedRelationName(targetrel),
+ get_publication_name(pubid, false)),
+ errdetail("Ancestor \"%s\" of partition \"%s\" is currently listed
in the EXCEPT clause of the publication.",
+ quote_qualified_identifier(get_namespace_name(get_rel_namespace(root)),
+ get_rel_name(root)),
+ RelationGetQualifiedRelationName(targetrel)),
+ errhint("Change EXCEPT list using ALTER PUBLICATION ... SET TABLES
IN SCHEMA ... EXCEPT.")));
+ }
+ }
This whole part does not really need to be in `else` because previous
block throws ERROR. So it might be simpler code to remove the `else`
keyword and save some indentation.
~~~
2.
+ /*
+ * If not in EXCEPT clause, a partition cannot be independently
+ * included when its partition root is in this publication's
+ * EXCEPT list. Doing so would leave the catalog inconsistent
+ * (root excluded, partition explicitly included) and the
+ * ancestor-cascade rule would silently override the include at
+ * replication time.
This could be worded simpler
SUGGESTION:
A partition cannot be included when its partition root is in the same
publication's EXCEPT list. Doing so would leave the catalog
inconsistent (root excluded, partition included) and the ...
~~~
3.
+ * Only the root of a partition hierarchy can ever appear in an
+ * EXCEPT clause (a partition itself is rejected just above), so
+ * checking any intermediate ancestor cannot find a match; the
+ * root is the only one worth a catalog lookup.
This could be worded simpler
SUGGESTION
For partition hierachies, only the partition root can be in an EXCEPT
clause (a partition itself is rejected just above), so we only need to
look up the catalog for the root.
~~~
is_table_publication:
4.
"Returns true if the publication has explicitly included relation"
Typos in function comment.
/has explicitly included relation/has an explicitly-included relation/
~~~
5.
+ /*
+ * A publication can hold both explicit-include (prexcept=false) and
+ * EXCEPT (prexcept=true) rows for the same pubid. Scan until we find an
+ * explicit-include row, rather than relying on the first row's prexcept
+ * value.
+ */
2x typos /explicit-include/explicitly-included/
~~~
6.
+ /*
+ * GetTopMostAncestorInPublication() returns InvalidOid both when no
+ * ancestor matched at all, and when the root is excluded via EXCEPT.
+ * Disambiguate here: if the root is excluded, the partition is never
+ * published through this publication, regardless of whether the
+ * partition's own schema is separately included.
+ */
When you say "the partition's own schema", it seems to be viewed
through the lens of FOR TABLES IN SCHEMA, but the partition could also
be explicitly included (e.g. FOR TABLE xxx).
IOW, does "own schema" need to be mentioned, or can that last sentence
say "regardless of whether the partition is separately included".
~~~
7.
+ *
+ * A pg_publication_rel row with prexcept=true means the table is
+ * explicitly excluded via EXCEPT and must not be reported as published,
+ * even if its schema is otherwise included. A row with prexcept=false
+ * means it is explicitly included. If no pg_publication_rel row exists,
+ * the table is published iff its schema appears in
+ * pg_publication_namespace.
Again, this comment seems viewed the the lens of FOR TABLES IN SCHEMA.
That last part, ("If no pg_publication_rel row exists, the table is
published iff its schema appears in pg_publication_namespace."), seems
not quite correct. For example, a table can be published by a FOR ALL
TABLES publication, which has nothing in pg_publication_namespace at
all.
======
src/backend/commands/publicationcmds.c
CheckExceptNotInTableList:
8.
/*
* Check that no relation in except_rels is also present in explicitrelids,
* the list of OIDs added to the publication by the explicit TABLE list. A
* table cannot be both explicitly published and excluded in the same DDL.
*
* Also check that no relation in explicitrelids is a partition whose
* partition root is in except_rels; that would leave the catalog
* inconsistent (root excluded, partition explicitly included) with the
* ancestor-cascade rule silently overriding the include at replication
* time.
The wording like "Check that no relation..." is a bit hard to read.
SUGGESTION
Check that a table is not both excluded and published in the same DDL.
An excluded relation (except_rels) cannot also be present in
explicitrelids, the list of OIDs added to the publication by the
explicit TABLE list.
Also reject any relation in explicitrelids whose partition root is in
except_rels. Otherwise the catalog would be inconsistent (root
excluded, partition explicitly included), and the ancestor-cascade
rule would silently override the include at replication time.
~~~
9.
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("partition \"%s\" cannot be both published and excluded",
+ quote_qualified_identifier(get_namespace_name(get_rel_namespace(explicitrelid)),
+ get_rel_name(explicitrelid))),
+ errdetail("Ancestor \"%s\" is also being excluded by this same command.",
+ RelationGetQualifiedRelationName(pri->relation))));
Hmm. Elsewhere there was an errdetail worded like:
errdetail("Ancestor \"%s\" of partition \"%s\" is currently listed in
the EXCEPT clause of the publication.",
Maybe they should both use that wording.
======
src/backend/replication/pgoutput/pgoutput.c
get_rel_sync_entry:
10.
+ /*
+ * GetTopMostAncestorInPublication() itself skips
+ * schema-based ancestor matches when the partition root
+ * is excluded via this publication's EXCEPT clause.
+ */
ancestor = GetTopMostAncestorInPublication(pub->oid,
ancestors,
&level);
I'm not sure if that comment is helpful here or not. Why is the caller
describing the inner logic of the function it is calling?
~~~
11.
+ Oid root_relid;
+ HeapTuple tup;
+ bool is_except = false;
Given how this is used, maybe `root_is_except` is a better var name.
~~~
12.
+ /*
+ * schemaPubids is relid's own schema, independent of the
+ * ancestor walk above -- a partition can live in a
+ * different schema than its root. Still need to check
+ * for exclusion here, using the top-most ancestor since
+ * only a root (non-partition) table can appear in an
+ * EXCEPT clause.
+ */
I don't know what "schemaPubids is relid's own schema" means. AFAIK
the `schemaPubids` was a list of publications this schemas is a member
of (??).
======
src/test/regress/sql/publication.sql
13.
+-- fail: partition still rejected from EXCEPT even when its own root is also
+-- named in the same EXCEPT list
+CREATE PUBLICATION testpub_except_partition_with_root
+ FOR TABLES IN SCHEMA pub_test EXCEPT (TABLE
pub_test.testpub_part_s, TABLE pub_test.testpub_parted_s);
+
Is this test needed? Isn't the previous test ("only root tables are
allowed") covering this?
Alternatively, consider to put the partition in a different schema
(e.g. see the review comment #15 just below)
~~~
14.
+-- fail: same contradiction (explicit partition + EXCEPT-ed ancestor), but
+-- given in a single statement instead of two separate ones; the ancestor's
+-- EXCEPT row doesn't exist in the catalog yet when the explicit partition is
+-- validated, so this must be caught by comparing the in-memory lists
All that "; the ancestor's EXCEPT ..." is more like some explanation
about internals, and nothing really to do with the test case, so I was
not sure it needs to be in this comment.
~~~
15.
+-- test for EXCEPT clause with schema publication, where the excluded root's
+-- partition lives in a different schema that is separately, fully included
+-- (no EXCEPT) in the same publication. The root's exclusion must cascade to
+-- the partition regardless of the partition's own schema membership.
+CREATE SCHEMA gpt_cross_sch1;
+CREATE SCHEMA gpt_cross_sch2;
+CREATE TABLE gpt_cross_sch1.croot (id int) PARTITION BY RANGE (id);
+CREATE TABLE gpt_cross_sch2.cpart1 PARTITION OF gpt_cross_sch1.croot
FOR VALUES FROM (1) TO (10);
+
+SET client_min_messages = 'ERROR';
+CREATE PUBLICATION pub_cross_schema_except FOR TABLES IN SCHEMA
gpt_cross_sch1 EXCEPT (TABLE gpt_cross_sch1.croot), TABLES IN SCHEMA
gpt_cross_sch2;
IIUC, a different way to do this test would be to name the partition explicitly:
CREATE PUBLICATION pub_cross_schema_except FOR TABLES IN SCHEMA
gpt_cross_sch1 EXCEPT (TABLE gpt_cross_sch1.croot), TABLE
gpt_cross_sch2.cpart1;
Is it worth adding this way as well?
======
src/test/subscription/t/037_except.pl
16.
+$node_publisher->safe_psql('postgres',
+ "CREATE PUBLICATION cross_sch_pub FOR TABLES IN SCHEMA csch1 EXCEPT
(TABLE csch1.croot), TABLES IN SCHEMA csch2"
Wondering if you should also say "WITH (publish_via_partition_root =
false)"... Even though it is the default maybe it helps to be more
explicitLy, since later you do try to insert directly into partitions
to see the effect.
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Hi Nisha.
Here are my review comments for all the rest of the v20* patches
//////////
Patch v20-0002.
//////////
======
Commit message.
1.
entries, build a sorted signature per schema OID, and compare it
against any prior mention of the same schema in the same statement,
erroring on a mismatch.
~
It does more than that though -- it also checks there are no clashes
of the same schema with/without EXCEPT.
======
src/backend/commands/publicationcmds.c
ProcessSchemaExceptTables:
2.
+ * Also rejects a repeated mention of the same schema in the same TABLES IN
+ * SCHEMA list if either mention specifies a non-empty EXCEPT list, without
+ * checking whether the two EXCEPT lists actually name the same tables. This
+ * mirrors OpenTableList()'s handling of repeated tables with column lists
+ * (e.g. "FOR TABLE t1(a), t1(a)" is rejected even though the lists match):
+ * two mentions of the same schema wouldn't have a well-defined single
+ * EXCEPT list to enforce, so it's rejected as conflicting or redundant
+ * rather than silently unioned or compared for equivalence.
+ * *schemas_with_except accumulates the OIDs of schemas already seen with a
+ * non-empty EXCEPT list in this statement.
Some rewording might be needed. The "if either" and "the two" make it
sound like there are only 2 members in the schema list, but there
might be many schemas:
e.g. FOR TABLES IN SCHEMA S1,S1,S1,S1,S1,S1,S1,S1,S1,S1;
~~~
3.
Something about this logic seems over-complicated to me.
e.g. All this stuff about `schema_repeated`?
AFAICT, you only need to be accumulating 2 lists
- list1 = schemas without EXCEPT
- list2 = schemas with EXCEPT
To check conflicting the logic is simple:
- before adding to list1 ensure same schema is not already in list2, else error
- before adding to list2 ensure same schema is not already in list1, else error
Those checks can be done before you verify the qualified schema names
match their schema...
======
src/backend/parser/gram.y
4.
/*
* Process pubobjspec_list to check for errors in any of the objects and
* convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
- * Also flattens except_tables from TABLES IN SCHEMA nodes into the list so
- * that ObjectsInPublicationToOids() sees them as top-level
EXCEPT_TABLE entries.
+ * The except_tables attached to TABLES IN SCHEMA nodes are left in place here;
+ * ObjectsInPublicationToOids() qualifies their names, validates schema
+ * membership, and merges the qualified tables into its except_pubtables
+ * output list once the schema OID is known.
*/
Maybe add a blank line before the new text here.
//////////
Patch v20-0003.
//////////
======
src/test/regress/sql/publication.sql
1.
+-- fail: partition still rejected from EXCEPT even when its own root is also
+-- named in the same EXCEPT list, via ALTER ... ADD
+ALTER PUBLICATION testpub_alter_except
+ ADD TABLES IN SCHEMA pub_test EXCEPT (TABLE
pub_test.testpub_part_s, TABLE pub_test.testpub_parted_s);
+
Not sure how this test case differs from a plain-ol'
cannot-specify-a-partition-in-EXCEPT test case.
//////////
Patch v20-0004
//////////
======
src/backend/commands/publicationcmds.c
AlterPublicationSchemaExceptTables:
1.
+ /*
+ * Validate that no excluded table is also already explicitly
+ * published (exact match), and that no already-published partition
+ * has its root among the tables being newly excluded here.
+ */
The comment seems to be over-explaining the logic of the function it is calling.
How about something simpler.
SUGGESTION
Check that there is no clash between what tables are included and excluded.
~~~
PublicationDropTables:
2.
+ if (is_except)
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("cannot drop table \"%s\" from publication \"%s\"",
+ RelationGetQualifiedRelationName(rel),
+ get_publication_name(pubid, false)),
+ errdetail("The table is currently listed in the EXCEPT clause of the
publication."),
+ errhint("Use ALTER PUBLICATION ... SET TABLES IN SCHEMA ... EXCEPT
to drop the table from the EXCEPT list.")));
+
This new errhint makes more sense, but I felt it's more natural to say
you are "removing" something from a list, not "dropping" something
from a list.
So:
SUGGESTION #1
Use ALTER PUBLICATION ... SET TABLES IN SCHEMA ... EXCEPT to remove a
table from the EXCEPT list.
or, more generically:
SUGGESTION #2
Use ALTER PUBLICATION ... SET TABLES IN SCHEMA ... EXCEPT to modify
the EXCEPT list.
//////////
Patch v20-0005 (docs)
//////////
======
doc/src/sgml/ref/create_publication.sgml
For partitioned tables, only the root partitioned table may be specified
- in EXCEPT. Doing so excludes the root table and
- all of its partitions from replication. The optional
+ in EXCEPT. Excluding the root table automatically
+ excludes all of its partitions from replication, including those in
+ schemas that are otherwise included in the publication. The optional
ONLY and * has no effect for
partitioned tables.
In hindsight, I thought it would seem weird to have the word
"including" in the sentence where you are trying to describe excluded
tables.
/including those/even those/
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Mon, Jul 13, 2026 at 3:31 PM shveta malik wrote:
>
> On Fri, Jul 10, 2026 at 5:07 PM Nisha Moond wrote:
> >
> >
> > Yes, that works for me as we have FOR TABLES example to follow. I've
> > made the changes in v20.
> >
>
> Thanks! I had a quick look, few initial comments:
>
>
> 1)
> GetTopMostAncestorInPublication():
>
> + if (ancestors == NIL)
> + return InvalidOid;
>
> Should this be Assert or can there be a case where ancestors list can
> come as NIL?
>
I found one case where ancestors can be NIL.
Test case:
CREATE TABLE t1 (a int) PARTITION BY RANGE (a);
CREATE TABLE t1_part PARTITION OF t1 FOR VALUES FROM (1) TO (100);
CREATE PUBLICATION mypub FOR TABLE t1;
-- Get the partition into the pending-detach state:
-- Session A:
BEGIN;
SELECT * FROM t1;
-- leave open
-- Session B (blocks, waiting on Session A's lock on t1):
ALTER TABLE t1 DETACH PARTITION t1_part CONCURRENTLY;
-- Session C, while B is blocked:
SELECT * FROM pg_get_publication_tables('{mypub}'::text[],
't1_part'::regclass);
In this scenario, Session C reaches GetTopMostAncestorInPublication()
with ancestors == NIL. So I think we should keep return InvalidOid;
rather than replacing it with an Assert.
While investigating this race, I also hit assertions at places that
call "llast_oid(ancestors)" without checking for NIL, for example in
check_publication_add_relation() and RelationBuildPublicationDesc(). I
fixed those by guarding with if (ancestors != NIL).
But due to this same race, other existing callers of llast_oid() on
HEAD that assume ancestors is never NIL can also hit the following
assertion:
"TRAP: failed Assert("list != NIL"), File:
"../../../../src/include/nodes/pg_list.h" ..."
One such case is pgoutput.c:get_rel_sync_entry(). To reproduce on HEAD:
-- create a slot
SELECT pg_create_logical_replication_slot('myslot', 'pgoutput');
-- get the partition into the pending-detach state (using same A & B
sessions), and in session C run -
INSERT INTO t1_part VALUES (5);
SELECT * FROM pg_logical_slot_get_binary_changes('myslot', NULL, NULL,
'proto_version', '1', 'publication_names', 'mypub');
I think this should be handled separately after analyzing whether
there's a better fix than simply adding if (ancestors != NIL) guards
at each call site.
Note: Other callers of llast_oid(ancestors) may need similar review.
Thoughts?
> 2)
> GetAllSchemaPublicationRelations
>
> + if (!excluded && get_rel_relispartition(relid))
> + {
> + List *ancestors = get_partition_ancestors(relid);
> + ListCell *alc;
> +
> + foreach(alc, ancestors)
> + {
> + if (list_member_oid(except_relids, lfirst_oid(alc)))
> + {
> + excluded = true;
> + break;
> + }
> + }
> + list_free(ancestors);
> + }
>
> Should we check root only in except_relids instead of complete ancestor chain?
>
yes, corrected.
> 3)
> postgres=# ALTER TABLE s2.tab_root_new ATTACH PARTITION s2.tab_root
> FOR VALUES FROM (1) TO (2000);
> ERROR: 55000: cannot attach table "tab_root" as partition because it
> is referenced in publication "pub1" EXCEPT clause
> DETAIL: The publication EXCEPT clause cannot contain tables that are
> partitions.
> HINT: Change the publication's EXCEPT clause using ALTER PUBLICATION
> ... SET ALL TABLES.
> LOCATION: ATExecAttachPartition, tablecmds.c:21107
>
> pub1 is a schmea publication table here, I think HINT needs some adjustment.
>
Fixed.
> 4)
> + root_tup = SearchSysCache2(PUBLICATIONRELMAP,
> + ObjectIdGetDatum(llast_oid(ancestors)),
> + ObjectIdGetDatum(pub->oid));
> + if (HeapTupleIsValid(root_tup))
> + {
> + bool root_except = ((Form_pg_publication_rel) GETSTRUCT(root_tup))->prexcept;
> +
> + ReleaseSysCache(root_tup);
> + if (root_except)
> + return false;
> + }
>
> Above code snipet appears a lot many times either for relid or
> llast_oid(ancestors), can we replace this with a common function like:
>
> bool lookup_pub_relmap(Oid pubid, Oid relid, bool *is_except); (or
> get_publication_rel_entry or anything which you find better)
>
> The return value will indicate when the relid is present. 'is_except'
> will indicate whetehr it is marked with except flag or not. Then above
> can be replaced with:
>
> if (lookup_pub_relmap(pub->oid, llast_oid(ancestors), &root_except)
> && root_except)
> return false;
>
> Do this only if you feel it will simplify the code and apply it where it helps.
>
You're right. The same check appears in five places. I replaced it
with a helper function, get_publication_rel_entry(), which
significantly reduces code duplication.
~~~
Attached is the v21 patch set addressing the above changes, along with
all other comments for v20 at [1], [2], and [3].
[1] https://www.postgresql.org/message-id/CAJpy0uCFCdL97L3Pt8f586br5irqkzCa_i3tXMjH6JFCPxxr4Q%40mail.gmail.com
[2] https://www.postgresql.org/message-id/CAHut%2BPuJE947Y3WPo%2BcaEpEojQdRXryS2KjBLBr12rb9RQ95Zw%40mail.gmail.com
[3] https://www.postgresql.org/message-id/CAHut%2BPsGg7Pi2CM5eBjb8s6FCPb5XmyWaBUxPrDSzt_2wK4Gfg%40mail.gmail.com
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Wed, Jul 15, 2026 at 10:19 AM Peter Smith wrote:
>
> Some review comments for v20-0001.
>
Thanks for review. All suggestions are incorporated. Please find
responses for few below.
> ~~~
>
> 6.
> + /*
> + * GetTopMostAncestorInPublication() returns InvalidOid both when no
> + * ancestor matched at all, and when the root is excluded via EXCEPT.
> + * Disambiguate here: if the root is excluded, the partition is never
> + * published through this publication, regardless of whether the
> + * partition's own schema is separately included.
> + */
>
> When you say "the partition's own schema", it seems to be viewed
> through the lens of FOR TABLES IN SCHEMA, but the partition could also
> be explicitly included (e.g. FOR TABLE xxx).
>
> IOW, does "own schema" need to be mentioned, or can that last sentence
> say "regardless of whether the partition is separately included".
>
I think it is better to view this through the lens of FOR TABLES IN
SCHEMA, since a partition cannot be included by any other means if its
root is excluded.
My intent with this comment is to clarify that a partition should not
be assumed to be included simply because its schema is included --
hence the additional check.
I reworded it as: "regardless of whether the partition's schema is
separately included".
> ~~~
>
> 7.
> + *
> + * A pg_publication_rel row with prexcept=true means the table is
> + * explicitly excluded via EXCEPT and must not be reported as published,
> + * even if its schema is otherwise included. A row with prexcept=false
> + * means it is explicitly included. If no pg_publication_rel row exists,
> + * the table is published iff its schema appears in
> + * pg_publication_namespace.
>
> Again, this comment seems viewed the the lens of FOR TABLES IN SCHEMA.
>
> That last part, ("If no pg_publication_rel row exists, the table is
> published iff its schema appears in pg_publication_namespace."), seems
> not quite correct. For example, a table can be published by a FOR ALL
> TABLES publication, which has nothing in pg_publication_namespace at
> all.
>
IIUC, we reach this code only for non-FOR ALL TABLES publications,
since the pub->alltables case is handled before reaching here.
Therefore, the pointed "last part" of comment holds true. Please
correct me if I'm missing another scenario where this would not be the
case.
>
> ======
> src/backend/replication/pgoutput/pgoutput.c
>
> get_rel_sync_entry:
>
> 10.
> + /*
> + * GetTopMostAncestorInPublication() itself skips
> + * schema-based ancestor matches when the partition root
> + * is excluded via this publication's EXCEPT clause.
> + */
> ancestor = GetTopMostAncestorInPublication(pub->oid,
> ancestors,
> &level);
>
> I'm not sure if that comment is helpful here or not. Why is the caller
> describing the inner logic of the function it is calling?
I missed removing the comment during the recent code optimization.
It's removed now.
>
> ~~~
> ~~~
>
> 12.
> + /*
> + * schemaPubids is relid's own schema, independent of the
> + * ancestor walk above -- a partition can live in a
> + * different schema than its root. Still need to check
> + * for exclusion here, using the top-most ancestor since
> + * only a root (non-partition) table can appear in an
> + * EXCEPT clause.
> + */
>
> I don't know what "schemaPubids is relid's own schema" means. AFAIK
> the `schemaPubids` was a list of publications this schemas is a member
> of (??).
>
Correct. Reworded the comment as: "schemaPubids is the list of
publications that include relid's schema..."
> ======
> src/test/regress/sql/publication.sql
>
> 13.
> +-- fail: partition still rejected from EXCEPT even when its own root is also
> +-- named in the same EXCEPT list
> +CREATE PUBLICATION testpub_except_partition_with_root
> + FOR TABLES IN SCHEMA pub_test EXCEPT (TABLE
> pub_test.testpub_part_s, TABLE pub_test.testpub_parted_s);
> +
>
> Is this test needed? Isn't the previous test ("only root tables are
> allowed") covering this?
>
Okay, makes sense. I've removed it.
> Alternatively, consider to put the partition in a different schema
> (e.g. see the review comment #15 just below)
Added a test case covering the cross-schema failure scenario.
>
> ~~~
>
> 15.
> +-- test for EXCEPT clause with schema publication, where the excluded root's
> +-- partition lives in a different schema that is separately, fully included
> +-- (no EXCEPT) in the same publication. The root's exclusion must cascade to
> +-- the partition regardless of the partition's own schema membership.
> +CREATE SCHEMA gpt_cross_sch1;
> +CREATE SCHEMA gpt_cross_sch2;
> +CREATE TABLE gpt_cross_sch1.croot (id int) PARTITION BY RANGE (id);
> +CREATE TABLE gpt_cross_sch2.cpart1 PARTITION OF gpt_cross_sch1.croot
> FOR VALUES FROM (1) TO (10);
> +
> +SET client_min_messages = 'ERROR';
> +CREATE PUBLICATION pub_cross_schema_except FOR TABLES IN SCHEMA
> gpt_cross_sch1 EXCEPT (TABLE gpt_cross_sch1.croot), TABLES IN SCHEMA
> gpt_cross_sch2;
>
> IIUC, a different way to do this test would be to name the partition explicitly:
> CREATE PUBLICATION pub_cross_schema_except FOR TABLES IN SCHEMA
> gpt_cross_sch1 EXCEPT (TABLE gpt_cross_sch1.croot), TABLE
> gpt_cross_sch2.cpart1;
>
> Is it worth adding this way as well?
>
This test is intended to verify pg_get_publication_tables() for the
case where a partition's schema is included, but the partition itself
should not appear in the publication.
The suggested command would not cover that code path. That said, I
agree that explicitly adding such a partition should also fail, so
I've added a failure test under the "EXCEPT tests for TABLES IN
SCHEMA" section.
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Wed, Jul 15, 2026 at 2:13 PM Peter Smith wrote: > > Hi Nisha. > > Here are my review comments for all the rest of the v20* patches > Thanks for the review. I've addressed all the comments as suggested in v21. > > 3. > Something about this logic seems over-complicated to me. > > e.g. All this stuff about `schema_repeated`? > > AFAICT, you only need to be accumulating 2 lists > - list1 = schemas without EXCEPT > - list2 = schemas with EXCEPT > > To check conflicting the logic is simple: > - before adding to list1 ensure same schema is not already in list2, else error > - before adding to list2 ensure same schema is not already in list1, else error > > Those checks can be done before you verify the qualified schema names > match their schema... > After addressing Shveta's comments in [1], the function is much simpler. I also adjusted the if conditions to improve readability. Please let me know if this looks acceptable or if you see further opportunities for improvement. [1] https://www.postgresql.org/message-id/CAJpy0uCFCdL97L3Pt8f586br5irqkzCa_i3tXMjH6JFCPxxr4Q%40mail.gmail.com -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Wed, Jul 15, 2026 at 10:16 PM Nisha Moond wrote:
>
> On Mon, Jul 13, 2026 at 3:31 PM shveta malik wrote:
> >
> > On Fri, Jul 10, 2026 at 5:07 PM Nisha Moond wrote:
> > >
> > >
> > > Yes, that works for me as we have FOR TABLES example to follow. I've
> > > made the changes in v20.
> > >
> >
> > Thanks! I had a quick look, few initial comments:
> >
> >
> > 1)
> > GetTopMostAncestorInPublication():
> >
> > + if (ancestors == NIL)
> > + return InvalidOid;
> >
> > Should this be Assert or can there be a case where ancestors list can
> > come as NIL?
> >
>
> I found one case where ancestors can be NIL.
> Test case:
> CREATE TABLE t1 (a int) PARTITION BY RANGE (a);
> CREATE TABLE t1_part PARTITION OF t1 FOR VALUES FROM (1) TO (100);
> CREATE PUBLICATION mypub FOR TABLE t1;
>
> -- Get the partition into the pending-detach state:
> -- Session A:
> BEGIN;
> SELECT * FROM t1;
> -- leave open
>
> -- Session B (blocks, waiting on Session A's lock on t1):
> ALTER TABLE t1 DETACH PARTITION t1_part CONCURRENTLY;
>
> -- Session C, while B is blocked:
> SELECT * FROM pg_get_publication_tables('{mypub}'::text[],
> 't1_part'::regclass);
>
> In this scenario, Session C reaches GetTopMostAncestorInPublication()
> with ancestors == NIL. So I think we should keep return InvalidOid;
> rather than replacing it with an Assert.
>
> While investigating this race, I also hit assertions at places that
> call "llast_oid(ancestors)" without checking for NIL, for example in
> check_publication_add_relation() and RelationBuildPublicationDesc(). I
> fixed those by guarding with if (ancestors != NIL).
Okay, I will review.
> But due to this same race, other existing callers of llast_oid() on
> HEAD that assume ancestors is never NIL can also hit the following
> assertion:
> "TRAP: failed Assert("list != NIL"), File:
> "../../../../src/include/nodes/pg_list.h" ..."
>
> One such case is pgoutput.c:get_rel_sync_entry(). To reproduce on HEAD:
> -- create a slot
> SELECT pg_create_logical_replication_slot('myslot', 'pgoutput');
>
> -- get the partition into the pending-detach state (using same A & B
> sessions), and in session C run -
> INSERT INTO t1_part VALUES (5);
> SELECT * FROM pg_logical_slot_get_binary_changes('myslot', NULL, NULL,
> 'proto_version', '1', 'publication_names', 'mypub');
>
> I think this should be handled separately after analyzing whether
> there's a better fix than simply adding if (ancestors != NIL) guards
> at each call site.
> Note: Other callers of llast_oid(ancestors) may need similar review.
>
> Thoughts?
>
Nisha, I am not able to reproduce this on HEAD. Can you please verify
if you missed providing any steps? This I what I have tried:
Session1:
postgres=# SELECT pg_create_logical_replication_slot('myslot', 'pgoutput');
pg_create_logical_replication_slot
------------------------------------
(myslot,0/0178F5B8)
(1 row)
postgres=# CREATE TABLE t1 (a int) PARTITION BY RANGE (a);
CREATE TABLE t1_part PARTITION OF t1 FOR VALUES FROM (1) TO (100);
CREATE PUBLICATION mypub FOR TABLE t1;
CREATE TABLE
CREATE TABLE
CREATE PUBLICATION
Session2:
postgres=# BEGIN;
SELECT * FROM t1;
BEGIN
a
---
(0 rows)
Session3:
postgres=# ALTER TABLE t1 DETACH PARTITION t1_part CONCURRENTLY;
Session4:
postgres=# INSERT INTO t1_part VALUES (5);
SELECT * FROM pg_logical_slot_get_binary_changes('myslot', NULL, NULL,
'proto_version', '1', 'publication_names', 'mypub');
INSERT 0 1
lsn | xid | data
-----+-----+------
(0 rows)
thanks
Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Thu, Jul 16, 2026 at 10:15 AM shveta malik wrote:
>
> On Wed, Jul 15, 2026 at 10:16 PM Nisha Moond wrote:
> >
> > On Mon, Jul 13, 2026 at 3:31 PM shveta malik wrote:
> > >
> > > On Fri, Jul 10, 2026 at 5:07 PM Nisha Moond wrote:
> > > >
> > > >
> > > > Yes, that works for me as we have FOR TABLES example to follow. I've
> > > > made the changes in v20.
> > > >
> > >
> > > Thanks! I had a quick look, few initial comments:
> > >
> > >
> > > 1)
> > > GetTopMostAncestorInPublication():
> > >
> > > + if (ancestors == NIL)
> > > + return InvalidOid;
> > >
> > > Should this be Assert or can there be a case where ancestors list can
> > > come as NIL?
> > >
> >
> > I found one case where ancestors can be NIL.
> > Test case:
> > CREATE TABLE t1 (a int) PARTITION BY RANGE (a);
> > CREATE TABLE t1_part PARTITION OF t1 FOR VALUES FROM (1) TO (100);
> > CREATE PUBLICATION mypub FOR TABLE t1;
> >
> > -- Get the partition into the pending-detach state:
> > -- Session A:
> > BEGIN;
> > SELECT * FROM t1;
> > -- leave open
> >
> > -- Session B (blocks, waiting on Session A's lock on t1):
> > ALTER TABLE t1 DETACH PARTITION t1_part CONCURRENTLY;
> >
> > -- Session C, while B is blocked:
> > SELECT * FROM pg_get_publication_tables('{mypub}'::text[],
> > 't1_part'::regclass);
> >
> > In this scenario, Session C reaches GetTopMostAncestorInPublication()
> > with ancestors == NIL. So I think we should keep return InvalidOid;
> > rather than replacing it with an Assert.
> >
> > While investigating this race, I also hit assertions at places that
> > call "llast_oid(ancestors)" without checking for NIL, for example in
> > check_publication_add_relation() and RelationBuildPublicationDesc(). I
> > fixed those by guarding with if (ancestors != NIL).
>
> Okay, I will review.
>
> > But due to this same race, other existing callers of llast_oid() on
> > HEAD that assume ancestors is never NIL can also hit the following
> > assertion:
> > "TRAP: failed Assert("list != NIL"), File:
> > "../../../../src/include/nodes/pg_list.h" ..."
> >
> > One such case is pgoutput.c:get_rel_sync_entry(). To reproduce on HEAD:
> > -- create a slot
> > SELECT pg_create_logical_replication_slot('myslot', 'pgoutput');
> >
> > -- get the partition into the pending-detach state (using same A & B
> > sessions), and in session C run -
> > INSERT INTO t1_part VALUES (5);
> > SELECT * FROM pg_logical_slot_get_binary_changes('myslot', NULL, NULL,
> > 'proto_version', '1', 'publication_names', 'mypub');
> >
> > I think this should be handled separately after analyzing whether
> > there's a better fix than simply adding if (ancestors != NIL) guards
> > at each call site.
> > Note: Other callers of llast_oid(ancestors) may need similar review.
> >
> > Thoughts?
> >
>
> Nisha, I am not able to reproduce this on HEAD. Can you please verify
> if you missed providing any steps? This I what I have tried:
>
> Session1:
> postgres=# SELECT pg_create_logical_replication_slot('myslot', 'pgoutput');
> pg_create_logical_replication_slot
> ------------------------------------
> (myslot,0/0178F5B8)
> (1 row)
>
> postgres=# CREATE TABLE t1 (a int) PARTITION BY RANGE (a);
> CREATE TABLE t1_part PARTITION OF t1 FOR VALUES FROM (1) TO (100);
> CREATE PUBLICATION mypub FOR TABLE t1;
> CREATE TABLE
> CREATE TABLE
> CREATE PUBLICATION
>
> Session2:
> postgres=# BEGIN;
> SELECT * FROM t1;
> BEGIN
> a
> ---
> (0 rows)
>
> Session3:
> postgres=# ALTER TABLE t1 DETACH PARTITION t1_part CONCURRENTLY;
>
>
> Session4:
> postgres=# INSERT INTO t1_part VALUES (5);
> SELECT * FROM pg_logical_slot_get_binary_changes('myslot', NULL, NULL,
> 'proto_version', '1', 'publication_names', 'mypub');
> INSERT 0 1
> lsn | xid | data
> -----+-----+------
> (0 rows)
>
A zero-row result indicates the INSERT wasn't decoded, so seems
get_rel_sync_entry() wasn't reached. Sorry for the ambiguous test
steps -- the slot creation order matters.
Please follow these steps to reproduce the issue on HEAD:
Session1:
CREATE TABLE t1 (a int) PARTITION BY RANGE (a);
CREATE TABLE t1_part PARTITION OF t1 FOR VALUES FROM (1) TO (100);
CREATE PUBLICATION mypub FOR ALL TABLES;
SELECT pg_create_logical_replication_slot('myslot', 'pgoutput');
Session 2:
BEGIN;
SELECT * FROM t1;
-- leave open
Session 3 (hangs):
ALTER TABLE t1 DETACH PARTITION t1_part CONCURRENTLY;
Session 4, while 3 is blocked:
INSERT INTO t1_part VALUES (5);
SELECT * FROM pg_logical_slot_get_binary_changes('myslot', NULL,
NULL, 'proto_version', '1', 'publication_names', 'mypub');
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Thu, Jul 16, 2026 at 11:14 AM Nisha Moond wrote:
>
> A zero-row result indicates the INSERT wasn't decoded, so seems
> get_rel_sync_entry() wasn't reached. Sorry for the ambiguous test
> steps -- the slot creation order matters.
> Please follow these steps to reproduce the issue on HEAD:
>
> Session1:
> CREATE TABLE t1 (a int) PARTITION BY RANGE (a);
> CREATE TABLE t1_part PARTITION OF t1 FOR VALUES FROM (1) TO (100);
> CREATE PUBLICATION mypub FOR ALL TABLES;
> SELECT pg_create_logical_replication_slot('myslot', 'pgoutput');
>
> Session 2:
> BEGIN;
> SELECT * FROM t1;
> -- leave open
>
> Session 3 (hangs):
> ALTER TABLE t1 DETACH PARTITION t1_part CONCURRENTLY;
>
> Session 4, while 3 is blocked:
> INSERT INTO t1_part VALUES (5);
> SELECT * FROM pg_logical_slot_get_binary_changes('myslot', NULL,
> NULL, 'proto_version', '1', 'publication_names', 'mypub');
>
Okay thanks. I am able to reproduce the crash on HEAD now. We can
pursue this in separate thread. I am not immediately clear on the
solution yet. I think this is introduced by:
https://www.postgresql.org/message-id/E1lPX7q-0001lJ-NO%40gemulon.postgresql.org
it seems 'get_partition_parent' is changed to accept an arguement
'even_if_detached' to control whether caller wants detached partition
or should error-out but no such arguement in
get_partition_ancestors(). We can discuss this in separate thread.
thanks
Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Hi Nisha.
Some review comments for v21-0001.
======
src/backend/catalog/pg_publication.c
1.
+bool
+get_publication_rel_entry(Oid pubid, Oid relid, bool *is_except)
This is a bit like the 'is_table_publication' function and others.
Perhaps it should be moved nearer that one?
~~~
check_publication_add_relation:
2.
+ Oid relid = RelationGetRelid(targetrel);
+ Oid root;
+ bool root_except;
Those declarations can all be moved closer to where they are used.
~~~
3.
+ * A partition cannot be included when its partition root is in the
+ * same publication's EXCEPT list. Doing so would leave the catalog
+ * inconsistent (root excluded, partition included) and the
+ * ancestor-cascade rule would silently override the include at
+ * replication time.
Hmm. A single publication may have multiple EXCEPT clauses, but that
first sentence wording seems to be suggesting there is only one.
Perhaps better to say:
SUGGESTION
A partition cannot be included when its partition root is excluded by
the same publication.
~~~
4.
+ errdetail("Ancestor \"%s\" of partition \"%s\" is currently listed
in the EXCEPT clause of the publication.",
For the same reason (a publication may have multiple EXCEPT clauses, I
think this errdetail should change:
/the EXCEPT clause/an EXCEPT clause/
~~~
GetTopMostAncestorInPublication:
5.
+ * If the partition root (the last element of ancestors) is excluded from
+ * this publication via its EXCEPT clause, the partition is not published
+ * through this publication at all, so we short-circuit and return
+ * InvalidOid without walking the ancestor list. Only the root of a
Similar to above. Should not be singular "its EXCEPT clause".
/via its EXCEPT clause/via an EXCEPT clause/
~~~
6.
{
- table_close(rel, RowExclusiveLock);
+ bool is_except;
- if (if_not_exists)
- return InvalidObjectAddress;
-
- ereport(ERROR,
- (errcode(ERRCODE_DUPLICATE_OBJECT),
- errmsg("relation \"%s\" is already member of publication \"%s\"",
- RelationGetRelationName(targetrel), pub->name)));
+ if (get_publication_rel_entry(pubid, relid, &is_except))
+ {
...
+ }
}
I think having a code block like this just for the variable
declaration is unconventional for PG source code; it's not necessary
here, so maybe don't do it.
~~~
7.
+ errdetail("Ancestor \"%s\" of partition \"%s\" is currently listed
in the EXCEPT clause of the publication.",
+ quote_qualified_identifier(get_namespace_name(get_rel_namespace(root)),
Similar (singular) comment to before.
/in the EXCEPT clause/in an EXCEPT clause/
~~~
GetAllSchemaPublicationRelations:
8.
/*
* Gets the list of all relations published by FOR TABLES IN SCHEMA
- * publication.
+ * publication, excluding any tables listed in the EXCEPT clause.
*/
/EXCEPT clause./EXCEPT clauses./
~~~
9.
+ /* filter out any tables that appear in the EXCEPT list */
+ ListCell *rlc;
+
+ foreach(rlc, schemaRels)
+ {
+ Oid relid = lfirst_oid(rlc);
Isn't this loop something that can be simplified using foreach_oid macro?
~~~
10.
+ * A partition whose root is in the publication's EXCEPT list
+ * is also excluded, even if the partition itself lives in a
+ * different (included) schema. Only the topmost root of a
SUGGESTION #1
A partition whose root is in an EXCEPT list of the publication is also
excluded, even if...
SUGGESTION #2
A partition whose root is excluded from the publication is also
excluded, even if...
~~~
is_table_publishable_in_publication:
11.
+ {
+ bool is_except;
+
+ if (get_publication_rel_entry(pub->oid, relid, &is_except))
+ return !is_except;
+ }
Here is another code block which AFAIK is uncommon in PG source code.
IMO would be better to remove this and have a new function variable
`is_except`. You can also remove the other existing `root_except`
declaration because they can bother share this same var. So, the
result will be fewer vars, less unusual code blocks, less code.
======
src/backend/commands/tablecmds.c
12.
+ errhint("%s", has_alltables_pub ?
+ _("Change the publication's EXCEPT clause using ALTER PUBLICATION
... SET ALL TABLES ... EXCEPT.") :
+ _("Change the publication's EXCEPT clause using ALTER PUBLICATION
... SET TABLES IN SCHEMA ... EXCEPT.")));
12a.
The message wording is slightly broken now because there is potential
for even a single publication to have multiple EXCEPT clauses.
Here it might be OK to reword it like:
BEFORE
Change the publication's EXCEPT clause...
SUGGESTION
Change the EXCEPT clause...
~
12b.
Also, IMO the errmsg_plural might be better if reworded:
BEFORE
"cannot attach table \"%s\" as partition because it is referenced in
publication %s EXCEPT clause",
"cannot attach table \"%s\" as partition because it is referenced in
publications %s EXCEPT clause",
SUGGESTION
"cannot attach table \"%s\" as partition because it is referenced in
EXCEPT clause of publication %s",
"cannot attach table \"%s\" as partition because it is referenced in
EXCEPT clause of publications %s",
======
src/include/catalog/pg_publication.h
13.
+extern bool get_publication_rel_entry(Oid pubid, Oid relid, bool *is_except);
Do you think this function name should be CamelCase (more common for
non-static functions), instead of snake_case?
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
I have reviewed a portion of v21-001 yet. The comments so far: 1) check_publication_add_relation: + Oid relid = RelationGetRelid(targetrel); Please move this inside : + if (targetrel->rd_rel->relispartition) 2) Please shorten this comment: + /* + * If the partition root (the last element of ancestors) is excluded from + * this publication via its EXCEPT clause, the partition is not published + * through this publication at all, so we short-circuit and return + * InvalidOid without walking the ancestor list. Only the root of a + * partition hierarchy can ever appear in a publication's EXCEPT clause (a + * partition itself is rejected from EXCEPT elsewhere), so it's the only + * one worth a catalog lookup. + */ Suggestion: /* * If the partition root is excluded from this publication via its EXCEPT * clause, the partition is not published through this publication, so return * InvalidOid. Since only partition roots can appear in an EXCEPT clause, the * root is the only ancestor worth a catalog lookup. */ 3) postgres=# ALTER TABLE s2.tab_root_new ATTACH PARTITION s2.tab_root FOR VALUES FROM (1) TO (2000); ERROR: cannot attach table "tab_root" as partition because it is referenced in publication "pub1" EXCEPT clause DETAIL: The publication EXCEPT clause cannot contain tables that are partitions. HINT: Change the publication's EXCEPT clause using ALTER PUBLICATION ... SET TABLES IN SCHEMA ... EXCEPT. postgres=# ALTER publication pub1 add TABLE s2.tab_part_1_p2; ERROR: cannot add partition "s2.tab_part_1_p2" to publication "pub1" DETAIL: Ancestor "s2.tab_root" of partition "s2.tab_part_1_p2" is currently listed in the EXCEPT clause of the publication. HINT: Change EXCEPT list using ALTER PUBLICATION ... SET TABLES IN SCHEMA ... EXCEPT. Can we make HINT same? We can retain the wording of HINT given in ATTACH PARTITION case as that is existing one. 4) postgres=# create publication pub1 for tables in schema s2 except (table s2.tab_root), table s2.tab_part_2, table s2.tab_part_1_p2; ERROR: partition "s2.tab_part_2" cannot be both published and excluded DETAIL: Ancestor "s2.tab_root" of partition "s2.tab_part_2" is currently listed in the EXCEPT clause of this command. postgres=# ALTER publication pub1 add TABLE s2.tab_part_1_p2; ERROR: cannot add partition "s2.tab_part_1_p2" to publication "pub1" DETAIL: Ancestor "s2.tab_root" of partition "s2.tab_part_1_p2" is currently listed in the EXCEPT clause of the publication. HINT: Change EXCEPT list using ALTER PUBLICATION ... SET TABLES IN SCHEMA ... EXCEPT. Should the DETAIL be just: DETAIL: Partition root "s2.tab_root" is listed in the publication's EXCEPT clause. Thoughts? thanks Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Hi Nisha. I noticed multiple places where these patches want to discover the root partition table OID, but they are not interested in the ancestor tree. I've created another thread/patch [1] to introduce a `get_partition_root` C function. I think this could simplify some of your code by removing the requirement to declare and free the unwanted ancestor lists. Please take a look and give your +1 there if you think it would be useful. ====== [1] https://www.postgresql.org/message-id/CAHut%2BPtc73UpWSn4teMyMxQoHwGJjRwhWiu%3DhGJqAj5k2AOXEw%40mail.gmail.com Kind Regards, Peter Smith. Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Some review comments for v21-0002.
======
Commit message.
1.
Add ProcessSchemaExceptTables() to qualify each mention's EXCEPT
entries, build a sorted signature per schema OID, and compare it
against any prior mention of the same schema in the same statement,
erroring on a mismatch. It also checks there are no clashes of the
same schema with or without EXCEPT.
~
IMO it's too confusing to explain the implementation detail here
instead of the purpose. Also, it should say "with *and* without".
SUGGESTION
Add ProcessSchemaExceptTables(), which errors if the same schema is
mentioned more than once with EXCEPT, or both with and without EXCEPT.
It also checks that a schema's EXCEPT clause only lists tables from
that same schema.
======
src/backend/commands/publicationcmds.c
ProcessSchemaExceptTables:
2.
+/*
+ * Qualify unqualified EXCEPT table names with the given schema, reject
+ * entries explicitly qualified with a different schema, and append the (now
+ * qualified) tables to *except_pubtables.
+ *
+ * Also rejects a repeated mention of the same schema in the same TABLES IN
+ * SCHEMA list if it, or an earlier mention of the same schema, specified a
+ * non-empty EXCEPT list, without checking whether the EXCEPT lists across
+ * all the mentions actually name the same tables. This mirrors
+ * OpenTableList()'s handling of repeated tables with column lists (e.g.
+ * "FOR TABLE t1(a), t1(a)" is rejected even though the lists match):
+ * repeated mentions of the same schema wouldn't have a well-defined single
+ * EXCEPT list to enforce, so they're rejected as conflicting or redundant
+ * rather than silently unioned or compared for equivalence. A schema may
+ * still be mentioned multiple times as long as none of the mentions
+ * specify EXCEPT.
+ * *schemas_with_except accumulates the OIDs of schemas already seen with a
+ * non-empty EXCEPT list in this statement.
+ */
2a.
This function comment seems very complex. Here is a simpler version;
AFAICT it says the same:
SUGGESTION
/*
* Qualify unqualified EXCEPT table names with the given schema (rejecting
* any explicitly qualified with a different schema), and append them to
* *except_pubtables.
*
* Also rejects a schema being mentioned more than once with an EXCEPT
* clause, even if the EXCEPT lists are identical — much like
* OpenTableList() rejects "FOR TABLE t1(a), t1(a)" despite the column
* lists matching. A schema can still be mentioned multiple times, just
* not more than once with EXCEPT.
*
* *schemas_with_except tracks which schema OIDs have already been seen
* with an EXCEPT clause in this statement.
*/
~~
2b.
It would also be helpful to explain what the other parameters are.
IIUC, it is something like:
`*except_tables` = "the EXCEPT list (or NIL) for this schema"
`*schemas` = "the list of all schema OIDs seen so far for this statement"
~~~
3.
+ /*
+ * A repeat is only a problem if this mention has EXCEPT, or an earlier
+ * mention of the same schema did.
+ */
/A repeat is only a problem/A repeating schema is only a problem/
~~~
4.
+ /*
+ * A repeat is only a problem if this mention has EXCEPT, or an earlier
+ * mention of the same schema did.
+ */
+ if (list_member_oid(*schemas, schemaid))
+ {
+ if (except_tables != NIL ||
+ list_member_oid(*schemas_with_except, schemaid))
+ ereport(ERROR,
+ errcode(ERRCODE_DUPLICATE_OBJECT),
+ errmsg("conflicting or redundant EXCEPT lists for schema \"%s\"",
+ schema_name));
+ }
+
+ if (except_tables != NIL)
+ *schemas_with_except = lappend_oid(*schemas_with_except, schemaid);
+
+ /* Filter out duplicates if the user specifies "sch1, sch1" */
+ *schemas = list_append_unique_oid(*schemas, schemaid);
+
+ if (except_tables == NIL)
+ return;
All the except_tables checks are making this code harder to read than
it needs to be. How about having another variable:
bool schema_has_except = (except_tables != NIL);
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
One more v21* review comment...
1.
@@ -6838,6 +6838,24 @@ describePublications(const char *pattern)
if (!addFooterToPublicationDesc(&buf, _("Tables from schemas:"),
true, &cont))
goto error_return;
+
+ if (pset.sversion >= 190000)
+ {
+ /*
+ * Get tables in the EXCEPT clause for this schema
+ * publication.
+ */
The SCHEMA EXCEPT does not exist in PG19, so shouldn't that version
check be 200000?
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Fri, Jul 17, 2026 at 9:50 AM Peter Smith wrote: > > Hi Nisha. > > I noticed multiple places where these patches want to discover the > root partition table OID, but they are not interested in the ancestor > tree. > > I've created another thread/patch [1] to introduce a > `get_partition_root` C function. I think this could simplify some of > your code by removing the requirement to declare and free the unwanted > ancestor lists. > > Please take a look and give your +1 there if you think it would be useful. > Okay, the idea looks reasonable to me. I'll review the patch and share my thoughts on the thread. -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Thu, Jul 16, 2026 at 2:04 PM Peter Smith wrote:
>
> Hi Nisha.
>
> Some review comments for v21-0001.
>
Thanks for the review. I've applied all the suggestions in v22.
> ~~~
>
> 7.
> + errdetail("Ancestor \"%s\" of partition \"%s\" is currently listed
> in the EXCEPT clause of the publication.",
> + quote_qualified_identifier(get_namespace_name(get_rel_namespace(root)),
>
> Similar (singular) comment to before.
>
> /in the EXCEPT clause/in an EXCEPT clause/
>
It looks like comment #4 is repeated here. In any case, I addressed
both occurrences of the errdetail (in check_publication_add_relation()
and CheckExceptNotInTableList()):
"Ancestor \"%s\" of partition \"%s\" is curre..".
> ~~~
> 9.
> + /* filter out any tables that appear in the EXCEPT list */
> + ListCell *rlc;
> +
> + foreach(rlc, schemaRels)
> + {
> + Oid relid = lfirst_oid(rlc);
>
> Isn't this loop something that can be simplified using foreach_oid macro?
>
Yes, that's possible. I've simplified it.
> ~~~
>
> 10.
> + * A partition whose root is in the publication's EXCEPT list
> + * is also excluded, even if the partition itself lives in a
> + * different (included) schema. Only the topmost root of a
>
> SUGGESTION #1
> A partition whose root is in an EXCEPT list of the publication is also
> excluded, even if...
>
> SUGGESTION #2
> A partition whose root is excluded from the publication is also
> excluded, even if...
>
Changed as per SUGGESTION #2.
> ======
> src/include/catalog/pg_publication.h
>
> 13.
> +extern bool get_publication_rel_entry(Oid pubid, Oid relid, bool *is_except);
>
> Do you think this function name should be CamelCase (more common for
> non-static functions), instead of snake_case?
>
I kept it consistent with the nearby functions, but I agree, it should
use CamelCase for a non-static function.
~~~
Attached is the v22 patch set. Also incorporated all the other
suggestions and feedback from Shveta and Peter at [1], [2], [3], and
[4].
[1] https://www.postgresql.org/message-id/CAJpy0uCj8NdSuWSWkn8iGriz1D1i1g-rMLs9Fk8SEf8uWs60ww%40mail.gmail.com
[2] https://www.postgresql.org/message-id/CAHut%2BPsqq%3DNT%3DbhuKtqTU%2B0esbk2cxhxPYp3jjn3KTR%2BL4wc9w%40mail.gmail.com
[3] https://www.postgresql.org/message-id/CAHut%2BPuA8YUdqMLS9QjU991bb6N1i5Eo9gq5wUzA7WJbG4FB3g%40mail.gmail.com
[4] https://www.postgresql.org/message-id/CAHut%2BPvCeJ6yDdRu3Qo7-M5fMzZnV1aEDPckW3oLmgY4xPw3HA%40mail.gmail.com
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Fri, Jul 17, 2026 at 1:37 PM Peter Smith wrote: > > Some review comments for v21-0002. > > ====== > Commit message. > > 1. > Add ProcessSchemaExceptTables() to qualify each mention's EXCEPT > entries, build a sorted signature per schema OID, and compare it > against any prior mention of the same schema in the same statement, > erroring on a mismatch. It also checks there are no clashes of the > same schema with or without EXCEPT. > > ~ > > IMO it's too confusing to explain the implementation detail here > instead of the purpose. Also, it should say "with *and* without". > > SUGGESTION > Add ProcessSchemaExceptTables(), which errors if the same schema is > mentioned more than once with EXCEPT, or both with and without EXCEPT. > It also checks that a schema's EXCEPT clause only lists tables from > that same schema. > Updated as suggested in v22. I think patch 002 is now in good shape to be merged into patch 001. Thoughts? -- Thanks, Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Mon, Jul 20, 2026 at 1:53 PM Nisha Moond wrote:
>
>
> Updated as suggested in v22.
> I think patch 002 is now in good shape to be merged into patch 001. Thoughts?
>
I will check it soon. A few comments on 001:
1)
+ /*
+ * A partition cannot be included when its partition root is excluded
+ * by the same publication. Doing so would leave the catalog
+ * inconsistent (root excluded, partition included) and the
+ * ancestor-cascade rule would silently override the include at
+ * replication time.
+ *
+ * For partition hierarchies, only the partition root can be in an
+ * EXCEPT clause (a partition itself is rejected just above), so we
+ * only need to look up the catalog for the root.
+ */
Instead of mentioning the reason, can we simply mention below.
/*
* A partition cannot be added to a publication if its partition root is
* excluded by the publication. We follow the rule that excluding a
* partition root means that the entire partition tree is excluded. Thus,
* check whether the root is in the EXCEPT clause and reject adding the
* individual partition to the publication.
*/
2)
+ /*
+ * A publication can hold both explicitly-included (prexcept=false) and
+ * EXCEPT (prexcept=true) rows for the same pubid. Scan until we find an
+ * explicitly-included row, rather than relying on the first row's
+ * prexcept value.
+ */
Good to add one example to give clarity on the case here. Suggestion.
/*
* A publication can have both explicitly included (prexcept = false) and
* EXCEPT (prexcept = true) rows for the same pubid. For example:
*
* CREATE PUBLICATION pub1 FOR TABLE s1.t1,
* TABLES IN SCHEMA s2 EXCEPT (TABLE s2.t1);
*
* Scan until we find an explicitly included row.
*/
3)
+/*
+ * Check whether a pg_publication_rel row exists for (pubid, relid); if so,
+ * set *is_except to its prexcept flag.
+ */
+bool
+GetPublicationRelEntry(Oid pubid, Oid relid, bool *is_except)
It is only checking (returning bool) and not getting the pg_pub_rel
row as such. Shall we name it as CheckPublicationRelEntry or
CheckPubRelEntry?
4)
Are the changes in GetAllPublicationRelations() intentional? We are
not changing any logic there though. So we can avoid touching this
function.
5)
GetAllSchemaPublicationRelations:
+ if (ancestors != NIL)
+ excluded = list_member_oid(except_relids,
+ llast_oid(ancestors));
+ list_free(ancestors);
Since we are already checking 'if (ancestors != NIL)', we can move
'list_free(ancestors)' also inside that if-block.
6)
+ }
+ list_free(schemaRels);
We an leave a blank line before list_free for better readibility.
7)
Currently is_table_publishable_in_publication() has:
----------------------------------
/*
* If an ancestor is published, the partition's status depends on
* publish_via_partition_root value.
*
* If it's true, the ancestor's relation OID is the effective published
* OID, so the partition itself should be excluded (return false).
*
* If it's false, the partition is covered by its ancestor's presence in
* the publication, it should be included (return true).
*/
if (relispartition)
{
if (OidIsValid(GetTopMostAncestorInPublication(pub->oid, ancestors, NULL)))
return !pub->pubviaroot;
/*
* GetTopMostAncestorInPublication() returns InvalidOid both when no
* ancestor matched at all, and when the root is excluded via EXCEPT.
* Disambiguate here: if the root is excluded, the partition is never
* published through this publication, regardless of whether the
* partition's schema is separately included. ancestors can be NIL
* for a partition whose DETACH ... CONCURRENTLY is pending, in which
* case there is no ancestor to check.
*/
if (ancestors != NIL &&
GetPublicationRelEntry(pub->oid, llast_oid(ancestors), &is_except) &&
is_except)
return false;
}
----------------------------------
Shall we change this to:
/*
* If the partition root is excluded via the EXCEPT clause, the partition
* is never considered to be published through this publication. Check this
* before checking whether an ancestor is published.
*
* If an ancestor is published, the partition's status depends on
*....rest of the comment here...
*/
if (relispartition)
{
/*
* ancestors can be NIL for a partition whose DETACH ... CONCURRENTLY is
* pending, in which case there is no ancestor to check.
*/
if (ancestors != NIL &&
GetPublicationRelEntry(pub->oid, llast_oid(ancestors), &is_except) &&
is_except)
return false;
if (OidIsValid(GetTopMostAncestorInPublication(pub->oid, ancestors, NULL)))
return !pub->pubviaroot;
}
The benefit of above apporach is the bigger comment saying
'Disambiguate here' is not needed. That makes it complex to
understand. Plus if ROOT is excluded, we need not to execute ROOT
exlcusion check twice as you were doing earlier, one through
GetTopMostAncestorInPublication and one outside it. But let me know if
you see any issue in above changes.
thanks
Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Mon, Jul 20, 2026 at 3:47 PM shveta malik wrote:
>
> On Mon, Jul 20, 2026 at 1:53 PM Nisha Moond wrote:
> >
> >
> > Updated as suggested in v22.
> > I think patch 002 is now in good shape to be merged into patch 001. Thoughts?
> >
>
> I will check it soon. A few comments on 001:
>
>
> 1)
> + /*
> + * A partition cannot be included when its partition root is excluded
> + * by the same publication. Doing so would leave the catalog
> + * inconsistent (root excluded, partition included) and the
> + * ancestor-cascade rule would silently override the include at
> + * replication time.
> + *
> + * For partition hierarchies, only the partition root can be in an
> + * EXCEPT clause (a partition itself is rejected just above), so we
> + * only need to look up the catalog for the root.
> + */
>
> Instead of mentioning the reason, can we simply mention below.
>
> /*
> * A partition cannot be added to a publication if its partition root is
> * excluded by the publication. We follow the rule that excluding a
> * partition root means that the entire partition tree is excluded. Thus,
> * check whether the root is in the EXCEPT clause and reject adding the
> * individual partition to the publication.
> */
>
> 2)
>
> + /*
> + * A publication can hold both explicitly-included (prexcept=false) and
> + * EXCEPT (prexcept=true) rows for the same pubid. Scan until we find an
> + * explicitly-included row, rather than relying on the first row's
> + * prexcept value.
> + */
>
> Good to add one example to give clarity on the case here. Suggestion.
>
> /*
> * A publication can have both explicitly included (prexcept = false) and
> * EXCEPT (prexcept = true) rows for the same pubid. For example:
> *
> * CREATE PUBLICATION pub1 FOR TABLE s1.t1,
> * TABLES IN SCHEMA s2 EXCEPT (TABLE s2.t1);
> *
> * Scan until we find an explicitly included row.
> */
>
> 3)
> +/*
> + * Check whether a pg_publication_rel row exists for (pubid, relid); if so,
> + * set *is_except to its prexcept flag.
> + */
> +bool
> +GetPublicationRelEntry(Oid pubid, Oid relid, bool *is_except)
>
> It is only checking (returning bool) and not getting the pg_pub_rel
> row as such. Shall we name it as CheckPublicationRelEntry or
> CheckPubRelEntry?
>
> 4)
> Are the changes in GetAllPublicationRelations() intentional? We are
> not changing any logic there though. So we can avoid touching this
> function.
>
> 5)
> GetAllSchemaPublicationRelations:
> + if (ancestors != NIL)
> + excluded = list_member_oid(except_relids,
> + llast_oid(ancestors));
> + list_free(ancestors);
>
> Since we are already checking 'if (ancestors != NIL)', we can move
> 'list_free(ancestors)' also inside that if-block.
>
> 6)
> + }
> + list_free(schemaRels);
>
> We an leave a blank line before list_free for better readibility.
>
> 7)
> Currently is_table_publishable_in_publication() has:
> ----------------------------------
> /*
> * If an ancestor is published, the partition's status depends on
> * publish_via_partition_root value.
> *
> * If it's true, the ancestor's relation OID is the effective published
> * OID, so the partition itself should be excluded (return false).
> *
> * If it's false, the partition is covered by its ancestor's presence in
> * the publication, it should be included (return true).
> */
> if (relispartition)
> {
> if (OidIsValid(GetTopMostAncestorInPublication(pub->oid, ancestors, NULL)))
> return !pub->pubviaroot;
>
> /*
> * GetTopMostAncestorInPublication() returns InvalidOid both when no
> * ancestor matched at all, and when the root is excluded via EXCEPT.
> * Disambiguate here: if the root is excluded, the partition is never
> * published through this publication, regardless of whether the
> * partition's schema is separately included. ancestors can be NIL
> * for a partition whose DETACH ... CONCURRENTLY is pending, in which
> * case there is no ancestor to check.
> */
> if (ancestors != NIL &&
> GetPublicationRelEntry(pub->oid, llast_oid(ancestors), &is_except) &&
> is_except)
> return false;
> }
> ----------------------------------
>
> Shall we change this to:
>
> /*
> * If the partition root is excluded via the EXCEPT clause, the partition
> * is never considered to be published through this publication. Check this
> * before checking whether an ancestor is published.
> *
> * If an ancestor is published, the partition's status depends on
> *....rest of the comment here...
> */
> if (relispartition)
> {
> /*
> * ancestors can be NIL for a partition whose DETACH ... CONCURRENTLY is
> * pending, in which case there is no ancestor to check.
> */
> if (ancestors != NIL &&
> GetPublicationRelEntry(pub->oid, llast_oid(ancestors), &is_except) &&
> is_except)
> return false;
>
> if (OidIsValid(GetTopMostAncestorInPublication(pub->oid, ancestors, NULL)))
> return !pub->pubviaroot;
> }
>
>
> The benefit of above apporach is the bigger comment saying
> 'Disambiguate here' is not needed. That makes it complex to
> understand. Plus if ROOT is excluded, we need not to execute ROOT
> exlcusion check twice as you were doing earlier, one through
> GetTopMostAncestorInPublication and one outside it. But let me know if
> you see any issue in above changes.
>
A few more comments:
8)
CreatePublication:
+ /*
+ * Collect explicit table OIDs now, before we close the relation
+ * list, so that except-table validation below can check for
+ * contradictions without relying on a catalog scan that might not
+ * yet see the just-inserted rows.
+ */
+ if (except_pubtables != NIL)
+ {
+ foreach_ptr(PublicationRelInfo, pri, rels)
+ explicitrelids = lappend_oid(explicitrelids,
+ RelationGetRelid(pri->relation));
+ }
+
PublicationAddTables(puboid, rels, true, NULL);
Shall we make the explicitrelids collection after
'PublicationAddTables', as PublicationAddTables may error out too
while doing 'check_publication_add_relation'.
9)
In the check above, IIUC, except_pubtables can be there even for ALL
TABLES, but we want this handling only for schema-except list, so
shall we have the check as:
if (schemaidlist != NIL && except_pubtables != NIL)
10)
+ /*
+ * Validate that each excluded table is not also in the
+ * explicit table list (which would be contradictory), and
+ * that no explicit partition's root is in the except list.
+ * Use the in-memory explicitrelids collected above rather
+ * than re-reading the catalog, which may not yet see the
+ * just-inserted rows.
+ */
Can we please simplify this comment. The function
CheckExceptNotInTableList() already explains it in detail inside. Also
catalog-rows not visible is already explained by a comment where we
collect the relids.
/*
* Validate that a table is not both explicitly included and excluded by
* the schema's EXCEPT clause.
*/
11)
The changes in AlterPublication (variable name change) if really
needed can be shifter to alter-pub patch.
thanks
Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Some review comments for v22*
======
1. GENERAL -- Consistent wording in messages
I found some examples of error messages that could be made more similar:
1a.
"modify" versus "change"
modify...
+ errhint("Use ALTER PUBLICATION ... SET TABLES IN SCHEMA ... EXCEPT
to modify the EXCEPT list.")));
versus (Change)
+ errhint("Change the EXCEPT clause using ALTER PUBLICATION ... SET
TABLES IN SCHEMA ... EXCEPT."));
+ errhint("Change the EXCEPT clause using ALTER PUBLICATION ... SET
TABLES IN SCHEMA ... EXCEPT.")));
+ errhint("%s", has_alltables_pub ?
+ _("Change the EXCEPT clause using ALTER PUBLICATION ... SET ALL
TABLES ... EXCEPT.") :
+ _("Change the EXCEPT clause using ALTER PUBLICATION ... SET TABLES
IN SCHEMA ... EXCEPT.")));
~
Shouldn't 1st one (from patch v22-0004) be identical to the others? e.g.:
Change the EXCEPT clause using ALTER PUBLICATION ... SET TABLES IN
SCHEMA ... EXCEPT.
~~~
1b.
"referenced" versus "named" versus "listed"
referenced...
+ errmsg_plural("cannot attach table \"%s\" as partition because it is
referenced in EXCEPT clause of publication %s",
+ "cannot attach table \"%s\" as partition because it is referenced
in EXCEPT clause of publications %s",
versus (named)
+ errdetail("Partition root \"%s\" is named in the publication's
EXCEPT clause for schema \"%s\".",
+ quote_qualified_identifier(get_namespace_name(get_rel_namespace(root)),
+ get_rel_name(root)),
+ errdetail("Partition root \"%s\" is named in the publication's
EXCEPT clause for schema \"%s\".",
+ RelationGetQualifiedRelationName(pri->relation),
+ get_namespace_name(RelationGetNamespace(pri->relation)))));
versus (listed)
+ errdetail("Ancestor \"%s\" of partition \"%s\" is currently listed
in the EXCEPT clause of the publication.",
+ quote_qualified_identifier(get_namespace_name(get_rel_namespace(root)),
+ get_rel_name(root)),
+ errdetail("The table is currently listed in the EXCEPT clause of the
publication."),
+ * publication, excluding any tables listed in the EXCEPT clause.
+ errdetail("Ancestor \"%s\" of partition \"%s\" is currently listed
in the EXCEPT clause of this command.",
+ RelationGetQualifiedRelationName(pri->relation),
+ quote_qualified_identifier(get_namespace_name(get_rel_namespace(explicitrelid)),
~
IMO there is no real difference here in saying "referenced" v "named"
v "listed", so why not make them all "named" so they are alike.
~~~
1c.
"EXCEPT list" versus "EXCEPT clause"
EXCEPT list:
+ errhint("Use ALTER PUBLICATION ... SET TABLES IN SCHEMA ... EXCEPT
to modify the EXCEPT list.")));
+ * A partition cannot be included when its partition root is in the
+ * same publication's EXCEPT list. Doing so would leave the catalog
+ errhint("Change EXCEPT list using ALTER PUBLICATION ... SET TABLES
IN SCHEMA ... EXCEPT."));
+ errhint("Change EXCEPT list using ALTER PUBLICATION ... SET TABLES
IN SCHEMA ... EXCEPT.")));
+ /* filter out any tables that appear in the EXCEPT list */
+ * A partition whose root is in the publication's EXCEPT list
+ * is also excluded, even if the partition itself lives in a
+ * Validate that each excluded table is not also in the
+ * explicit table list (which would be contradictory), and
+ * that no explicit partition's root is in the except list.
etc.
I don't recognise the reasons for the difference -- it all seems a bit
random. There are a lot more "EXCEPT clause" than there are "EXCEPT
list".
EXCEPT list makes sense for some comments and parameters, but for
user-facing messages maybe those should consistently say "EXCEPT
clause"?
======
src/backend/catalog/pg_publication.c
2.
publication_add_relation:
On Mon, Jul 20, 2026 at 6:22 PM Nisha Moond wrote:
>
> On Thu, Jul 16, 2026 at 2:04 PM Peter Smith wrote:
> >
>
> > 7.
> > + errdetail("Ancestor \"%s\" of partition \"%s\" is currently listed
> > in the EXCEPT clause of the publication.",
> > + quote_qualified_identifier(get_namespace_name(get_rel_namespace(root)),
> >
> > Similar (singular) comment to before.
> >
> > /in the EXCEPT clause/in an EXCEPT clause/
> >
>
> It looks like comment #4 is repeated here. In any case, I addressed
> both occurrences of the errdetail (in check_publication_add_relation()
> and CheckExceptNotInTableList()):
> "Ancestor \"%s\" of partition \"%s\" is curre..".
>
Looks like a previous review comment #7 was missed despite saying it
was addressed. It still says:
+ errdetail("The table is currently listed in the EXCEPT clause of the
publication."),
======
src/backend/commands/publicationcmds.c
ProcessSchemaExceptTables
3.
(patch 0002)
+ * *schemas: accumulates all schema OIDs seen so far in this statement.
+ * *schemas_with_except: tracks which schema OIDs have already been seen
+ * with an EXCEPT clause in this statement.
Maybe this can clarify that `*schemas_with_except` OIDs will be a
subset of `*schemas`.OIDs
SUGGESTION
*schemas_with_except: This is a subset of *schemas. Tracks which of
the seen schemas of this statement had an EXCEPT clause.
======
Kind Regards,
Peter Smith.
Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Tue, Jul 21, 2026 at 11:23 AM Peter Smith wrote:
>
> Some review comments for v22*
>
> ======
>
> 1. GENERAL -- Consistent wording in messages
>
> I found some examples of error messages that could be made more similar:
>
> 1a.
> "modify" versus "change"
>
> modify...
>
> + errhint("Use ALTER PUBLICATION ... SET TABLES IN SCHEMA ... EXCEPT
> to modify the EXCEPT list.")));
>
> versus (Change)
>
> + errhint("Change the EXCEPT clause using ALTER PUBLICATION ... SET
> TABLES IN SCHEMA ... EXCEPT."));
> + errhint("Change the EXCEPT clause using ALTER PUBLICATION ... SET
> TABLES IN SCHEMA ... EXCEPT.")));
>
> + errhint("%s", has_alltables_pub ?
> + _("Change the EXCEPT clause using ALTER PUBLICATION ... SET ALL
> TABLES ... EXCEPT.") :
> + _("Change the EXCEPT clause using ALTER PUBLICATION ... SET TABLES
> IN SCHEMA ... EXCEPT.")));
>
> ~
>
> Shouldn't 1st one (from patch v22-0004) be identical to the others? e.g.:
> Change the EXCEPT clause using ALTER PUBLICATION ... SET TABLES IN
> SCHEMA ... EXCEPT.
>
> ~~~
>
> 1b.
> "referenced" versus "named" versus "listed"
>
> referenced...
>
> + errmsg_plural("cannot attach table \"%s\" as partition because it is
> referenced in EXCEPT clause of publication %s",
> + "cannot attach table \"%s\" as partition because it is referenced
> in EXCEPT clause of publications %s",
>
> versus (named)
>
> + errdetail("Partition root \"%s\" is named in the publication's
> EXCEPT clause for schema \"%s\".",
> + quote_qualified_identifier(get_namespace_name(get_rel_namespace(root)),
> + get_rel_name(root)),
>
> + errdetail("Partition root \"%s\" is named in the publication's
> EXCEPT clause for schema \"%s\".",
> + RelationGetQualifiedRelationName(pri->relation),
> + get_namespace_name(RelationGetNamespace(pri->relation)))));
>
> versus (listed)
>
> + errdetail("Ancestor \"%s\" of partition \"%s\" is currently listed
> in the EXCEPT clause of the publication.",
> + quote_qualified_identifier(get_namespace_name(get_rel_namespace(root)),
> + get_rel_name(root)),
>
> + errdetail("The table is currently listed in the EXCEPT clause of the
> publication."),
>
> + * publication, excluding any tables listed in the EXCEPT clause.
>
> + errdetail("Ancestor \"%s\" of partition \"%s\" is currently listed
> in the EXCEPT clause of this command.",
> + RelationGetQualifiedRelationName(pri->relation),
> + quote_qualified_identifier(get_namespace_name(get_rel_namespace(explicitrelid)),
>
> ~
>
> IMO there is no real difference here in saying "referenced" v "named"
> v "listed", so why not make them all "named" so they are alike.
>
> ~~~
>
> 1c.
> "EXCEPT list" versus "EXCEPT clause"
>
> EXCEPT list:
>
> + errhint("Use ALTER PUBLICATION ... SET TABLES IN SCHEMA ... EXCEPT
> to modify the EXCEPT list.")));
>
> + * A partition cannot be included when its partition root is in the
> + * same publication's EXCEPT list. Doing so would leave the catalog
>
> + errhint("Change EXCEPT list using ALTER PUBLICATION ... SET TABLES
> IN SCHEMA ... EXCEPT."));
>
> + errhint("Change EXCEPT list using ALTER PUBLICATION ... SET TABLES
> IN SCHEMA ... EXCEPT.")));
>
> + /* filter out any tables that appear in the EXCEPT list */
>
> + * A partition whose root is in the publication's EXCEPT list
> + * is also excluded, even if the partition itself lives in a
>
> + * Validate that each excluded table is not also in the
> + * explicit table list (which would be contradictory), and
> + * that no explicit partition's root is in the except list.
>
> etc.
>
> I don't recognise the reasons for the difference -- it all seems a bit
> random. There are a lot more "EXCEPT clause" than there are "EXCEPT
> list".
>
> EXCEPT list makes sense for some comments and parameters, but for
> user-facing messages maybe those should consistently say "EXCEPT
> clause"?
>
Thanks, agreed on all three.
Standardized the user-facing messages using "clause" and updated the
comments to use "EXCEPT clause", keeping "list" only where it refers
to the actual List variable.
I'll keep an eye on the next iterations and correct in case I missed any.
> ======
> src/backend/catalog/pg_publication.c
>
> 2.
> publication_add_relation:
> On Mon, Jul 20, 2026 at 6:22 PM Nisha Moond wrote:
> >
> > On Thu, Jul 16, 2026 at 2:04 PM Peter Smith wrote:
> > >
> >
> > > 7.
> > > + errdetail("Ancestor \"%s\" of partition \"%s\" is currently listed
> > > in the EXCEPT clause of the publication.",
> > > + quote_qualified_identifier(get_namespace_name(get_rel_namespace(root)),
> > >
> > > Similar (singular) comment to before.
> > >
> > > /in the EXCEPT clause/in an EXCEPT clause/
> > >
> >
> > It looks like comment #4 is repeated here. In any case, I addressed
> > both occurrences of the errdetail (in check_publication_add_relation()
> > and CheckExceptNotInTableList()):
> > "Ancestor \"%s\" of partition \"%s\" is curre..".
> >
>
> Looks like a previous review comment #7 was missed despite saying it
> was addressed. It still says:
> + errdetail("The table is currently listed in the EXCEPT clause of the
> publication."),
>
Sorry, I misread the comment; it's corrected now.
> ======
> src/backend/commands/publicationcmds.c
>
> ProcessSchemaExceptTables
>
> 3.
> (patch 0002)
>
> + * *schemas: accumulates all schema OIDs seen so far in this statement.
> + * *schemas_with_except: tracks which schema OIDs have already been seen
> + * with an EXCEPT clause in this statement.
>
> Maybe this can clarify that `*schemas_with_except` OIDs will be a
> subset of `*schemas`.OIDs
>
> SUGGESTION
> *schemas_with_except: This is a subset of *schemas. Tracks which of
> the seen schemas of this statement had an EXCEPT clause.
>
Done.
~~~
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Tue, Jul 21, 2026 at 11:12 AM shveta malik wrote:
>
>
> A few more comments:
>
> 8)
> CreatePublication:
> + /*
> + * Collect explicit table OIDs now, before we close the relation
> + * list, so that except-table validation below can check for
> + * contradictions without relying on a catalog scan that might not
> + * yet see the just-inserted rows.
> + */
> + if (except_pubtables != NIL)
> + {
> + foreach_ptr(PublicationRelInfo, pri, rels)
> + explicitrelids = lappend_oid(explicitrelids,
> + RelationGetRelid(pri->relation));
> + }
> +
> PublicationAddTables(puboid, rels, true, NULL);
>
> Shall we make the explicitrelids collection after
> 'PublicationAddTables', as PublicationAddTables may error out too
> while doing 'check_publication_add_relation'.
>
make sense. Updated.
> 9)
> In the check above, IIUC, except_pubtables can be there even for ALL
> TABLES, but we want this handling only for schema-except list, so
> shall we have the check as:
>
> if (schemaidlist != NIL && except_pubtables != NIL)
>
Here FOR ALL TABLES EXCEPT is already handled in the for_all_tables
branch, so it can't reach this code.
The only possible cases here are FOR TABLE and FOR TABLES IN SCHEMA.
Since EXCEPT is not supported with plain FOR TABLE, except_pubtables
!= NIL already implies the schema case.
That said, should we add an assertion here, e.g.:
if (except_pubtables != NIL)
{
/* EXCEPT is only accepted with TABLES IN SCHEMA */
Assert(schemaidlist != NIL);
...
Or please correct me if I've misunderstood something.
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Fri, Jul 17, 2026 at 9:50 AM Peter Smith wrote: > > Hi Nisha. > > I noticed multiple places where these patches want to discover the > root partition table OID, but they are not interested in the ancestor > tree. > > I've created another thread/patch [1] to introduce a > `get_partition_root` C function. I think this could simplify some of > your code by removing the requirement to declare and free the unwanted > ancestor lists. > > Please take a look and give your +1 there if you think it would be useful. > > ====== > [1] https://www.postgresql.org/message-id/CAHut%2BPtc73UpWSn4teMyMxQoHwGJjRwhWiu%3DhGJqAj5k2AOXEw%40mail.gmail.com > Nisha, Peter, Do you think we should make get_partition_root's patch as 0001 in this thread and rebase rest of patches atop it? That way duplicated code in many places will be removed. Another idea is to make get_partition_root's patch as last patch here, but I prefer it as first patch. Thoughts? thanks Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Nisha Moond <nisha.moond412@gmail.com>
Дата:
On Thu, Jul 30, 2026 at 11:33 AM Nisha Moond wrote:
>
> On Tue, Jul 28, 2026 at 2:38 PM shveta malik wrote:
> >
> > Nisha, the changes in RelationBuildPublicationDesc() looks quite
> > tricky now. We are doing 'list_difference_oid' thrice:
> >
> > --for schema-pub
> > --for schmea-pubs on complete ancestor tree
> > --for all-tables pub
> >
> > Ultimately we are concatenating all individual pubids after
> > subtracting 'exceptpuboids' from each individual 'puboids' list. The
> > 'exceptpuboids' is computed only once and doesn't change with each
> > computation. Why don't we uncondiitonally do list_concat_unique_oid
> > for all pub-ids
> > and only minus 'exceptpuboids' once at the end? Won't it work? Let me
> > know if I am missing something.
> >
>
> Done as suggested. The change modifies the existing code slightly, but
> the function now seems simpler and easier to read overall. It works
> well based on my testing. I'll do a deeper analysis to ensure it
> doesn't change any existing behavior.
>
> > ~~
> >
> > I think, we can now merge 002 to 001, it will help in combined review
> > by placing except-validation logic where it should ultimately be.
> >
>
> Merged both into v24-0001.
> ~~~
>
> Attached v24 patch set.
>
I missed mentioning that, besides the comments, also fixed a bug in describe.
The bug: with v23, describe (\d t) was incorrectly showing the table
as both included and excluded in same pub -
postgres=# CREATE PUBLICATION p FOR TABLES IN SCHEMA s EXCEPT (TABLE s.t);
CREATE PUBLICATION
postgres=# \d s.t;
Table "s.t"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
a | integer | | |
Included in publications:
"p"
Excluded from publications:
"p"
It is now fixed in v24.
--
Thanks,
Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Tue, Aug 4, 2026 at 2:11 PM Nisha Moond wrote:
>
> On Fri, Jul 31, 2026 at 11:41 AM shveta malik wrote:
> >
> > Nisha,
> > A few comments on v24-001:
> >
> > 1)
> > + if (is_except)
> > + ereport(ERROR,
> > + (errcode(ERRCODE_DUPLICATE_OBJECT),
> > + errmsg("cannot add table \"%s\" to publication \"%s\"",
> > + RelationGetQualifiedRelationName(targetrel),
> > + pub->name),
> > + errdetail("The table is named in the publication's EXCEPT clause for
> > schema \"%s\".",
> > + get_namespace_name(RelationGetNamespace(targetrel))),
> > + errhint("Change the EXCEPT clause using ALTER PUBLICATION ... SET
> > TABLES IN SCHEMA ... EXCEPT.")));
> > + else
> > + ereport(ERROR,
> > + (errcode(ERRCODE_DUPLICATE_OBJECT),
> > + errmsg("relation \"%s\" is already member of publication \"%s\"",
> > + RelationGetRelationName(targetrel), pub->name)));
> >
> > Does ERRCODE_INVALID_PARAMETER_VALUE suits better in 'if-block' rather
> > than ERRCODE_DUPLICATE_OBJECT?
> > See similar error you added in CheckExceptNotInTableList():
> >
> > + if (exceptrelid == explicitrelid)
> > + ereport(ERROR,
> > + errcode(ERRCODE_INVALID_PARAMETER_VALUE),
> > + errmsg("table \"%s\" cannot be both published and excluded",
> > + RelationGetQualifiedRelationName(pri->relation)));
> >
>
> Changed to ERRCODE_INVALID_PARAMETER_VALUE in if-block.
>
> > 2)
> > +static void
> > +ProcessSchemaExceptTables(Oid schemaid, List *except_tables,
> >
> > Since we have defined most of the arguments in comment section, we can
> > add 'pstate' as well for the sake of completion.
> >
>
> Done.
>
> > 3)
> > Atop CheckExceptNotInTableList(), please add a comment indicating why
> > this funciton is still needed when we already have similar checks in
> > publication_add_relation and check_publication_add_relation.
> >
> > 4)
> > I was debugging the flow to see why 'CheckExceptNotInTableList' is
> > still needed when we have similar check in publication_add_relation().
> > My analysis:
> >
> > publication_add_relation() accepts 'if_not_exists' i.e. add the new
> > entry 'if already not present' else skip it (no error if it is a
> > duplicate addition). Most flows pass it as 'true'. The current code
> > skips raising error if if_not_exists=true and entry exists. It made
> > sense earlier, but in our implementation, I feel it should still raise
> > an error if entries are cross wired (i.e., if an exclusion is present
> > and we are trying to add it as an inclusion, or vice versa). The
> > 'if_not_exists' based 'skip logic' should only be exercised if the
> > nature of existing entity is of same kind as user is trying to add.
> > Let me know if you have different understanding.
> >
> > Based on this, I tried debugging:
> >
> > create publication pub1 for table s1.t1, tables in schema s1 except
> > (table s1.t1);
> >
> > What changes I did:
> > --I skipped CheckExceptNotInTableList() invoked from
> > CreatePublication() so that flow directly hits the immediate next call
> > PublicationAddTables for schmea's except entries.
> > --In publication_add_relation(), I made this 'if_not_exists'
> > correction (by simply making it false for debuggin purpose).
> >
> > The flow was as follows:
> >
> > --CREATE-SUb first added table s1.t1 with prexcept=false through
> > PublicationAddTables.
> >
> > --It then added Schmea to pg_pub_namespace using PublicationAddSchemas
> > and then invoked PublicationAddTables on except-table for the schema.
> > This step (against my expectation) could not find the entry added in
> > previous step (prexcept=false once) using CheckPublicationRelEntry()
> > and thus could not hit the required error. Instead it hit more
> > internal error:
> > ERROR: duplicate key value violates unique constraint
> > "pg_publication_rel_prrelid_prpubid_index"
> >
> > So it seems the catalog change from the first step was not visible in
> > the second step. What am I missing? The rel-cache invalidation or
> > something else?
> >
> > Nisha, can you debug and analyse in this direction? Expectation is to
> > either get rid of CheckExceptNotInTableList() or to conclude that
> > CheckExceptNotInTableList() is a reasonable addition to the code.
> >
>
> CheckExceptNotInTableList() was written to handle only CREATE
> PUBLICATION ... EXCEPT.
>
> IIUC you are not seeing the catalog change because of command-counter
> MVCC, not relcache invalidation. CommandCounterIncrement() is what
> makes the changes so far visible to later lookups —
> CreatePublication() already does that once, for the new pg_publication
> row.
>
> So yes, we could add a CommandCounterIncrement() between the two
> PublicationAddTables() calls, but I don't think it gets us to a better
> place:
> 1. The error message would be misleading. The explicit tables are
> added first, so it is the later EXCEPT insertion that finds the
> existing row, and that row has prexcept = false — so we would report -
> relation "%s" is already member of publication "%s" (with a hint
> pointing at ALTER PUBLICATION ... SET) for a CREATE PUBLICATION
> statement. This one is arguable, though — we could tweak the error
> message accordingly.
> 2. It still doesn't solve the partition case. Visibility aside,
> check_publication_add_relation() only looks upwards from the relation
> being added ("is my root excluded?"). For
> CREATE PUBLICATION p FOR TABLE part, TABLES IN SCHEMA s EXCEPT
> (TABLE root);
> the root's EXCEPT row does not exist yet when part is inserted, and
> when root is inserted it isn't a partition, so no check runs at all.
> Catching it there would need a new downward scan over every partition
> of an excluded root,
Okay, I see your point.
> which is more work than comparing the lists we
> already have in hand.
I agree. It is expensive as well.
>
> Since CreatePublication() has every table of the statement available
> in memory, this separate function identifies the contradiction with no
> catalog lookup at all. So IMO keeping CheckExceptNotInTableList() is
> the better way; I have expanded the comment atop the function to
> explain this. Let me know your thoughts.
I will reveiw the comment. But I agree with the overall approach.
> ~~~
>
> Attached is the v25 patch set addressing all of the above, as well as
> Shlok's and Peter's comments in [1] and [2].
>
> [1] https://www.postgresql.org/message-id/CANhcyEXtX-tAMMMvsK%2Be1TUzUWT77%2BiwTbXPx-nM1Va_UjYTHg%40mail.gmail.com
> [2] https://www.postgresql.org/message-id/CAHut%2BPumod7UW71WHO0GMA2qibG%2BTTsX7j5FJykAJgBwR73EdA%40mail.gmail.com
>
> --
> Thanks,
> Nisha
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
I reviewed test changes in 037.pl today. Should we add one more test for the case where a subscription subscribes to multiple publications, where one publication excludes a table from the schema, and another includes the full same schema? thanks Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Peter Smith <smithpb2250@gmail.com>
Дата:
Some review comments for v26* ====== ////////// Patch v26-0001 ////////// src/backend/commands/publicationcmds.c ProcessSchemaExceptTables: 1. +/* + * Also rejects a schema being mentioned more than once with an EXCEPT + * clause, even if the EXCEPT clauses are identical — much like + * OpenTableList() rejects "FOR TABLE t1(a), t1(a)" despite the column + * lists matching. A schema can still be mentioned multiple times, just + * not more than once with EXCEPT. + * + * Qualify unqualified EXCEPT table names with the given schema (rejecting + * any explicitly qualified with a different schema), and append them to + * *except_pubtables. + * + * schemaid: OID of the schema for this TABLES IN SCHEMA mention. + * except_tables: the EXCEPT list (or NIL) attached to this mention. + * pstate: parse state of the statement, used to report the error position of + * an offending EXCEPT entry. + * *schemas: accumulates all schema OIDs seen so far in this statement. + * *schemas_with_except: This is a subset of *schemas. Tracks which of + * the seen schemas of this statement had an EXCEPT clause. + * *except_pubtables: accumulates the (now schema-qualified) EXCEPT table + * entries across the whole statement. + */ Needs some adjustment. It doesn't make sense for the function comment to start with "Also ..." ~~~ 2. + * - CreatePublication() inserts the explicit tables and the EXCEPT tables in + * a single command, and rows inserted by the current command are not + * visible to later lookups within the same command. + * + * - In the partition case, the excluded root's row might not yet exist + * because the root may be added to the EXCEPT list later. Detecting such + * contradictions when adding the root to the EXCEPT clause would require + * traversing downward through the partition hierarchy, whereas the + * existing ancestor lookups only traverse upward from the relation being + * added. 2a. /, and rows inserted/, but rows inserted/ ~ 2b. /In the partition case/For partitions/ AFAICT this case is referring to something like: "FOR TABLE part, TABLES IN SCHEMA EXCEPT (part_root)" But, isn't that just a variation of the 1st case issue? e.g. where table "part" is not yet visible for later lookup of "root", then you wont be able to check integrity of the partition tree regardless of the up/down traversal logic, so I wasn't sure why this 2nd case was separately mentioned at all. ====== ////////// Patch v26-0004 (docs) ////////// 1. + + Replace the schema list of sales_publication with + only schema sales, excluding only + sales.drafts. All other previously excluded tables + in schema sales are no longer excluded. Any schemas + previously in sales_publication are removed: + +ALTER PUBLICATION sales_publication SET TABLES IN SCHEMA sales EXCEPT (TABLE drafts); + + The last modification missed the point of my previous review comment. My point was now that the first sentence is modified it should just end with a colon (:), because and all the rest is redundant since IMO it is just repeating the same. e.g. BEFORE Replace the schema list of sales_publication with only schema sales, excluding only sales.drafts. All other previously excluded tables in schema sales are no longer excluded. Any schemas previously in sales_publication are removed: SUGGESTION Replace the schema list of sales_publication with only schema sales, excluding only sales.drafts: ====== Kind Regards, Peter Smith. Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Wed, 12 Aug 2026 at 11:42, shveta malik wrote: > > I thought some more. Please find my analysis and opinion on all > related scenarios: > > Metadata: > schema s1: parent > schema s2: parition/child of parent. > > Scenarios: > a) s1.s1.parent is a partitioned table, and its partitions live in > another schema. Or > b) s1.parent is a parent table, and its descendants/inherited tables > live in another schema. > > ~~ > > Now consider the exclusion cases: > > Case 1: No contradiction in EXCEPT > ----------------------------------------- > CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA s1 EXCEPT (TABLE s1.parent*); > > My opinion: > In both cases a) and b), s1.parent will be included in the > publication. Its partitions or descendants, however, will not be > included because they belong to another schema (s2), which is not > included in the publication. Thus, they are effectively excluded due > to the absence of a schema inclusion rule, rather than by the EXCEPT > clause. > > > Case 2: Indirect contradiction in EXCEPT > -------------------------------------------------------- > CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA s1 EXCEPT (TABLE > s1.parent*), TABLES IN SCHEMA s2; > > The above command creates an indirect logical contradiction. The > child/partition is explicitly brought into the publication pool > through the schema inclusion rule (TABLES IN SCHEMA s2), while at the > same time being excluded by the recursive EXCEPT (TABLE s1.parent*) > clause of another schema. I believe this should result in the same > error that we have already concluded and implemented in the following > case: Thanks for the feedback. I have made the changes to handle inheritance tables. I will address the partition table case in a follow-up patch. The attached v27 patch has the changes for the same. Regards, Vignesh
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
vignesh C <vignesh21@gmail.com>
Дата:
On Wed, 12 Aug 2026 at 14:40, shveta malik wrote: > > On Tue, Aug 11, 2026 at 2:28 PM vignesh C wrote: > > > > > > Apart from these, the rest of the comments are also fixed in the v26 > > version attached. > > Thanks Vignesh. A few comments on v26-0001: > > 1) > > publication_add_relation() accepts 'if_not_exists' i.e. add the new > entry 'if already not present' else skip it (no error if it is a > duplicate addition). Most flows pass it as 'true'. The current code > skips raising error if if_not_exists=true and entry exists. It made > sense earlier, but in our implementation, I feel it should still raise > an error if entries are cross wired (i.e., if an exclusion is present > and we are trying to add it as an inclusion, or vice versa). The > 'if_not_exists' based 'skip logic' should only be exercised if the > nature of existing entity is of same kind as user is trying to add. > > Let me know if you have different understanding. That is my understanding as well. I tested a few scenarios to determine whether there was an actual issue and found that the following cases were succeeding when they should have thrown an error: Scenario 1: CREATE PUBLICATION p FOR TABLES IN SCHEMA s1 EXCEPT (TABLE s1.t); ALTER PUBLICATION p ADD TABLE s1.t; Scenario 2: CREATE PUBLICATION p2 FOR TABLE s1.t; ALTER PUBLICATION p2 ADD TABLES IN SCHEMA s1 EXCEPT (TABLE s1.t); Both scenarios should have resulted in an error, but they currently succeed. I have addressed these cases as well. > 2) > ProcessSchemaExceptTables: > > + * Also rejects a schema being mentioned more than once with an EXCEPT > + * clause, even if the EXCEPT clauses are identical — much like > + * OpenTableList() rejects "FOR TABLE t1(a), t1(a)" despite the column > + * lists matching. A schema can still be mentioned multiple times, just > + * not more than once with EXCEPT. > + * > + * Qualify unqualified EXCEPT table names with the given schema (rejecting > + * any explicitly qualified with a different schema), and append them to > + * *except_pubtables. > > We changed the order of comments above, but missed to change these: > > 'Also rejects a schema ' -> Reject a schema > Qualify unqualified -> 'Also qualify unqualified EXCEPT table..' Modified > 3) > CheckExceptNotInTableList: > + * Both checks are performed here, on the lists supplied by the statement, > + * because at this point the catalog cannot answer either question. The > + * corresponding checks in publication_add_relation() and > + * check_publication_add_relation() rely on pg_publication_rel entries and > + * ancestor lookups, neither of which is sufficient in the cases below: > > Since we have changed comment prior to it, this too needs to be > changed as 'Both checks' does not make much sense. > > Suggestion: > Similar checks are present in publication_add_relation() and > check_publication_add_relation(), but they rely on pg_publication_rel > entries and ancestor lookups. Here, the checks are performed on the > object lists collected during the statement, as the catalog state is > not sufficient in the cases below: Modified The v27 version patch attached at [1] has the changes for the same. [1] - https://www.postgresql.org/message-id/CALDaNm0802S%3D557rKtYcV%2BoEbXFw23n%3DXtPHMCbKGSgOgOgk2A%40mail.gmail.com Regards, Vignesh
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
vignesh C <vignesh21@gmail.com>
Дата:
On Fri, 7 Aug 2026 at 19:51, vignesh C wrote: > > On Tue, 4 Aug 2026 at 14:11, Nisha Moond wrote: > > > > Attached is the v25 patch set addressing all of the above, as well as > > Shlok's and Peter's comments in [1] and [2]. > > There is another issue with pg_dump when dumping a publication created > using FOR TABLES IN SCHEMA ... EXCEPT. > CREATE SCHEMA s1; > CREATE SCHEMA s2; > CREATE TABLE s1.parent (a int); > CREATE TABLE s2.child (b int) INHERITS (s1.parent); > > -- Create a publication excluding the parent table > CREATE PUBLICATION p FOR TABLES IN SCHEMA s1 EXCEPT (TABLE s1.parent); > > The publication correctly excludes both the parent and its inherited child: > postgres=# \dRp+ > Publication p > Owner | All tables | All sequences | Inserts | Updates | Deletes > | Truncates | Generated columns | Via root | Description > ------------+------------+---------------+---------+---------+---------+-----------+-------------------+----------+------------- > test | f | f | t | t | t > | t | none | f | > Tables from schemas: > "s1" > Except tables: > "s1.parent" > "s2.child" This implementation has now been modified to include only s1.parent and not s2.child, since the s2 schema was not specified in the publication. > However, pg_dump generates the following definition: > CREATE PUBLICATION p WITH (publish = 'insert, update, delete, truncate'); > ALTER PUBLICATION p OWNER TO test; > ALTER PUBLICATION p ADD TABLES IN SCHEMA s1 EXCEPT (TABLE ONLY parent); Since s2.child is not included in the publication relation catalog, the dump retains the original publication definition. Consequently, during restore, the original publication definition is recreated. This issue is addressed in the v27 version patch attached at [1]. [1] - https://www.postgresql.org/message-id/CALDaNm0802S%3D557rKtYcV%2BoEbXFw23n%3DXtPHMCbKGSgOgOgk2A%40mail.gmail.com Regards, Vignesh
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Fri, Aug 14, 2026 at 7:52 PM vignesh C wrote: > > On Wed, 12 Aug 2026 at 14:40, shveta malik wrote: > > > > On Tue, Aug 11, 2026 at 2:28 PM vignesh C wrote: > > > > > > > > > Apart from these, the rest of the comments are also fixed in the v26 > > > version attached. > > > > Thanks Vignesh. A few comments on v26-0001: > > > > 1) > > > > publication_add_relation() accepts 'if_not_exists' i.e. add the new > > entry 'if already not present' else skip it (no error if it is a > > duplicate addition). Most flows pass it as 'true'. The current code > > skips raising error if if_not_exists=true and entry exists. It made > > sense earlier, but in our implementation, I feel it should still raise > > an error if entries are cross wired (i.e., if an exclusion is present > > and we are trying to add it as an inclusion, or vice versa). The > > 'if_not_exists' based 'skip logic' should only be exercised if the > > nature of existing entity is of same kind as user is trying to add. > > > > Let me know if you have different understanding. > > That is my understanding as well. > I tested a few scenarios to determine whether there was an actual > issue and found that the following cases were succeeding when they > should have thrown an error: > Scenario 1: > CREATE PUBLICATION p FOR TABLES IN SCHEMA s1 EXCEPT (TABLE s1.t); > ALTER PUBLICATION p ADD TABLE s1.t; > > Scenario 2: > CREATE PUBLICATION p2 FOR TABLE s1.t; > ALTER PUBLICATION p2 ADD TABLES IN SCHEMA s1 EXCEPT (TABLE s1.t); > > Both scenarios should have resulted in an error, but they currently > succeed. I have addressed these cases as well. > These are very simple scenarios which I tested multiple times. These scenarios produced an error in the previous version; see: postgres=# create publication pub1 for tables in schema s1 except (table s1.t1); CREATE PUBLICATION postgres=# alter publication pub1 add table s1.t1; ERROR: cannot add table "s1.t1" to publication "pub1" DETAIL: The table is named in the publication's EXCEPT clause for schema "s1". HINT: Change the EXCEPT clause using ALTER PUBLICATION ... SET TABLES IN SCHEMA ... EXCEPT. postgres=# CREATE PUBLICATION pub2 FOR TABLE s1.t1; CREATE PUBLICATION postgres=# ALTER PUBLICATION pub2 ADD TABLES IN SCHEMA s1 EXCEPT (TABLE s1.t1); ERROR: table "s1.t1" cannot be both published and excluded By any chance did you comment out 'CheckExceptNotInTableList' while testing these i.e. did you intend to test these through publication_add_relation() alone? thanks Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Wed, Aug 19, 2026 at 8:17 PM vignesh C wrote: > > On Tue, 18 Aug 2026 at 13:34, Peter Smith wrote: > > > > Hi Vignesh/Nisha, > > > > IMO, it feels like these patches are doing too much work trying to > > protect the user from themselves, and it is even making some > > combinations difficult to specify. > > > > Also, there is a lot of logic and many lines of code now just for > > checking publication command "inconsistencies". > > I still feel we should throw the error at CREATE PUBLICATION itself. > That would make the conflict clear to the user and allow them to > modify the publication accordingly. Otherwise, in a conflicting case > like the following, it may be unclear whether the table will actually > be published: > CREATE TABLE s1.parent (a int); > CREATE TABLE s2.child (b int) INHERITS (s1.parent); > CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA s1 EXCEPT (TABLE s1.parent), s2; > Yeah, but is that even a conflict? AFAICT, it is considered a "conflict" only because you assume the user has made a mistake. OTOH, if you trust the user really wanted a publication with "everything from schemas s1 and s2 but excluding the parent/children tree", then the command could be considered valid, right? > Here, it may not be obvious whether s2.child will be published because > schema s2 is included, or whether it will be skipped because its > parent s1.parent is specified in the EXCEPT clause. It is unambiguous by this simple rule: "RULE 1: Fine-grained clauses take precedence (so anything the user says about a TABLE takes precedence over whatever they say about a SCHEMA)" In your example, the exclusion of the TABLE `parent` and its children takes precedence over the inclusion of all tables from SCHEMA s2. ~ The patches have grown a lot with the recent conflict checking code: v25-0001 -- 2001 lines v26-0001 -- 2085 lines v27-0001 -- 2514 lines v28-0001 -- 2597 lines v29-0001 -- 2541 lines Perhaps my proposed rule has unknown flaws in it, but I'd hoped to explore how much simpler the patch implementation would be if we just assumed users know what they are doing. ====== Kind Regards, Peter Smith. Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Mon, Aug 24, 2026 at 11:10 AM shveta malik wrote: > > On Fri, Aug 21, 2026 at 11:00 PM Nisha Moond wrote: > > > > Hi, > > After considering the discussion upthread, I think it is difficult to > > handle all combinations with a simple rule without making the code > > more complex. The main problematic cases seem to be when a > > partition/inherited child is in a different schema from its root. > > > > For example, s1.root has two partitions: s1.p1 and s2.p2. > > With the current patch v28/v29, if we do not allow: > > CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA s1 EXCEPT (s1.root), s2; (ERROR) > > then, we would also need to block several DDL operations to ensure the > > publication can never reach this state later. Say if s2.p2 does not > > exist yet and the creation of pub1 succeeds, then: > > > > 1. A partition of s1.root cannot later be created in another schema: > > Block: CREATE TABLE s2.p2 PARTITION OF s1.root ... > > > > 2. A partition from a published schema cannot be attached to an excluded root: > > Block: ALTER TABLE s1.root ATTACH PARTITION s2.p2 ... > > > > 3. A partition of the excluded root cannot be moved to another schema: > > Block: ALTER TABLE s1.p1 SET SCHEMA s2; > > > > 4. Another schema s3 having s3.p3 (root's part) cannot later be added > > to the publication: > > Block: ALTER PUBLICATION pub1 ADD TABLES IN SCHEMA s3; > > > > IMO, especially for cases 1 and 3, table DDL should not depend on > > publication metadata. So I don't think adding these DDL restrictions > > is a good approach. > > I agree with the analysis. > > > > > Another option is to simply allow FOR TABLES IN SCHEMA s1 EXCEPT > > (s1.root), s2; and exclude the full s1.root tree along with s2.p2. as > > suggested at [1] > > However, this conflicts with the other case where FOR TABLES IN SCHEMA > > s1 EXCEPT (s1.root), TABLE s2.p2; is rejected, as discussed earlier. > > > > So the question is whether we can simplify the rule further. > > On HEAD, I tested combinations where multiple publications in the same > > subscription have conflicting rules. > > For example: > > pub1: FOR ALL TABLES EXCEPT (s1.root); > > pub2: FOR TABLE s1.root; > > > > If the subscription includes both publications, s1.root is still > > replicated through pub2. > > > > Similarly: > > pub1: FOR ALL TABLES EXCEPT (s1.root); > > pub2: FOR TABLE s1.p1; > > > > and > > > > pub1: FOR ALL TABLES EXCEPT (s1.root); > > pub2: FOR TABLE s2.p2; > > > > In both cases, the subscriber receives s1.p1 / s2.p2 through pub2. > > Okay. I see these cases but I don't think we can comapre these cases > with single publication case. > > > This is because pgoutput makes the publication decision independently > > for each publication. So effectively, INCLUSION wins over EXCLUSION. I > > think we could apply the same rule to the publication definition > > itself. > > > > For example: (Partitions case) > > > > 1. FOR TABLES IN SCHEMA s1 EXCEPT (s1.root), s2; > > -- Exclude s1.root and its children in s1, such as s1.p1. > > -- Publish s2.p2 because s2 is explicitly included. > > > > The limitation is that there is still no way to exclude the complete > > s1.root tree when publishing both s1 and s2. This could potentially be > > addressed later by allowing partition children in the EXCEPT clause. > > > > 2. FOR TABLE s1.p1, FOR TABLES IN SCHEMA s1 EXCEPT (s1.root); > > -- Allow s1.p1 to be published. The EXCEPT only excludes s1.root and > > other children in the same schema. > > > > 3. FOR TABLE s2.p2, FOR TABLES IN SCHEMA s1 EXCEPT (s1.root); > > -- Same as case 1. Exclude s1.root and its children in s1, while > > s2.p2 is published. > > > > 4. FOR TABLE s1.root, FOR TABLES IN SCHEMA s1 EXCEPT (s1.root); > > -- Allow s1.root to be published and ignore the EXCEPT entry, with a > > notice/warning. > > > > For partitions, we may need some changes in pgoutput and the relevant > > ancestor lookup code to ensure inclusion always wins over exclusion. > > > > I think the same rule can simplify inheritance trees as well: > > > > 5. FOR TABLES IN SCHEMA s1 EXCEPT (TABLE s1.parent), s2; > > -- Exclude s1.parent and its children in s1, but publish s2.child. > > > > 6. FOR TABLE s1.parent, TABLES IN SCHEMA s2 EXCEPT (TABLE s2.child); > > -- Publish the full s1.parent tree. The explicit inclusion of > > s1.parent tree overrides the exclusion of s2.child, with a > > notice/warning. > > > > 7. FOR TABLE s2.child, TABLES IN SCHEMA s1 EXCEPT (TABLE s1.parent); > > -- Same as case 5: publish s2.child, while excluding s1.parent and > > its children in s1. > > > > 8. FOR TABLES IN SCHEMA s1, TABLES IN SCHEMA s2 EXCEPT (TABLE s2.child); > > -- Same as case 6: publish the full s1.parent tree, since s1 is > > included, so s2.child is published. The inclusion overrides the > > EXCEPT, with a notice/warning. > > > > With this approach, I don't think we need additional DDL restrictions. > > New tables/partitions added under an explicitly included schema would > > simply be included. > > > > I tried to cover the conflicting combinations including the ones > > discussed upthread. Please let me know if there are other cases that > > would still be ambiguous with this rule. > > > > Thoughts? > > > > While the proposal to let inclusion win over conflicting rules avoids > adding complex alter-table restrictions, I think it has a significant > drawback: relying on a NOTICE/warning to override an explicit EXCEPT > clause feels risky. > > An EXCEPT clause is an explicit data-filtering boundary. If a DBA/user > explicitly excludes a table or its child, for example, because it > contains sensitive data, I don't think we should silently override > that exclusion just because another inclusion rule happens to cover > the same relation indirectly. A NOTICE or warning could easily be > missed, and we could end up publishing data that the user explicitly > intended to exclude. So, to me, the concern is not just that the > behavior could be surprising; we would actually be publishing > something that the user explicitly asked us not to publish. > > An Alternative Solution could be 'Strict Schema-Bound Isolation' > (Peter also suggested something similar earlier if I am not wrong, > which did not reach to conclusion). To avoid both DDL-blocking and > unsafe Exclusion overrides, we could adopt a Strict Schema-Bound > Isolation model. > > Core rule: Schema boundaries act as hard firewalls. An EXCEPT clause > defined for a specific schema applies only to objects physically > residing in that schema. Inclusion or exclusion through one schema > does not recursively "bleed over" into another schema or affect > partitions or inherited children that reside there. > > How this resolves the cases from your email: > > a). Clean Cross-Schema Separation (Cases 1, 3, 5, 7) > ---------------------------------- > Partitions: > 1. FOR TABLES IN SCHEMA s1 EXCEPT (s1.root), s2; > --s1.root excluded, everything under s2 even if it is parition of > s1.root is published > > 3. FOR TABLE s2.p2, FOR TABLES IN SCHEMA s1 EXCEPT (s1.root); > --s1.root excluded, s2.p2 published > > Inheritance: > 5. FOR TABLES IN SCHEMA s1 EXCEPT (TABLE s1.parent), s2; > --s1.parent excluded, everything under s2 even if it is child of > s1.parent is published. > > 7. FOR TABLE s2.child, TABLES IN SCHEMA s1 EXCEPT (TABLE s1.parent); > --s1.parent excluded, s2.child is published as it is explcilty mentioned. > > > b. Local Exceptions are Respected (Cases 6 & 8) > ---------------------------------- > 6. FOR TABLE s1.parent, TABLES IN SCHEMA s2 EXCEPT (TABLE s2.child); > --s1.parent published with all its children present in s1, > s2.child is excluded. Based on experiments done by Peter in [1], I would like to revise this behavious. In this case: --s1.parent and all its children belonging to any schema should be published because inclusion of s1.parent is not schema-bound. But s2.child should be excluded as explicitly given by the user. > > 8. FOR TABLES IN SCHEMA s1, TABLES IN SCHEMA s2 EXCEPT (TABLE > s2.child); > --s1.parent published with all its children present in s1, > s2.child is excluded. Here s1.s1.parent is schema-bound as it is included by schema s1, and thus the behaviour I stated above remains the same. [1] https://www.postgresql.org/message-id/CAHut%2BPvpFR0%3D-AT_0QfjtWFov5ZT4yrfJgbAd-N7w%3DCzSm708g%40mail.gmail.com > > c. Local Table Precedence within the Same Schema (Cases 2 & 4) > ---------------------------------- > 2. FOR TABLE s1.p1, FOR TABLES IN SCHEMA s1 EXCEPT (s1.root); > -- parition s1.p1 is published. s1.root and other paritions in the > same schema are excluded. The same rule applies to inherited tables > too. > > 4. FOR TABLE s1.root, FOR TABLES IN SCHEMA s1 EXCEPT (s1.root); > --This is clearly an ERROR scenario as user is giving exact same > inclusion and exclusion for the same schema. > > > NOTE: > The case where parition is included while ROOT is excluded and > publish_via_partition_root is TRUE (e.g., case a.1), we may not even > publish parition itself. Check this once please. But this case will > not be any different from existing case on HEAD where partition alone > is included in publication with publish_via_partition_root=true. > Example: > > create publication pub1 for table s2.part with > (publish_via_partition_root = true); > > ~~ > > > Benefits I see: > 1) We avoid any other issues requiring DDL blocking. Let me know if > you see any. > b) We follow what the user explicitly asked to EXCLUDE without any > notice/warning to override their choice. > c) We can clearly document it: 'Inclusion/exclusion rules do not bleed > over to other schema. > > Nisha, can you please review this in detail? I might have overlooked something. > > thanks > Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
On Mon, Aug 24, 2026 at 12:55 PM Peter Smith wrote: > > On Mon, Aug 24, 2026 at 3:40 PM shveta malik wrote: > > > > On Fri, Aug 21, 2026 at 11:00 PM Nisha Moond wrote: > > > > > > Hi, > > > After considering the discussion upthread, I think it is difficult to > > > handle all combinations with a simple rule without making the code > > > more complex. The main problematic cases seem to be when a > > > partition/inherited child is in a different schema from its root. > > > > > > For example, s1.root has two partitions: s1.p1 and s2.p2. > > > With the current patch v28/v29, if we do not allow: > > > CREATE PUBLICATION pub1 FOR TABLES IN SCHEMA s1 EXCEPT (s1.root), s2; (ERROR) > > > then, we would also need to block several DDL operations to ensure the > > > publication can never reach this state later. Say if s2.p2 does not > > > exist yet and the creation of pub1 succeeds, then: > > > > > > 1. A partition of s1.root cannot later be created in another schema: > > > Block: CREATE TABLE s2.p2 PARTITION OF s1.root ... > > > > > > 2. A partition from a published schema cannot be attached to an excluded root: > > > Block: ALTER TABLE s1.root ATTACH PARTITION s2.p2 ... > > > > > > 3. A partition of the excluded root cannot be moved to another schema: > > > Block: ALTER TABLE s1.p1 SET SCHEMA s2; > > > > > > 4. Another schema s3 having s3.p3 (root's part) cannot later be added > > > to the publication: > > > Block: ALTER PUBLICATION pub1 ADD TABLES IN SCHEMA s3; > > > > > > IMO, especially for cases 1 and 3, table DDL should not depend on > > > publication metadata. So I don't think adding these DDL restrictions > > > is a good approach. > > > > I agree with the analysis. > > > > > > > > Another option is to simply allow FOR TABLES IN SCHEMA s1 EXCEPT > > > (s1.root), s2; and exclude the full s1.root tree along with s2.p2. as > > > suggested at [1] > > > However, this conflicts with the other case where FOR TABLES IN SCHEMA > > > s1 EXCEPT (s1.root), TABLE s2.p2; is rejected, as discussed earlier. > > > > > > So the question is whether we can simplify the rule further. > > > On HEAD, I tested combinations where multiple publications in the same > > > subscription have conflicting rules. > > > For example: > > > pub1: FOR ALL TABLES EXCEPT (s1.root); > > > pub2: FOR TABLE s1.root; > > > > > > If the subscription includes both publications, s1.root is still > > > replicated through pub2. > > > > > > Similarly: > > > pub1: FOR ALL TABLES EXCEPT (s1.root); > > > pub2: FOR TABLE s1.p1; > > > > > > and > > > > > > pub1: FOR ALL TABLES EXCEPT (s1.root); > > > pub2: FOR TABLE s2.p2; > > > > > > In both cases, the subscriber receives s1.p1 / s2.p2 through pub2. > > > > Okay. I see these cases but I don't think we can comapre these cases > > with single publication case. > > > > > This is because pgoutput makes the publication decision independently > > > for each publication. So effectively, INCLUSION wins over EXCLUSION. I > > > think we could apply the same rule to the publication definition > > > itself. > > > > > > For example: (Partitions case) > > > > > > 1. FOR TABLES IN SCHEMA s1 EXCEPT (s1.root), s2; > > > -- Exclude s1.root and its children in s1, such as s1.p1. > > > -- Publish s2.p2 because s2 is explicitly included. > > > > > > The limitation is that there is still no way to exclude the complete > > > s1.root tree when publishing both s1 and s2. This could potentially be > > > addressed later by allowing partition children in the EXCEPT clause. > > > > > > 2. FOR TABLE s1.p1, FOR TABLES IN SCHEMA s1 EXCEPT (s1.root); > > > -- Allow s1.p1 to be published. The EXCEPT only excludes s1.root and > > > other children in the same schema. > > > > > > 3. FOR TABLE s2.p2, FOR TABLES IN SCHEMA s1 EXCEPT (s1.root); > > > -- Same as case 1. Exclude s1.root and its children in s1, while > > > s2.p2 is published. > > > > > > 4. FOR TABLE s1.root, FOR TABLES IN SCHEMA s1 EXCEPT (s1.root); > > > -- Allow s1.root to be published and ignore the EXCEPT entry, with a > > > notice/warning. > > > > > > For partitions, we may need some changes in pgoutput and the relevant > > > ancestor lookup code to ensure inclusion always wins over exclusion. > > > > > > I think the same rule can simplify inheritance trees as well: > > > > > > 5. FOR TABLES IN SCHEMA s1 EXCEPT (TABLE s1.parent), s2; > > > -- Exclude s1.parent and its children in s1, but publish s2.child. > > > > > > 6. FOR TABLE s1.parent, TABLES IN SCHEMA s2 EXCEPT (TABLE s2.child); > > > -- Publish the full s1.parent tree. The explicit inclusion of > > > s1.parent tree overrides the exclusion of s2.child, with a > > > notice/warning. > > > > > > 7. FOR TABLE s2.child, TABLES IN SCHEMA s1 EXCEPT (TABLE s1.parent); > > > -- Same as case 5: publish s2.child, while excluding s1.parent and > > > its children in s1. > > > > > > 8. FOR TABLES IN SCHEMA s1, TABLES IN SCHEMA s2 EXCEPT (TABLE s2.child); > > > -- Same as case 6: publish the full s1.parent tree, since s1 is > > > included, so s2.child is published. The inclusion overrides the > > > EXCEPT, with a notice/warning. > > > > > > With this approach, I don't think we need additional DDL restrictions. > > > New tables/partitions added under an explicitly included schema would > > > simply be included. > > > > > > I tried to cover the conflicting combinations including the ones > > > discussed upthread. Please let me know if there are other cases that > > > would still be ambiguous with this rule. > > > > > > Thoughts? > > > > > > > While the proposal to let inclusion win over conflicting rules avoids > > adding complex alter-table restrictions, I think it has a significant > > drawback: relying on a NOTICE/warning to override an explicit EXCEPT > > clause feels risky. > > > > An EXCEPT clause is an explicit data-filtering boundary. If a DBA/user > > explicitly excludes a table or its child, for example, because it > > contains sensitive data, I don't think we should silently override > > that exclusion just because another inclusion rule happens to cover > > the same relation indirectly. A NOTICE or warning could easily be > > missed, and we could end up publishing data that the user explicitly > > intended to exclude. So, to me, the concern is not just that the > > behavior could be surprising; we would actually be publishing > > something that the user explicitly asked us not to publish. > > +1 If the user says EXCEPT then the only safe thing to do is what the > user asked for. To do otherwise is effectively saying: “We see you > wanted to exclude this table but we are going to publish it anyway > because we figure you just made a mistake”. > > > > > An Alternative Solution could be 'Strict Schema-Bound Isolation' > > (Peter also suggested something similar earlier if I am not wrong, > > which did not reach to conclusion). To avoid both DDL-blocking and > > unsafe Exclusion overrides, we could adopt a Strict Schema-Bound > > Isolation model. > > > > Core rule: Schema boundaries act as hard firewalls. An EXCEPT clause > > defined for a specific schema applies only to objects physically > > residing in that schema. Inclusion or exclusion through one schema > > does not recursively "bleed over" into another schema or affect > > partitions or inherited children that reside there. > > Something seems off here. The inclusion rules are already > well-established. Partitioning really *does* bleed already into other > unpublished schemas currently on HEAD. > > e.g. > CREATE PUBLICATION pub FOR TABLES IN SCHEMA s1; > > Inheritance: > s1.parent INCLUDED > s1.child INCLUDED > s2.child NOT INCLUDED > > Partitioning: > s1.root INCLUDED > s1.part INCLUDED > s2.part INCLUDED (it cascades to other schemas) > Right I found this case specially documented also in [1]: See: "When a partitioned table is published via a schema-level publication, all of its existing and future partitions are implicitly considered to be part of the publication, regardless of whether they are from the publication schema or not." Thus, on re-thinking, we can apply a similar EXCLUSION rule to partitions: excluding a partition root excludes all of its partitions, even if their schemas are included separately. The only addition I would make is that if a partition is explicitly included by name, then it remains included. Partition Case Rules: ----------------------------------- a) By default, mentioning a 'partition root 'means that its entire partition tree is included/excluded, irrespective of schema boundaries, consistent with HEAD. b) An explicitly mentioned partition is allowed and takes precedence over the partition-tree exclusion. Going through the cases again: 1. FOR TABLES IN SCHEMA s1 EXCEPT (s1.root), TABLES IN SCHEMA s2; Excludes root: By default all its parition gets excluded, even the ones present in s2. 2. FOR TABLES IN SCHEMA s1 EXCEPT (s1.root), FOR TABLE s1.p1; Excludes s1.root: By default all its partitions get excluded except s1.p1. s1.p1 is still published as the user has explicitly mentioned it. 3. FOR TABLES IN SCHEMA s1 EXCEPT (s1.root), FOR TABLE s2.p2; Excludes s1.root: By default all its partitions get excluded except s2.p2. s2.p2 is still published as the user has explicitly mentioned it. 4. FOR TABLE s1.root, FOR TABLES IN SCHEMA s1 EXCEPT (s1.root); ERROR scenario: We cannot have the exact same table (root in this case) included and excluded. Inheritance Case Rules: ----------------------------------- a) An EXCEPT clause associated with a schema does not follow the inheritance hierarchy across schema boundaries. It only excludes the parent and its descendants selected through that schema. b) An explicitly mentioned child is allowed and takes precedence over an exclusion inherited through the parent. Going through the cases again: 5. FOR TABLES IN SCHEMA s1 EXCEPT (TABLE s1.parent), TABLES IN SCHEMA s2; --s1.parent and its children in s1 are excluded; while s2.child is published. --if 'ONLY' is mentioned in EXCEPT, only s1.parent is excluded; all its children in s1 and s2 are published. 6. FOR TABLE s1.parent, TABLES IN SCHEMA s2 EXCEPT (TABLE s2.child); --s1.parent and all its children belonging to any schema should be published because inclusion of s1.parent is not schema-bound. This would mean, any child present in s3 would also be published, similar to HEAD (see [2]). s2.child will be excluded, as explicitly given by the user. --if 'ONLY' s1.parent is mentioned, only s1.parent is published. s2.child is excluded by EXCEPT rule of s2. 7. FOR TABLE s2.child, TABLES IN SCHEMA s1 EXCEPT (TABLE s1.parent); -- s1.parent and all its children in s1 are excluded; s2.child is published. -- if 'ONLY' is mentioned in EXCEPT, only s1.parent is excluded; all its children in s1 are published along with s2.child. 8. FOR TABLES IN SCHEMA s1, TABLES IN SCHEMA s2 EXCEPT (TABLE s2.child); --s1.parent is published with all its children present in s1 alone; s2.child is excluded. This would mean unlike case 6, if any child is present in s3, that will not be published. Taking the behaviour of HEAD as the base (see [2]). 9. A new case: FOR TABLES IN SCHEMA s1 EXCEPT (TABLE s1.parent), TABLE s1.child; --s1.parent and its children in s1 are excluded; while s1.child is still published. [1]: https://www.postgresql.org/docs/19/sql-createpublication.html [2]: https://www.postgresql.org/message-id/CAHut%2BPvpFR0%3D-AT_0QfjtWFov5ZT4yrfJgbAd-N7w%3DCzSm708g%40mail.gmail.com ~~ Please reveiw this and let me know. thanks Shveta
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Tue, Sep 1, 2026 at 12:13 PM Peter Smith wrote: > > On Tue, Aug 25, 2026 at 6:49 PM shveta malik wrote: > > > > On Tue, Aug 25, 2026 at 1:05 PM Peter Smith wrote: > > > > > > On Mon, Aug 24, 2026 at 7:55 PM shveta malik wrote: > > > > > > > ... > > > > > > > > > > > > Partition Case Rules: > > > > ----------------------------------- > > > > a) By default, mentioning a 'partition root 'means that its entire > > > > partition tree is included/excluded, irrespective of schema > > > > boundaries, consistent with HEAD. > > > > b) An explicitly mentioned partition is allowed and takes precedence > > > > over the partition-tree exclusion. > > > > > > OK. > > > Also (c). A partition cannot be mentioned as an explicit *exclusion* > > > because we only allow partition roots in EXCEPT. > > > Also (d). "EXCEPT (TABLE ONLY root)" -- the ONLY is completely ignored > > > for partitions so that is identical to "EXCEPT (TABLE root)", right? > > > > Right. > > > > > > > > > > Going through the cases again: > > > > 1. FOR TABLES IN SCHEMA s1 EXCEPT (s1.root), TABLES IN SCHEMA s2; > > > > Excludes root: By default all its parition gets excluded, even the > > > > ones present in s2. > > > > > > > > 2. FOR TABLES IN SCHEMA s1 EXCEPT (s1.root), FOR TABLE s1.p1; > > > > Excludes s1.root: By default all its partitions get excluded except > > > > s1.p1. s1.p1 is still published as the user has explicitly mentioned > > > > it. > > > > > > > > 3. FOR TABLES IN SCHEMA s1 EXCEPT (s1.root), FOR TABLE s2.p2; > > > > Excludes s1.root: By default all its partitions get excluded except > > > > s2.p2. s2.p2 is still published as the user has explicitly mentioned > > > > it. > > > > > > > > 4. FOR TABLE s1.root, FOR TABLES IN SCHEMA s1 EXCEPT (s1.root); > > > > ERROR scenario: We cannot have the exact same table (root in this > > > > case) included and excluded. > > > > > > > > > > > > Inheritance Case Rules: > > > > ----------------------------------- > > > > a) An EXCEPT clause associated with a schema does not follow the > > > > inheritance hierarchy across schema boundaries. It only excludes the > > > > parent and its descendants selected through that schema. > > > > b) An explicitly mentioned child is allowed and takes precedence over > > > > an exclusion inherited through the parent. > > > > > > OK. > > > For (b) you said explicit child takes precedence over exclusion > > > inherited by parent. > > > I think example is: TABLE IN SCHEMA s1 (EXCEPT s1.parent), TABLE > > > s1.child; --- child stays > > > > yes. Right. > > > > > But your rules don't say anything what happens for explicit child > > > taking precedence inherited **inclusion** > > > e.g. TABLE s1.parent, TABLES IN SCHEMA s1 EXCEPT (TABLE s1.child); -- > > > I think child excluded, right? > > > > Yes. The child is excluded because the user explicitly mentioned it. > > > > > > > > > > Please reveiw this and let me know. > > > > > > > > > > AFAICT all your example SQL results LGTM, but, IMO there are many > > > dozens more combinations (I have itemized over 100 variations so > > > far...). Sure, all these might all fall into just a few same-behaviour > > > categories, but OTOH there could be some unaccounted edge-cases. I am > > > currently trying to make a giant matrix of them all, but it is taking > > > much longer than expected. > > > > yes, the matrix will help; otherwise, we may end up missing some scenarios. > > > > > The suggested rules might still be OK -- I just don't know yet. > > > > > > ~~~ > > > Each time new EXCEPT rules are proposed in this thread, they come with > a worked examples, but I felt there was still a risk that other > combinations could be broken and go unnoticed. Then, when a > problematic combination is later encountered, we're back to square one > again. > > To help avoid that, I made a matrix of *many* combinations (~300), > covering both inheritance and partitioning. Thanks Peter. I think that if we come up with a new proposal, we should refer to this matrix to see that all the cases resolve correctly. I have gone through the matrix and it looks good to me. It should serve as a starting point to finalize any proposal. > Also, TBH I was getting lost keeping track of what "case 1", "case 2", > etc. meant. In this matrix, every case can instead be referred to like > "11x23" — a combo of clauses "11" and "23" (the first digit being the > schema). This makes it easy to refer to any of the 300 combinations > unambiguously. Furthermore, the same combination numbers (e.g. 11x23) > mean the same thing in both the INHERITANCE and PARTITIONING matrices, > so the two can be directly compared. > > PSA the doc containing the matrices, rules, results, diagrams, and a > key for interpreting them. > > My conclusion is that the rules proposed by Shveta ([1] and also > included in the document) are sound; they can be applied to all these > combinations to give unambiguous results. FWIW, my AI checking > confirms the matrix results are consistent. > > Of course, there are more possible variations (e.g. diamond > inheritance shapes), but IMO these 300 test cases give a much more > solid starting point. > > ====== > [1] https://www.postgresql.org/message-id/CAJpy0uAoRpAoWHWBrGmkCXeEEeMa9R0GXPmKmCrrwLHvgmzOfQ%40mail.gmail.com > > Kind Regards, > Peter Smith. > Fujitsu Australia
Re: Support EXCEPT for TABLES IN SCHEMA publications
От:
Mihail Nikalayeu <mihailnikalayeu@gmail.com>
Дата:
Hello! On Thu, Jul 16, 2026, shveta malik wrote: > Okay thanks. I am able to reproduce the crash on HEAD now. We can > pursue this in separate thread. For the archives: that separate thread is [1] and its entry [2]. [1]: https://www.postgresql.org/message-id/flat/CADzfLwWoFPT%2Ba73%3DA%3DbsNWRMZQ98NpBEMgE%3Dt1FS4O4_%3DQVLfA%40mail.gmail.com [2]: https://commitfest.postgresql.org/patch/7351/ Best regards, Mikhail.