Skip to content

Instantly share code, notes, and snippets.

@jvanasco
Created October 10, 2014 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvanasco/c49a6b488755612bdc07 to your computer and use it in GitHub Desktop.
Save jvanasco/c49a6b488755612bdc07 to your computer and use it in GitHub Desktop.
show postgres indexes by table
-- 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