From: Justin Pryzby Date: Fri, 17 Dec 2021 09:35:46 -0600 Subject: [PATCH 4/4] Move the double-plus "Size" columns to the right \dn, \dA, \db, \l, \d and \dP+ It doesn't make much sense that one cannot show a database's default tablespace without also showing its size, and stat()ing every segment of every relation in the DB. --- src/bin/psql/describe.c | 42 ++++++++++++++--------- src/test/regress/expected/psql.out | 54 +++++++++++++++--------------- 2 files changed, 53 insertions(+), 43 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 220262aa84c..9f73e90df23 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -234,11 +234,6 @@ describeTablespaces(const char *pattern, int verbose) appendPQExpBufferStr(&buf, ",\n "); printACLColumn(&buf, "spcacl"); - if (verbose > 1) - appendPQExpBuffer(&buf, - ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\"", - gettext_noop("Size")); - appendPQExpBuffer(&buf, ",\n spcoptions AS \"%s\"" ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"", @@ -246,6 +241,11 @@ describeTablespaces(const char *pattern, int verbose) gettext_noop("Description")); } + if (verbose > 1) + appendPQExpBuffer(&buf, + ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\"", + gettext_noop("Size")); + appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_tablespace\n"); @@ -941,17 +941,22 @@ listAllDbs(const char *pattern, int verbose) gettext_noop("Locale Provider")); appendPQExpBufferStr(&buf, " "); printACLColumn(&buf, "d.datacl"); - if (verbose > 1) + + if (verbose > 0) appendPQExpBuffer(&buf, - ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n" - " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n" - " ELSE 'No Access'\n" - " END as \"%s\"" ",\n t.spcname as \"%s\"" ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"", - gettext_noop("Size"), gettext_noop("Tablespace"), gettext_noop("Description")); + + if (verbose > 1) + appendPQExpBuffer(&buf, + ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n" + " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n" + " ELSE 'No Access'\n" + " END as \"%s\"", + gettext_noop("Size")); + appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_database d\n"); if (verbose > 0) @@ -3898,10 +3903,13 @@ listTables(const char *tabtypes, const char *pattern, int verbose, bool showSyst gettext_noop("Access method")); appendPQExpBuffer(&buf, - ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\"" ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"", - gettext_noop("Size"), gettext_noop("Description")); + + if (verbose > 1) + appendPQExpBuffer(&buf, + ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\"", + gettext_noop("Size")); } appendPQExpBufferStr(&buf, @@ -4082,6 +4090,11 @@ listPartitionedTables(const char *reltypes, const char *pattern, int verbose) gettext_noop("Table")); if (verbose > 0) + appendPQExpBuffer(&buf, + ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"", + gettext_noop("Description")); + + if (verbose > 1) { if (showNested) { @@ -4098,9 +4111,6 @@ listPartitionedTables(const char *reltypes, const char *pattern, int verbose) ",\n s.tps as \"%s\"", gettext_noop("Total size")); - appendPQExpBuffer(&buf, - ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"", - gettext_noop("Description")); } appendPQExpBufferStr(&buf, diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out index 60acbd1241e..8da23d7216c 100644 --- a/src/test/regress/expected/psql.out +++ b/src/test/regress/expected/psql.out @@ -2857,47 +2857,47 @@ Access method: heap -- AM is displayed for tables, indexes and materialized views. \d+ - List of relations - Schema | Name | Type | Owner | Persistence | Access method | Size | Description ------------------+--------------------+-------------------+----------------------+-------------+---------------+---------+------------- - tableam_display | mat_view_heap_psql | materialized view | regress_display_role | permanent | heap_psql | 0 bytes | - tableam_display | tbl_heap | table | regress_display_role | permanent | heap | 0 bytes | - tableam_display | tbl_heap_psql | table | regress_display_role | permanent | heap_psql | 0 bytes | - tableam_display | view_heap_psql | view | regress_display_role | permanent | | 0 bytes | + List of relations + Schema | Name | Type | Owner | Persistence | Access method | Description +-----------------+--------------------+-------------------+----------------------+-------------+---------------+------------- + tableam_display | mat_view_heap_psql | materialized view | regress_display_role | permanent | heap_psql | + tableam_display | tbl_heap | table | regress_display_role | permanent | heap | + tableam_display | tbl_heap_psql | table | regress_display_role | permanent | heap_psql | + tableam_display | view_heap_psql | view | regress_display_role | permanent | | (4 rows) \dt+ - List of relations - Schema | Name | Type | Owner | Persistence | Access method | Size | Description ------------------+---------------+-------+----------------------+-------------+---------------+---------+------------- - tableam_display | tbl_heap | table | regress_display_role | permanent | heap | 0 bytes | - tableam_display | tbl_heap_psql | table | regress_display_role | permanent | heap_psql | 0 bytes | + List of relations + Schema | Name | Type | Owner | Persistence | Access method | Description +-----------------+---------------+-------+----------------------+-------------+---------------+------------- + tableam_display | tbl_heap | table | regress_display_role | permanent | heap | + tableam_display | tbl_heap_psql | table | regress_display_role | permanent | heap_psql | (2 rows) \dm+ - List of relations - Schema | Name | Type | Owner | Persistence | Access method | Size | Description ------------------+--------------------+-------------------+----------------------+-------------+---------------+---------+------------- - tableam_display | mat_view_heap_psql | materialized view | regress_display_role | permanent | heap_psql | 0 bytes | + List of relations + Schema | Name | Type | Owner | Persistence | Access method | Description +-----------------+--------------------+-------------------+----------------------+-------------+---------------+------------- + tableam_display | mat_view_heap_psql | materialized view | regress_display_role | permanent | heap_psql | (1 row) -- But not for views and sequences. \dv+ - List of relations - Schema | Name | Type | Owner | Persistence | Size | Description ------------------+----------------+------+----------------------+-------------+---------+------------- - tableam_display | view_heap_psql | view | regress_display_role | permanent | 0 bytes | + List of relations + Schema | Name | Type | Owner | Persistence | Description +-----------------+----------------+------+----------------------+-------------+------------- + tableam_display | view_heap_psql | view | regress_display_role | permanent | (1 row) \set HIDE_TABLEAM on \d+ - List of relations - Schema | Name | Type | Owner | Persistence | Size | Description ------------------+--------------------+-------------------+----------------------+-------------+---------+------------- - tableam_display | mat_view_heap_psql | materialized view | regress_display_role | permanent | 0 bytes | - tableam_display | tbl_heap | table | regress_display_role | permanent | 0 bytes | - tableam_display | tbl_heap_psql | table | regress_display_role | permanent | 0 bytes | - tableam_display | view_heap_psql | view | regress_display_role | permanent | 0 bytes | + List of relations + Schema | Name | Type | Owner | Persistence | Description +-----------------+--------------------+-------------------+----------------------+-------------+------------- + tableam_display | mat_view_heap_psql | materialized view | regress_display_role | permanent | + tableam_display | tbl_heap | table | regress_display_role | permanent | + tableam_display | tbl_heap_psql | table | regress_display_role | permanent | + tableam_display | view_heap_psql | view | regress_display_role | permanent | (4 rows) RESET ROLE; -- 2.17.1 --HcAYCG3uE/tztfnV--