Created
December 9, 2014 16:06
-
-
Save FractalizeR/6c4fd1433611484e6c05 to your computer and use it in GitHub Desktop.
Postgres: get a list of all indexes with extended information
This file contains hidden or 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 | |
U.usename AS user_name, | |
ns.nspname AS schema_name, | |
idx.indrelid :: REGCLASS AS table_name, | |
i.relname AS index_name, | |
idx.indisunique AS is_unique, | |
idx.indisprimary AS is_primary, | |
am.amname AS index_type, | |
idx.indkey, | |
ARRAY( | |
SELECT pg_get_indexdef(idx.indexrelid, k + 1, TRUE) | |
FROM | |
generate_subscripts(idx.indkey, 1) AS k | |
ORDER BY k | |
) AS index_keys, | |
(idx.indexprs IS NOT NULL) OR (idx.indkey::int[] @> array[0]) AS is_functional, | |
idx.indpred IS NOT NULL AS is_partial | |
FROM pg_index AS idx | |
JOIN pg_class AS i | |
ON i.oid = idx.indexrelid | |
JOIN pg_am AS am | |
ON i.relam = am.oid | |
JOIN pg_namespace AS NS ON i.relnamespace = NS.OID | |
JOIN pg_user AS U ON i.relowner = U.usesysid | |
WHERE NOT nspname LIKE 'pg%'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment