Cписок схем с размерами (относительные и абсолютные) в базе данных PostgreSQL

SELECT schema_name, 
       pg_size_pretty(sum(table_size)::bigint),
       trunc((sum(table_size) / pg_database_size(current_database())) * 100, 2) as percent
FROM (
  SELECT pg_catalog.pg_namespace.nspname as schema_name,
         pg_relation_size(pg_catalog.pg_class.oid) as table_size
  FROM   pg_catalog.pg_class
     JOIN pg_catalog.pg_namespace ON relnamespace = pg_catalog.pg_namespace.oid
) t
GROUP BY schema_name
ORDER BY schema_name;

Результат:


    schema_name     | pg_size_pretty | percent 
--------------------+----------------+---------
 admin              | 4216 kB        |    0.00
 admin_portal       | 176 kB         |    0.00
 audit              | 5678 MB        |    4.31
 documents          | 50 GB          |   38.91
 etl                | 229 MB         |    0.17
 filebox            | 7733 MB        |    5.88
 information_schema | 96 kB          |    0.00
 mpi                | 352 kB         |    0.00
 nsi                | 228 MB         |    0.17
 patient_portal     | 280 kB         |    0.00
 pg_catalog         | 11 MB          |    0.00
 pg_toast           | 65 GB          |   50.48
 public             | 24 kB          |    0.00
 registry           | 16 MB          |    0.01
 roles              | 3128 kB        |    0.00
 standard_med       | 2888 kB        |    0.00
 tech_portal        | 240 kB         |    0.00

(17 строк)