Skip to content

Instantly share code, notes, and snippets.

@ThomasJunk
Created April 17, 2020 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasJunk/64b724d1ad6b2a2085c8b2c521f66eed to your computer and use it in GitHub Desktop.
Save ThomasJunk/64b724d1ad6b2a2085c8b2c521f66eed to your computer and use it in GitHub Desktop.
Missing indexes
SELECT relname,
seq_scan - idx_scan AS too_much_seq,
CASE
WHEN seq_scan - idx_scan > 0
THEN 'Missing Index?'
ELSE 'OK'
END AS result,
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