-- dbsizetables 
-- 
-- Ultimo cambio: Wed 04 Sep 2019 01:33:35 PM MDT
-- Consultar el tamaño de las bases de datos:
SELECT
pg_database.datname,
pg_size_pretty(pg_database_size(pg_database.datname)) AS size
FROM pg_database;

-- Consultar el Top10 de las tablas de una base de datos que más espacio consumen:
SELECT
relname as table,
pg_size_pretty(pg_total_relation_size(relid)) As size,
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as external_size
FROM pg_catalog.pg_statio_user_tables
ORDER BY pg_total_relation_size(relid) DESC LIMIT 10;

-- Consultar el tamaño de todos los objetos:
SELECT
relname AS objectname, relkind AS objecttype,
reltuples AS entries, pg_size_pretty(relpages::bigint*8*1024) AS size
FROM pg_class
ORDER BY relpages DESC LIMIT 20;


