From c4ee5dadb20afe509faf36da242c1f97ce88c13d Mon Sep 17 00:00:00 2001 From: Nisha Moond Date: Thu, 30 Jul 2026 10:15:42 +0530 Subject: [PATCH v28 4/4] Documentation Patch --- doc/src/sgml/logical-replication.sgml | 3 +- doc/src/sgml/ref/alter_publication.sgml | 54 ++++++++++++++++++++- doc/src/sgml/ref/create_publication.sgml | 60 ++++++++++++++++++++---- 3 files changed, 104 insertions(+), 13 deletions(-) diff --git a/doc/src/sgml/logical-replication.sgml b/doc/src/sgml/logical-replication.sgml index 3a61e2d6889..eaf2d814ac6 100644 --- a/doc/src/sgml/logical-replication.sgml +++ b/doc/src/sgml/logical-replication.sgml @@ -117,7 +117,8 @@ or FOR ALL SEQUENCES. Unlike tables, sequences can be synchronized at any time. For more information, see . When a publication is - created with FOR ALL TABLES, a table or set of tables can + created with FOR ALL TABLES or + FOR TABLES IN SCHEMA, a table or set of tables can be explicitly excluded from publication using the EXCEPT clause. diff --git a/doc/src/sgml/ref/alter_publication.sgml b/doc/src/sgml/ref/alter_publication.sgml index 86bdc98fd09..c1a60797361 100644 --- a/doc/src/sgml/ref/alter_publication.sgml +++ b/doc/src/sgml/ref/alter_publication.sgml @@ -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 tables_in_schema [, ... ] and publication_all_object is one of: @@ -47,6 +47,10 @@ ALTER PUBLICATION name RENAME TO table_object [ ( column_name [, ... ] ) ] [ WHERE ( expression ) ] +and tables_in_schema is: + + { schema_name | CURRENT_SCHEMA } [ EXCEPT ( except_table_object [, ... ] ) ] + and except_table_object is: TABLE table_object [, ... ] @@ -69,6 +73,9 @@ ALTER PUBLICATION name RENAME TO ADD and DROP clauses will add and remove one or more tables/schemas from the publication. + The EXCEPT clause can be used with + ADD TABLES IN SCHEMA to exclude specific tables from a + schema-level publication. @@ -93,7 +100,11 @@ ALTER PUBLICATION name RENAME TO 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. @@ -211,6 +222,26 @@ ALTER PUBLICATION name RENAME TO + + 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. + + + Dropping a table always removes it from the EXCEPT + clause. + + + + SET ( publication_parameter [= value] [, ... ] ) @@ -301,6 +332,25 @@ ALTER PUBLICATION sales_publication ADD TABLES IN SCHEMA marketing, sales; + + Add schema sales to the publication + sales_publication, excluding the + sales.internal and + sales.drafts tables: + +ALTER PUBLICATION sales_publication ADD TABLES IN SCHEMA sales EXCEPT (TABLE internal, drafts); + + + + + Replace the schema list of sales_publication with + only schema sales, excluding only + sales.drafts table: + +ALTER PUBLICATION sales_publication SET TABLES IN SCHEMA sales EXCEPT (TABLE drafts); + + + Add tables users, departments and schema diff --git a/doc/src/sgml/ref/create_publication.sgml b/doc/src/sgml/ref/create_publication.sgml index 35c28006f60..2de5bedb1c8 100644 --- a/doc/src/sgml/ref/create_publication.sgml +++ b/doc/src/sgml/ref/create_publication.sgml @@ -28,7 +28,7 @@ CREATE PUBLICATION name where publication_object is one of: TABLE table_and_columns [, ... ] - TABLES IN SCHEMA { schema_name | CURRENT_SCHEMA } [, ... ] + TABLES IN SCHEMA tables_in_schema [, ... ] and publication_all_object is one of: @@ -39,6 +39,10 @@ CREATE PUBLICATION name table_object [ ( column_name [, ... ] ) ] [ WHERE ( expression ) ] +and tables_in_schema is: + + { schema_name | CURRENT_SCHEMA } [ EXCEPT ( except_table_object [, ... ] ) ] + and except_table_object is: TABLE table_object [, ... ] @@ -172,6 +176,8 @@ CREATE PUBLICATION name 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. @@ -203,7 +209,7 @@ CREATE PUBLICATION name Marks the publication as one that replicates changes for all tables in the database, including tables created in the future. Tables listed in - EXCEPT clause are excluded from the publication. + the EXCEPT clause are excluded from the publication. @@ -228,13 +234,21 @@ CREATE PUBLICATION name 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, the exclusion applies only to tables in the schema + associated with the EXCEPT clause. - 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. + Once a table is excluded under FOR ALL TABLES, 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; if the table is later + moved back, the exclusion is not restored and must be re-established + with ALTER PUBLICATION. For inherited tables, if ONLY is specified before the @@ -245,12 +259,29 @@ CREATE PUBLICATION name table_name to explicitly indicate that descendant tables are excluded. + + For FOR TABLES IN SCHEMA, an EXCEPT + entry excludes only those descendants that belong to the schema specified + by the corresponding FOR TABLES IN SCHEMA clause. A + descendant in a different schema is not excluded, since the exclusion is + scoped to that schema. Publishing that schema in the same statement is + therefore rejected because the descendant would be both published and + excluded. + 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 - ONLY and * has no effect for - partitioned tables. + all of its partitions from replication, including any partition that + lives in another schema. The optional ONLY and + * has no effect for partitioned tables. + + + Because the exclusion is bound to the schema of the + TABLES IN SCHEMA clause it belongs to, a partition in + another schema is reached only when that schema is not itself published: + publishing it as well would both publish and exclude the same partition, + which is rejected. Excluding such a partition on its own is not possible + either, since a partition may not be named in EXCEPT. There can be a case where a subscription includes multiple publications. @@ -552,6 +583,15 @@ CREATE PUBLICATION production_publication FOR TABLE users, departments, TABLES I CREATE PUBLICATION sales_publication FOR TABLES IN SCHEMA marketing, sales; + + Create a publication that publishes all changes for all the tables present in + the schema sales, except + internal and drafts: + +CREATE PUBLICATION sales_filtered FOR TABLES IN SCHEMA sales EXCEPT (TABLE internal, drafts); + + + Create a publication that publishes all changes for table users, but replicates only columns user_id and -- 2.55.0