Перейти к содержанию

Запросы к БД postgres

Статистика по размеру всех таблиц

SELECT 
    table_schema,
    table_name,
    pg_size_pretty(pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')) as total_size,
    pg_size_pretty(pg_table_size('"' || table_schema || '"."' || table_name || '"')) as table_size,
    pg_size_pretty(pg_indexes_size('"' || table_schema || '"."' || table_name || '"')) as indexes_size
FROM 
    information_schema.tables
WHERE 
    table_schema NOT IN ('pg_catalog', 'information_schema')
    AND table_type = 'BASE TABLE'
ORDER BY 
    pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC;

получаем такую таблицу с размерами:

Далее можно в Excel ее представить в более удобном виде: