Skip to content

Instantly share code, notes, and snippets.

@fljdin
Created March 18, 2020 15:07
Show Gist options
  • Save fljdin/9098f39950c9626fe619705debeb1fc3 to your computer and use it in GitHub Desktop.
Save fljdin/9098f39950c9626fe619705debeb1fc3 to your computer and use it in GitHub Desktop.
SELECT i.indrelid::regclass AS "Table", i.indexrelid::regclass AS "Index",
pg_size_pretty(pg_relation_size(i.indexrelid)) AS "Taille de l'index"
FROM pg_index i JOIN (
SELECT indrelid, indclass, indkey, indexprs, indpred
FROM pg_index GROUP BY indrelid, indclass, indkey, indexprs, indpred
HAVING COUNT (*) > 1
) g ON i.indrelid = g.indrelid AND i.indclass = g.indclass AND i.indkey = g.indkey
AND COALESCE(i.indexprs::text,'x') = COALESCE(g.indexprs::text,'x')
AND COALESCE(i.indpred::text,'x') = COALESCE(g.indpred::text,'x')
ORDER BY pg_relation_size(i.indexrelid) DESC, i.indexrelid::regclass;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment