Skip to content

Instantly share code, notes, and snippets.

@mattsoldo
Created May 7, 2012 00:43
Show Gist options
  • Save mattsoldo/2625185 to your computer and use it in GitHub Desktop.
Save mattsoldo/2625185 to your computer and use it in GitHub Desktop.
PostgreSQL Index hit percentage by table
SELECT
schemaname::text,
relname::text,
seq_tup_read,
idx_tup_fetch,
seq_tup_read + idx_tup_fetch as total_reads,
round(100 * idx_tup_fetch / (seq_tup_read + idx_tup_fetch)) as idx_read_pct,
pg_size_pretty(pg_total_relation_size(relid)) as total_size
FROM
pg_stat_user_tables
JOIN
pg_stat_database ON datname = current_database()
WHERE
(seq_tup_read + idx_tup_fetch > 0) AND
tup_returned > 0
ORDER BY
(seq_tup_read + idx_tup_fetch) desc -- A.K.A. "total_reads"
limit
50;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment