Query database and table size
PostgreSQLStorageCommand
SELECT relname AS table_name, pg_size_pretty(pg_total_relation_size(relid)) AS total_size, pg_size_pretty(pg_relation_size(relid)) AS data_only FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC LIMIT 20;What it does
Lists the 20 largest tables with their total size including indexes and TOAST.
When to use it
To analyze disk usage and find which tables take up space.
Caution
For the whole database size: SELECT pg_size_pretty(pg_database_size(current_database()));