From 592f526b788f2c11c0f7b2fe64a3d660d393ab5a Mon Sep 17 00:00:00 2001 From: Vignesh C Date: Fri, 3 Sep 2021 17:46:08 +0530 Subject: [PATCH v30 5/6] Documentation for "FOR ALL TABLES IN SCHEMA" publication. Documentation for "FOR ALL TABLES IN SCHEMA" publication. --- doc/src/sgml/catalogs.sgml | 72 ++++++++++++++++++- doc/src/sgml/ref/alter_publication.sgml | 89 +++++++++++++++++++----- doc/src/sgml/ref/create_publication.sgml | 73 +++++++++++++++++-- 3 files changed, 208 insertions(+), 26 deletions(-) diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index 2f0def9b19..c18a90a691 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -240,6 +240,11 @@ publications for logical replication + + pg_publication_namespace + schema to publication mapping + + pg_publication_rel relation to publication mapping @@ -6236,6 +6241,67 @@ SCRAM-SHA-256$<iteration count>:&l + + <structname>pg_publication_namespace</structname> + + + pg_publication_namespace + + + + The catalog pg_publication_namespace contains the + mapping between schemas and publications in the database. This is a + many-to-many mapping. + + + + <structname>pg_publication_namespace</structname> Columns + + + + + Column Type + + + Description + + + + + + + + oid oid + + + Row identifier + + + + + + pnpubid oid + (references pg_publication.oid) + + + Reference to publication + + + + + + pnnspid oid + (references pg_namespace.oid) + + + Reference to schema + + + + +
+
+ <structname>pg_range</structname> @@ -11276,9 +11342,9 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx information about the mapping between publications and the tables they contain. Unlike the underlying catalog pg_publication_rel, - this view expands - publications defined as FOR ALL TABLES, so for such - publications there will be a row for each eligible table. + this view expands publications defined as FOR ALL TABLES + and FOR ALL TABLES IN SCHEMA, so for such publications + there will be a row for each eligible table. diff --git a/doc/src/sgml/ref/alter_publication.sgml b/doc/src/sgml/ref/alter_publication.sgml index faa114b2c6..af7c946498 100644 --- a/doc/src/sgml/ref/alter_publication.sgml +++ b/doc/src/sgml/ref/alter_publication.sgml @@ -21,12 +21,17 @@ PostgreSQL documentation -ALTER PUBLICATION name ADD TABLE [ ONLY ] table_name [ * ] [, ...] -ALTER PUBLICATION name SET TABLE [ ONLY ] table_name [ * ] [, ...] -ALTER PUBLICATION name DROP TABLE [ ONLY ] table_name [ * ] [, ...] +ALTER PUBLICATION name ADD publication_object [, ...] +ALTER PUBLICATION name SET publication_object [, ...] +ALTER PUBLICATION name DROP publication_object [, ...] ALTER PUBLICATION name SET ( publication_parameter [= value] [, ... ] ) ALTER PUBLICATION name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER } ALTER PUBLICATION name RENAME TO new_name + +where publication_object is one of: + + TABLE [ ONLY ] table_name [ * ] [, ... ] + ALL TABLES IN SCHEMA { schema_name | CURRENT_SCHEMA } [, ... ] @@ -39,14 +44,17 @@ ALTER PUBLICATION name RENAME TO - The first three variants change which tables are part of the publication. - The SET TABLE clause will replace the list of tables in - the publication with the specified one. The ADD TABLE - and DROP TABLE clauses will add and remove one or more - tables from the publication. Note that adding tables to a publication that - is already subscribed to will require a ALTER SUBSCRIPTION - ... REFRESH PUBLICATION action on the subscribing side in order - to become effective. + The first three variants change which tables and/or all tables in schema are + part of the publication. The SET clause will replace + the list of tables and/or all tables in schema in the publication with the + specified one, the existing tables and all tables in schema that were + present in the publication will be removed. The ADD + clause will add one or more tables and/or all tables in schema to the + publication. The DROP clauses will remove one or more + tables and/or all tables in schema from the publication. Note that adding + tables and/or all tables in schema to a publication that is already + subscribed to will require a ALTER SUBSCRIPTION ... REFRESH PUBLICATION + action on the subscribing side in order to become effective. @@ -63,11 +71,24 @@ ALTER PUBLICATION name RENAME TO You must own the publication to use ALTER PUBLICATION. Adding a table to a publication additionally requires owning that table. - To alter the owner, you must also be a direct or indirect member of the new - owning role. The new owner must have CREATE privilege on - the database. Also, the new owner of a FOR ALL TABLES - publication must be a superuser. However, a superuser can change the - ownership of a publication regardless of these restrictions. + The ADD ALL TABLES IN SCHEMA and + SET ALL TABLES IN SCHEMA to a publication requires the + invoking user to be a superuser. To alter the owner, you must also be a + direct or indirect member of the new owning role. The new owner must have + CREATE privilege on the database. Also, the new owner + of a FOR ALL TABLES publication must be a superuser. + However, a superuser can change the ownership of a publication regardless + of these restrictions. + + + + Adding/Setting a table that is part of schema specified in + ALL TABLES IN SCHEMA, adding/setting a schema to a + publication along with same schema's table specified with + TABLE, adding/setting a schema to a publication that + already has a table that is part of specified schema or adding/setting a + table to a publication that already has a table's schema as part of + specified schema is not supported. @@ -97,6 +118,15 @@ ALTER PUBLICATION name RENAME TO + + schema_name + + + Name of an existing schema. + + + + SET ( publication_parameter [= value] [, ... ] ) @@ -141,6 +171,33 @@ ALTER PUBLICATION noinsert SET (publish = 'update, delete'); Add some tables to the publication: ALTER PUBLICATION mypublication ADD TABLE users, departments; + + + + Add some schemas to the publication: + +ALTER PUBLICATION sales_publication ADD ALL TABLES IN SCHEMA marketing_june, sales_june; + + + + + Add some tables and schemas to the publication: + +ALTER PUBLICATION production_publication ADD TABLE users, departments, ALL TABLES IN SCHEMA production; + + + + + Drop some schemas from the publication: + +ALTER PUBLICATION production_quarterly_publication DROP ALL TABLES IN SCHEMA production_july, production_august; + + + + + Set some schemas to the publication: + +ALTER PUBLICATION production_publication SET ALL TABLES IN SCHEMA production_september, production_october; diff --git a/doc/src/sgml/ref/create_publication.sgml b/doc/src/sgml/ref/create_publication.sgml index ff82fbca55..0ca7e7c0e6 100644 --- a/doc/src/sgml/ref/create_publication.sgml +++ b/doc/src/sgml/ref/create_publication.sgml @@ -22,9 +22,14 @@ PostgreSQL documentation CREATE PUBLICATION name - [ FOR TABLE [ ONLY ] table_name [ * ] [, ...] - | FOR ALL TABLES ] + [ FOR ALL TABLES + | FOR publication object [, ... ] ] [ WITH ( publication_parameter [= value] [, ... ] ) ] + +where publication object is one of: + + TABLE [ ONLY ] table_name [ * ] [, ... ] + ALL TABLES IN SCHEMA { schema_name | CURRENT_SCHEMA } [, ... ] @@ -86,6 +91,11 @@ CREATE PUBLICATION name partition are also published via publications that its ancestors are part of. + + + Specifying a table that is part of schema specified in + FOR ALL TABLES IN SCHEMA option is not supported. + @@ -99,6 +109,28 @@ CREATE PUBLICATION name + + FOR ALL TABLES IN SCHEMA + + + Marks the publication as one that replicates changes for all tables in + the specified list of schemas, including tables created in the future. + + + + Specifying a schema along with schema's table specified as part of + FOR TABLE option is not supported. + + + + Only persistent base tables and partitioned tables present in the schema + will be included as part of the publication. Temporary tables, unlogged + tables, foreign tables, materialized views, and regular views from the + schema will not be part of the publication. + + + + WITH ( publication_parameter [= value] [, ... ] ) @@ -153,9 +185,10 @@ CREATE PUBLICATION name Notes - If neither FOR TABLE nor FOR ALL - TABLES is specified, then the publication starts out with an - empty set of tables. That is useful if tables are to be added later. + If FOR TABLE, FOR ALL TABLES or + FOR ALL TABLES IN SCHEMA is not specified, then the + publication starts out with an empty set of tables. That is useful if + tables or schemas are to be added later. @@ -171,8 +204,9 @@ CREATE PUBLICATION name To add a table to a publication, the invoking user must have ownership - rights on the table. The FOR ALL TABLES clause requires - the invoking user to be a superuser. + rights on the table. The FOR ALL TABLES and + FOR ALL TABLES IN SCHEMA clause requires the invoking + user to be a superuser. @@ -222,6 +256,31 @@ CREATE PUBLICATION alltables FOR ALL TABLES; CREATE PUBLICATION insert_only FOR TABLE mydata WITH (publish = 'insert'); + + + + + Create a publication that publishes all changes for all the tables present in + the schema "production": + +CREATE PUBLICATION production_publication FOR ALL TABLES IN SCHEMA production; + + + + + Create a publication that publishes all changes for tables "users" and + "departments" and that publishes all changes for all the tables present in + the schema "production": + +CREATE PUBLICATION production_publication FOR TABLE users, departments, ALL TABLES IN SCHEMA production; + + + + + Create a publication that publishes all changes for all the tables present in + the schemas "marketing" and "sales": + +CREATE PUBLICATION sales_publication FOR ALL TABLES IN SCHEMA marketing, sales; -- 2.30.2