Created
July 30, 2014 05:16
-
-
Save cihangir/b463b9df0148a76307bf to your computer and use it in GitHub Desktop.
Duplicate indexes
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 | |
pg_size_pretty ( | |
SUM (pg_relation_size(idx)) :: BIGINT | |
) AS SIZE, | |
(ARRAY_AGG(idx)) [ 1 ] AS idx1, | |
(ARRAY_AGG(idx)) [ 2 ] AS idx2, | |
(ARRAY_AGG(idx)) [ 3 ] AS idx3, | |
(ARRAY_AGG(idx)) [ 4 ] AS idx4 | |
FROM | |
( | |
SELECT | |
indexrelid :: regclass AS idx, | |
( | |
indrelid :: TEXT || E'\n' || indclass :: TEXT || E'\n' || indkey :: TEXT || E'\n' || COALESCE (indexprs :: TEXT, '') || E'\n' || COALESCE (indpred :: TEXT, '') | |
) AS KEY | |
FROM | |
pg_index | |
) sub | |
GROUP BY | |
KEY | |
HAVING | |
COUNT (*) > 1 | |
ORDER BY | |
SUM (pg_relation_size(idx)) DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment