Skip to content

Instantly share code, notes, and snippets.

@khusnetdinov
Created June 11, 2018 09:07
Show Gist options
  • Save khusnetdinov/a2e3794841ce8150e44b82d538d951b7 to your computer and use it in GitHub Desktop.
Save khusnetdinov/a2e3794841ce8150e44b82d538d951b7 to your computer and use it in GitHub Desktop.
Uniques of indexes
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