Skip to content

Instantly share code, notes, and snippets.

@haseebeqx
Last active July 7, 2024 10:24
Show Gist options
  • Save haseebeqx/54282b74de62fa6392d5c9037d9e22ce to your computer and use it in GitHub Desktop.
Save haseebeqx/54282b74de62fa6392d5c9037d9e22ce to your computer and use it in GitHub Desktop.
query.sql
SELECT
i.relname AS index_name,
t.relname AS table_name,
s.idx_scan AS times_used,
pg_size_pretty(pg_relation_size(i.oid)) AS index_size
FROM
pg_stat_user_indexes s
JOIN
pg_index ix
ON
s.indexrelid = ix.indexrelid
JOIN
pg_class t
ON
s.relid = t.oid
JOIN
pg_class i
ON
s.indexrelid = i.oid
ORDER BY
s.idx_scan DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment