I like this to find the missing indexes:
SELECT schemaname, 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(format('%I.%I', schemaname, relname)::regclass) AS rel_size, seq_scan, idx_scan FROM pg_stat_user_tables WHERE pg_relation_size(format('%I.%I', schemaname, relname)::regclass)>80000 ORDER BY too_much_seq DESC;
This checks if there are more sequence scans, and then an index scan. If the table is small, it is ignored, because Postgres seems to prefer sequence scanning for them.
The above query detects missing indexes.
The next step will be to find missing combined indexes. I think this is not easy, but doable. Perhaps analyzing slow queries ... I heard that pg_stat_statements can help ...
guettli Oct 10 '12 at 11:23 2012-10-10 11:23
source share