Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3VFF-0001lh-4g for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jul 2021 03:07:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m3VFD-0000Ej-J9 for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jul 2021 03:07:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3VFD-0000EM-9B for pgsql-hackers@lists.postgresql.org; Wed, 14 Jul 2021 03:07:31 +0000 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1m3VFA-0000Jn-C0 for pgsql-hackers@postgresql.org; Wed, 14 Jul 2021 03:07:30 +0000 Received: by mail-io1-xd29.google.com with SMTP id l5so274183iok.7 for ; Tue, 13 Jul 2021 20:07:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=paAegqIcdgJ9y1YCb/gGXhIu1xacRedi8ulIAAz9I0Q=; b=zPjlrY83w3hrerJgjeUDwqBjsh5I2p+7hlsCK9l6PdmOSNl3pPlz0RNAP8lIkqqNlJ 2xWI2WKgmFgZg7G/85KTVftNMYzg3LkyCHrYVgXwtEHkhcQEaV5nSH1jxuw7w/vdS0v5 pQ5y/0OgII+VWiOO98r0pLI9TAGg51e2VQvcNnYIEmTjQ/S0vj5qdWC4XyNdSrzFk1+g g6NsfJ/flxiunY+Ais01ZNxQVveDx+0j2ksbdMIJ89elk9BiM1EPjbxDtsg4fPC3oTvC EFQWx3DkBVXX2SyKqPNk+CTJ9xX2Qr5bw1qLs5Vl8aef6LrPMVVq+Qt9I32yfsX0ZC6+ pWQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=paAegqIcdgJ9y1YCb/gGXhIu1xacRedi8ulIAAz9I0Q=; b=YWLg+VM0Y5Mg7RyqAlufKf2wU+Z/6tLQsXkR3ZNQuB7yMlhzrM5Gi30WDfb6TFUgji e1vbwu18/KTYf/ya849x9xGG8CfmIIzaMFk3NOhUKvssSlRca1fuLapMGYgqaEcMweCl 4KwWe826l1FCuSIRqpsBQOE5liCJPSiHviNr5Y+MM7K5G7d2aF7Vy9LTInG0SAidZmHt VEE6YMkZ8+9MeOCMTpPpZujHnlosXPNaXuA+0znndnCvWO0sCljDVe6pIm7XTz5k5oOC QTp2K3WOtXkjPm5clQZyJ+5/BWlwSVjxpXBZmyOC4SbSXnt+YpmEisiFIyDWAh7tzMdJ BPlg== X-Gm-Message-State: AOAM531eemM1dhQ6ChEwqeYijNh84hLxOBY/f6xCdiMyNrVqfCMTe5Mz yzjs7z/3I3TYIwu19VMMEy3wRIbBALj99w== X-Google-Smtp-Source: ABdhPJy2v8K2/9Cz6wm216nELqFv7GB4ItiWiubs2G5mkF5NWTPmy6vRWZnapXlDdO9XPEYz/Ix+eg== X-Received: by 2002:a02:8241:: with SMTP id q1mr6859972jag.134.1626232046806; Tue, 13 Jul 2021 20:07:26 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id z7sm465514iox.4.2021.07.13.20.07.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Jul 2021 20:07:26 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 4E3F4800AAC; Tue, 13 Jul 2021 22:07:25 -0500 (CDT) Date: Tue, 13 Jul 2021 22:07:25 -0500 From: Justin Pryzby To: pgsql-hackers@postgresql.org Subject: [PATCH] psql: \dn+ to show size of each schema.. Message-ID: <20210714030725.GG9600@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk \db+ and \l+ show sizes of tablespaces and databases, so I was surprised in the past that \dn+ didn't show sizes of schemas. I would find that somewhat convenient, and I assume other people would use it even more useful. \db+ and \l+ seem to walk the filesystem, and this is distinguished from those cases. (Also, schemas are per-DB, not global). Maybe it's an issue if \dn+ is slow and expensive, since that's how to display ACL. But \db+ has the same issue. Maybe there should be a \db++ and \dn++ to allow \dn+ to showing the ACL but not the size. pg_relation_size() only includes one fork, and the other functions include toast, which should be in its separate schema, so it has to be summed across forks. postgres=# \dnS+ child | postgres | | | 946 MB information_schema | postgres | postgres=UC/postgres+| | 88 kB | | =U/postgres | | pg_catalog | postgres | postgres=UC/postgres+| system catalog schema | 42 MB | | =U/postgres | | pg_toast | postgres | | reserved schema for TOAST tables | 3908 MB public | postgres | postgres=UC/postgres+| standard public schema | 5627 MB | | =UC/postgres | | From c2d68eb54f785c759253d4100460aa1af9cbc676 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Tue, 13 Jul 2021 21:25:48 -0500 Subject: [PATCH] psql: \dn+ to show size of each schema.. See also: 358a897fa, 528ac10c7 --- src/bin/psql/describe.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 2abf255798..6b9b6ea34a 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -5036,6 +5036,11 @@ listSchemas(const char *pattern, bool verbose, bool showSystem) appendPQExpBuffer(&buf, ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"", gettext_noop("Description")); + + appendPQExpBuffer(&buf, + ",\n (SELECT pg_catalog.pg_size_pretty(sum(pg_relation_size(oid,fork))) FROM pg_catalog.pg_class c,\n" + " (VALUES('main'),('fsm'),('vm'),('init')) AS fork(fork) WHERE c.relnamespace = n.oid) AS \"%s\"", + gettext_noop("Size")); } appendPQExpBufferStr(&buf, -- 2.17.0