Database

Qual o tamanho ocupado por cada banco de dados e tabela no PostgreSQL?

RT.DB.FAQ-16975
O tamanho dos bancos pode ser obtido assim:

select db.datname AS database
, pg_size_pretty(pg_database_size(db.datname)) as db_size
from pg_database db
order by pg_database_size(db.datname) desc;

O tamanho das tabelas no PG (table size) com e sem os indices pode ser obtido através da seguinte consulta:

SELECT nspname || '.' || relname AS "Tabela"
, c.reltuples::integer AS "Registros"
, pg_size_pretty(pg_relation_size(c.oid)) AS "Dados"
, pg_size_pretty(pg_total_relation_size(c.oid)) AS "Dados e Indices"
, current_setting('data_directory')||'/'||pg_relation_filepath(c.oid) as file
FROM pg_class c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND c.relkind <> 'i'
AND nspname !~ '^pg_toast'
ORDER BY pg_relation_size(C.oid) DESC;