Skip to content

Instantly share code, notes, and snippets.

@sionide21
Created November 29, 2016 22:23
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 sionide21/0867b7b9ae98fa2de1609db3db6db157 to your computer and use it in GitHub Desktop.
Save sionide21/0867b7b9ae98fa2de1609db3db6db157 to your computer and use it in GitHub Desktop.
SELECT idstat.relname AS table_name,
indexrelname AS index_name,
CASE WHEN indexdef ~* 'unique' THEN 'UNIQUE' END,
pg_size_pretty(pg_relation_size(indexrelname::text)) AS index_size,
idstat.idx_scan AS times_used,
n_tup_upd + n_tup_ins + n_tup_del as num_writes,
indexdef
FROM pg_stat_user_indexes AS idstat JOIN pg_indexes ON indexrelname = indexname
JOIN pg_stat_user_tables AS tabstat ON idstat.relname = tabstat.relname
ORDER BY num_writes desc, times_used ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment