Skip to content

Instantly share code, notes, and snippets.

@bokwoon95
Created November 24, 2019 07:40
Show Gist options
  • Save bokwoon95/c8a9d680509ac0f59ed81e60c416c978 to your computer and use it in GitHub Desktop.
Save bokwoon95/c8a9d680509ac0f59ed81e60c416c978 to your computer and use it in GitHub Desktop.
-- https://stackoverflow.com/questions/3318727/postgresql-index-usage-analysis
SELECT relname, seq_scan-idx_scan AS too_much_seq,
case when seq_scan-idx_scan>0 THEN 'Missing Index?' ELSE 'OK' END,
pg_relation_size(relid::regclass) AS rel_size, seq_scan, idx_scan
FROM pg_stat_all_tables
WHERE schemaname='public' AND pg_relation_size(relid::regclass)>80000
ORDER BY too_much_seq DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment