Created
October 9, 2019 10:23
-
-
Save zabih-alipour/6403685ba0235668b3b3c23addb6977e 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
SELECT s.schemaname, | |
s.relname AS tablename, | |
s.indexrelname AS indexname, | |
pg_relation_size(s.indexrelid) AS index_size, | |
s.idx_scan | |
FROM pg_catalog.pg_stat_user_indexes s | |
JOIN pg_catalog.pg_index i ON s.indexrelid = i.indexrelid | |
WHERE s.idx_scan > 0 -- has never been scanned | |
AND 0 <>ALL (i.indkey) -- no index column is an expression | |
AND NOT i.indisunique -- is not a UNIQUE index | |
AND NOT EXISTS -- does not enforce a constraint | |
(SELECT 1 FROM pg_catalog.pg_constraint c | |
WHERE c.conindid = s.indexrelid) | |
ORDER BY pg_relation_size(s.indexrelid) DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment