From 1092342d1c3e66e6558196f76170ff90e91da0df Mon Sep 17 00:00:00 2001 From: Vignesh C Date: Tue, 31 Aug 2021 18:25:11 +0530 Subject: [PATCH v34 5/5] Implemented pg_publication_objects view. Implemented pg_publication_objects view which displays "FOR TABLE" and "FOR ALL TABLES IN SCHEMA" publications and the objects they contain. --- doc/src/sgml/catalogs.sgml | 70 ++++++++++++++++++++++++++++ src/backend/catalog/system_views.sql | 20 ++++++++ src/test/regress/expected/rules.out | 16 +++++++ 3 files changed, 106 insertions(+) diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index c18a90a691..38293cbdba 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -9501,6 +9501,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 @@ -11330,6 +11335,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..079148a364 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -362,6 +362,26 @@ 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_class C ON C.relnamespace = S.pnnspid + 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..1af7c53abd 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1451,6 +1451,22 @@ 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_class c ON ((c.relnamespace = s.pnnspid))) + 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