From df6670d55230097be3f36c26ff9181c98846c06d Mon Sep 17 00:00:00 2001 From: Vignesh C Date: Tue, 31 Aug 2021 18:25:11 +0530 Subject: [PATCH v44 5/5] Add new "pg_publication_objects" view to display "TABLE"/"SCHEMA" publication objects A new "pg_publication_objects" view is added, to display table/schema object information associated with publications. Author: Vignesh C Reviewed-by: Amit Kapila, Hou Zhijie, Greg Nancarrow, Masahiko Sawada, Peter Eisentraut, Tom Lane, Peter Smith, Ajin Cherian, Rahila Syed, Bharath Rupireddy Tested-by: Tang Haiying Discussion: https://www.postgresql.org/message-id/CALDaNm0OANxuJ6RXqwZsM1MSY4s19nuH3734j4a72etDwvBETQ%40mail.gmail.com --- doc/src/sgml/catalogs.sgml | 70 ++++++++++++++++++++++++++++ src/backend/catalog/system_views.sql | 19 ++++++++ src/test/regress/expected/rules.out | 15 ++++++ 3 files changed, 104 insertions(+) diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index 7bf132f8cd..a85053ab0b 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -9503,6 +9503,11 @@ SCRAM-SHA-256$<iteration count>:&l publications and their associated tables + + pg_publication_objects + publications and their associated objects + + pg_replication_origin_status information about replication origins, including replication progress @@ -11332,6 +11337,71 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx + + <structname>pg_publication_objects</structname> + + + pg_publication_objects + + + + The view pg_publication_objects provides + information about the mapping between publications and the objects they + contain. Unlike the underlying catalog + pg_publication_rel, + this view expands publications defined as FOR TABLE + and FOR ALL TABLES IN SCHEMA, so for such publications + there will be a row for each eligible object. + + + + <structname>pg_publication_objects</structname> Columns + + + + + Column Type + + + Description + + + + + + + + pubname name + (references pg_publication.pubname) + + + Name of publication + + + + + + objname name + (references pg_namespace.nspname or pg_class.relname) + + + Name of schema or Name of table + + + + + + objtype name + + + The object type: schema or table + + + + +
+
+ <structname>pg_publication_tables</structname> diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 55f6e3711d..f70348e34f 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -362,6 +362,25 @@ CREATE VIEW pg_stats_ext_exprs WITH (security_barrier) AS -- unprivileged users may read pg_statistic_ext but not pg_statistic_ext_data REVOKE ALL ON pg_statistic_ext_data FROM public; +CREATE VIEW pg_publication_objects AS +SELECT + P.pubname, + N.nspname AS objname, + 'schema'::text AS objtype +FROM pg_catalog.pg_publication P + JOIN pg_catalog.pg_publication_namespace S ON P.oid = S.pnpubid + JOIN pg_catalog.pg_namespace N on N.oid = S.pnnspid +UNION +SELECT + P.pubname, + quote_ident(N.nspname) || '.' || quote_ident(C.relname) AS objname, + 'table'::text AS objtype +FROM pg_catalog.pg_publication P + JOIN pg_catalog.pg_publication_rel R ON P.oid = R.prpubid + JOIN pg_catalog.pg_class C ON C.oid = R.prrelid + JOIN pg_catalog.pg_namespace N ON N.oid = C.relnamespace +ORDER BY pubname; + CREATE VIEW pg_publication_tables AS SELECT P.pubname AS pubname, diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 2fa00a3c29..8796f71de2 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1451,6 +1451,21 @@ pg_prepared_xacts| SELECT p.transaction, FROM ((pg_prepared_xact() p(transaction, gid, prepared, ownerid, dbid) LEFT JOIN pg_authid u ON ((p.ownerid = u.oid))) LEFT JOIN pg_database d ON ((p.dbid = d.oid))); +pg_publication_objects| SELECT p.pubname, + n.nspname AS objname, + 'schema'::text AS objtype + FROM ((pg_publication p + JOIN pg_publication_namespace s ON ((p.oid = s.pnpubid))) + JOIN pg_namespace n ON ((n.oid = s.pnnspid))) +UNION + SELECT p.pubname, + ((quote_ident((n.nspname)::text) || '.'::text) || quote_ident((c.relname)::text)) AS objname, + 'table'::text AS objtype + FROM (((pg_publication p + JOIN pg_publication_rel r ON ((p.oid = r.prpubid))) + JOIN pg_class c ON ((c.oid = r.prrelid))) + JOIN pg_namespace n ON ((n.oid = c.relnamespace))) + ORDER BY 1; pg_publication_tables| SELECT p.pubname, n.nspname AS schemaname, c.relname AS tablename -- 2.30.2