Created
September 24, 2016 12:39
-
-
Save meniam/99ec16cfbd0b19a20e541050d9264400 to your computer and use it in GitHub Desktop.
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
CREATE OR REPLACE VIEW public.unused_indexes AS | |
SELECT | |
(pg_stat_all_indexes.schemaname :: TEXT || '.' :: TEXT) || pg_stat_all_indexes.relname :: TEXT, | |
pg_stat_all_indexes.indexrelname, | |
pg_stat_all_indexes.idx_scan, | |
pg_size_pretty( | |
pg_relation_size(((pg_stat_all_indexes.schemaname :: TEXT || '.' :: TEXT) || pg_stat_all_indexes.indexrelname :: TEXT) :: REGCLASS)) AS pg_size_pretty | |
FROM pg_stat_all_indexes | |
WHERE (pg_stat_all_indexes.schemaname <> ALL (ARRAY ['pg_toast' :: NAME, 'pg_catalog' :: NAME])) AND pg_stat_all_indexes.idx_scan = 0 AND | |
pg_relation_size(((pg_stat_all_indexes.schemaname :: TEXT || '.' :: TEXT) || pg_stat_all_indexes.indexrelname :: TEXT) :: REGCLASS) > | |
(1024 * 1024 * 1024) | |
ORDER BY (pg_relation_size(((pg_stat_all_indexes.schemaname :: TEXT || '.' :: TEXT) || pg_stat_all_indexes.indexrelname :: TEXT) :: REGCLASS)) DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment