Skip to content

Instantly share code, notes, and snippets.

@StevenJL
Last active February 8, 2021 02:50
Show Gist options
  • Save StevenJL/da51473bd5edda326245367310896f21 to your computer and use it in GitHub Desktop.
Save StevenJL/da51473bd5edda326245367310896f21 to your computer and use it in GitHub Desktop.
PSQL index cache hit ratio
# See Cache Hit Ratio for a given index
SELECT
(heap_blks_hit::decimal / (heap_blks_hit + heap_blks_read)) as cache_hit_ratio
FROM
pg_statio_user_indexes
WHERE indexrelname = 'some_high_use_index';
# See overall Cache Hit Ratio across all indexes
SELECT
sum(idx_blks_hit)/(sum(idx_blks_read) + sum(idx_blks_hit)) as cache_hit_ratio
FROM
pg_statio_user_indexes;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment