Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wmWkT-000phU-0o for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Jul 2026 13:12:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wmWkS-00CH2A-2N for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Jul 2026 13:12:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wmWkS-00CH1x-1H for pgsql-hackers@lists.postgresql.org; Wed, 22 Jul 2026 13:12:32 +0000 Received: from stravinsky.debian.org ([2001:41b8:202:deb::311:108]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wmWkP-00000001QFw-09jd for pgsql-hackers@lists.postgresql.org; Wed, 22 Jul 2026 13:12:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=YX4TvTEfrR0xxHeZ+BiBsr1I5FP2x7oVMFmhp+QwOh0=; b=j+8fEBtuTiibr0GikfKNjvPOpQ sq/vHDHnYkDybweeNC3mn5EKWVScUZTLsrHsLnKgijQMIED6IZ6wf7zTRSZ3RzkQ+/SQl1OQoL77s D45P78PKnErCHwxAnrc1CVQTxye7igH5ldwnEzAcs+0zskOKZct0kJysdehCI4UnKPTq/vso8kgJf VOHq2yk2M8C8KXAMVLmmyeZI0go2S6dRiqoDBiRfLKvlo/uVI4HSkfaI/VxYoDrmzc1AM5Swa+VFY DRNac/3Si8+OAC/CQtVqehnZ8NklcylhlipGD6zEN+vFfQekYhc35nzZjAt7Jwt+VDL3Q7QcM0b1v ZN9UqEuQ==; Received: from authenticated-user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wmWkN-0031BO-2A; Wed, 22 Jul 2026 13:12:27 +0000 Date: Wed, 22 Jul 2026 15:12:26 +0200 From: Christoph Berg To: Fujii Masao Cc: PostgreSQL Hackers , Zsolt Parragi Subject: Re: Allow pg_read_all_stats to see database size in \l+ Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="GvhE+GC2PI361jLV" Content-Disposition: inline In-Reply-To: X-Debian-User: myon List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --GvhE+GC2PI361jLV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Thanks for the review! Re: Fujii Masao > The pg_read_all_stats check should be fine in master, since psql there > no longer supports pre-v10 servers, which don't have that role. But, > if this is backpatched, psql still needs to work with pre-v10 servers, > so we'll probably need a server version check (e.g., pset.sversion >= 100000) > before checking for pg_read_all_stats, at least in the older stable branches. The SQL-generating code there is already quite complex, and since no one complained, perhaps just skip the backpatching if it's complicated. I tried the patch back to version 9.3 and the query still works even when the role doesn't exist there. (9.2 and earlier failed due to the protocol version grease.) > Also, should the following description of the \l+ meta-command in > the psql docs be updated? > > (Size information is only available for databases that the current > user can connect to.) Done in v2. Christoph --GvhE+GC2PI361jLV Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename=v2-0001-Allow-pg_read_all_stats-to-see-database-size-in-l.patch From 5fe2f0e6bb07fa6fe2172d732c1be50b4698210d Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Wed, 22 Jul 2026 13:16:16 +0200 Subject: [PATCH v2] Allow pg_read_all_stats to see database size in \l+ The server already allows members of pg_read_all_stats to see the size of all databases, but psql's \l+ was too restrictive. --- doc/src/sgml/ref/psql-ref.sgml | 5 +++-- src/bin/psql/describe.c | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index 56c2692e618..4d5ee11ddd9 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -2817,8 +2817,9 @@ SELECT are displayed in expanded mode. If + is appended to the command name, database sizes, default tablespaces, and descriptions are also displayed. - (Size information is only available for databases that the current - user can connect to.) + Except for superusers or roles with privileges of the + pg_read_all_stats role, size information is only + available for databases that the current user can connect to. diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index a2f09c26369..ad9c8affb4f 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -986,7 +986,8 @@ listAllDbs(const char *pattern, bool verbose) printACLColumn(&buf, "d.datacl"); if (verbose) appendPQExpBuffer(&buf, - ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n" + ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT') OR\n" + " pg_catalog.pg_has_role('pg_read_all_stats', 'USAGE')\n" " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n" " ELSE 'No Access'\n" " END as \"%s\"" -- 2.53.0 --GvhE+GC2PI361jLV--