Last active
January 15, 2016 08:31
-
-
Save amitu/46e76af95be60989e687 to your computer and use it in GitHub Desktop.
DB Performance - Index Usage - Bad Ones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH query_stat AS ( | |
SELECT | |
relname, 100 * idx_scan / (seq_scan + idx_scan) percent_of_times_index_used, | |
n_live_tup rows_in_table, idx_scan, seq_scan | |
FROM | |
pg_stat_user_tables | |
WHERE | |
seq_scan + idx_scan > 0 | |
ORDER BY | |
seq_scan DESC | |
) | |
SELECT * | |
FROM query_stat | |
WHERE | |
percent_of_times_index_used < 95 | |
AND rows_in_table > 1000 | |
AND seq_scan > 1000; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment