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',relname)::regclass)>80000 ORDER BY too_much_seq DESC;
这将检查是否有更多的序列扫描,然后索引扫描。如果表是小的,它被忽略,因为Postgres似乎更喜欢序列扫描他们。