Skip to content

Instantly share code, notes, and snippets.

@dalen
Created October 8, 2013 15:30
Show Gist options
  • Save dalen/6886532 to your computer and use it in GitHub Desktop.
Save dalen/6886532 to your computer and use it in GitHub Desktop.
duplicate indices in puppetdb
puppetdb=# 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;
size | idx1 | idx2 | idx3 | idx4
---------+--------------------------------+--------------------------------+------+------
6928 kB | catalogs_pkey | idx_catalogs_hash | |
5984 kB | certname_catalogs_certname_key | idx_certname_catalogs_certname | |
(2 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment