Skip to content

Instantly share code, notes, and snippets.

@claudiug
Forked from consti/missing_indices.sql
Created April 7, 2020 20:35
Show Gist options
  • Save claudiug/a23720fa8b1af266b0208884c4c3e43a to your computer and use it in GitHub Desktop.
Save claudiug/a23720fa8b1af266b0208884c4c3e43a to your computer and use it in GitHub Desktop.
Find missing indices in postgres
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(relname::regclass) AS rel_size, seq_scan, idx_scan
FROM pg_stat_all_tables
WHERE schemaname='public' AND pg_relation_size(relname::regclass)>80000 ORDER BY too_much_seq DESC;
@claudiug
Copy link
Author

claudiug commented Apr 7, 2020

magic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment