Show table sizes
Top 20 tables by total size including indexes and TOAST
psql -U myuser -d mydb -c "SELECT schemaname, tablename, pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) size FROM pg_tables ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC LIMIT 20;"
- tool
- postgres29 commands
- tags
- postgresmonitoring
More postgres commands
-
psql -U myuser -d mydb -c "SELECT relname, indexrelname, idx_scan, idx_tup_read FROM pg_stat_user_indexes ORDER BY idx_scan DESC LIMIT 20;"Which indexes are actually being used and how often
-
psql -U myuser -d mydb -c "SELECT schemaname, tablename, indexname, idx_scan FROM pg_stat_user_indexes WHERE idx_scan = 0 AND NOT indisprimary ORDER BY pg_relation_size(indexrelid) DESC;"Indexes that have never been scanned — safe to drop candidates
-
pg_dump -U myuser -d mydb -F c -f mydb.dumpCustom-format dump (fastest, supports parallel restore)
-
pg_restore -U myuser -d mydb -j 4 --clean mydb.dumpParallel restore with 4 workers, drop existing objects first
-
psql -U myuser -d mydb -c 'VACUUM (VERBOSE, ANALYZE) orders;'Reclaim dead tuples and update statistics for query planner