Created
October 10, 2014 19:05
-
-
Save jvanasco/c49a6b488755612bdc07 to your computer and use it in GitHub Desktop.
show postgres indexes by table
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
-- modified from http://stackoverflow.com/questions/6777456/get-the-list-all-index-names-its-column-names-and-its-table-name-of-a-postgresq | |
SELECT | |
idx.indrelid::regclass as indexed_tabled, | |
i.relname as index_name, | |
ARRAY( | |
SELECT pg_get_indexdef(idx.indexrelid, k + 1, true) | |
FROM generate_subscripts(idx.indkey, 1) as k | |
ORDER BY k | |
) as indkey_names | |
FROM pg_index as idx | |
JOIN pg_class as i | |
ON i.oid = idx.indexrelid | |
JOIN pg_namespace as ns | |
ON ns.oid = i.relnamespace | |
AND ns.nspname = ANY(current_schemas(false)) | |
ORDER BY indexed_tabled ASC | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment