aboutsummaryrefslogtreecommitdiff
path: root/src/bin/psql/describe.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2017-06-20 12:25:07 -0400
committerPeter Eisentraut <peter_e@gmx.net>2017-06-20 12:35:02 -0400
commita2141c42f9ebc51b4501a4fafea9dd3fb7eda23d (patch)
tree6a273b7f730515593cdd6ba0e6fa8e19575d3e59 /src/bin/psql/describe.c
parent20d7d68b098dde6106e6c382e787c8b10c4403df (diff)
downloadpostgresql-a2141c42f9ebc51b4501a4fafea9dd3fb7eda23d.tar.gz
postgresql-a2141c42f9ebc51b4501a4fafea9dd3fb7eda23d.zip
Tweak publication fetching in psql
Viewing a table with \d in psql also shows the publications at table is in. If a publication is concurrently dropped, this shows an error, because the view pg_publication_tables internally uses pg_get_publication_tables(), which uses a catalog snapshot. This can be particularly annoying if a for-all-tables publication is concurrently dropped. To avoid that, write the query in psql differently. Expose the function pg_relation_is_publishable() to SQL and write the query using that. That still has a risk of being affected by concurrent catalog changes, but in this case it would be a table drop that causes problems, and then the psql \d command wouldn't be interesting anymore anyway. Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
Diffstat (limited to 'src/bin/psql/describe.c')
-rw-r--r--src/bin/psql/describe.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index ea0e8af2ecd..0e19e94841c 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -2536,12 +2536,16 @@ describeOneTableDetails(const char *schemaname,
if (pset.sversion >= 100000)
{
printfPQExpBuffer(&buf,
- "SELECT pub.pubname\n"
- " FROM pg_catalog.pg_publication pub,\n"
- " pg_catalog.pg_get_publication_tables(pub.pubname)\n"
- "WHERE relid = '%s'\n"
+ "SELECT pubname\n"
+ "FROM pg_catalog.pg_publication p\n"
+ "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
+ "WHERE pr.prrelid = '%s'\n"
+ "UNION ALL\n"
+ "SELECT pubname\n"
+ "FROM pg_catalog.pg_publication p\n"
+ "WHERE p.puballtables AND pg_relation_is_publishable('%s')\n"
"ORDER BY 1;",
- oid);
+ oid, oid);
result = PSQLexec(buf.data);
if (!result)