Created
July 26, 2012 17:20
-
-
Save rapimo/3183297 to your computer and use it in GitHub Desktop.
Find useless indexes on postres
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
SELECT idstat.relname AS table_name, | |
indexrelname AS index_name, | |
idstat.idx_scan AS times_used, | |
pg_size_pretty(pg_relation_size(idstat.relname::regclass)) AS table_size, pg_size_pretty(pg_relation_size(indexrelname::regclass)) AS index_size, | |
n_tup_upd + n_tup_ins + n_tup_del as num_writes, | |
indexdef AS definition | |
FROM pg_stat_user_indexes AS idstat JOIN pg_indexes ON indexrelname = indexname | |
JOIN pg_stat_user_tables AS tabstat ON idstat.relname = tabstat.relname | |
WHERE idstat.idx_scan < 200 | |
AND indexdef !~* 'unique' | |
ORDER BY idstat.relname, indexrelname; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment