Skip to content

Instantly share code, notes, and snippets.

@jberkus
Created October 8, 2014 21:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jberkus/de7cfdd3b6e0b187f63d to your computer and use it in GitHub Desktop.
Save jberkus/de7cfdd3b6e0b187f63d to your computer and use it in GitHub Desktop.
finding needed indexes -- early draft
SELECT schemaname, relname,
seq_scan as table_scans,
idx_scan as index_scans,
pg_size_pretty(pg_relation_size(relid)) as table_size,
n_tup_ins + n_tup_del + n_tup_upd + n_tup_hot_upd as write_activty
FROM pg_stat_user_tables
WHERE seq_scan > 1000
AND seq_scan > ( idx_scan / 10 )
AND pg_relation_size(relid) > ( 16000000 )
ORDER BY pg_relation_size(relid) desc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment