psql -d postgres -c "SELECT datname, pg_size_pretty(pg_database_size(datname)) FROM pg_database ORDER BY pg_database_size(datname) DESC;"
Rank databases by size
Ranks every database by size, largest first, in one pass over pg_database. template0 always appears; it is the pristine template and should stay untouched. A good first query when disk usage surprises you.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.