Skip to content

Instantly share code, notes, and snippets.

@fjsj
Forked from mmattozzi/Postgres cache hit ratio
Created December 31, 2021 21:13
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 fjsj/2787f67ac1161b259521f1c0c51c63bb to your computer and use it in GitHub Desktop.
Save fjsj/2787f67ac1161b259521f1c0c51c63bb to your computer and use it in GitHub Desktop.
SELECT
sum(idx_blks_read) as idx_read,
sum(idx_blks_hit) as idx_hit,
(sum(idx_blks_hit) - sum(idx_blks_read)) / sum(idx_blks_hit) as ratio
FROM
pg_statio_user_indexes;
SELECT
sum(heap_blks_read) as heap_read,
sum(heap_blks_hit) as heap_hit,
sum(heap_blks_hit) / (sum(heap_blks_hit) + sum(heap_blks_read)) as ratio
FROM
pg_statio_user_tables;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment