Thread: heap_blks_hit and heap_blks_read

heap_blks_hit and heap_blks_read

From
"Fernando Papa"
Date:
Hi all!

I'm trying to set up several scripts to get information about how
database is used. Actually I try to get "cache ratio" or "buffer ratio"
(like Oracle "buffer cache hit ratio").
With "sum(heap_blks_hit) from pg_statio_user_tables" I get buffer reads,
and with "sum(heap_blks_read) from pg_statio_user_tables" I get disk
read... It's that true?
But I'mt thinking about this: when postgres read from disk and then put
data into buffer... both heap_blks_hit and heap_blks_read are increased?
or only heap_blks_read are increased?
Is this formula correct?: "select
sum(heap_blks_hit)*100/(sum(heap_blks_hit)+sum(heap_blks_read)) from
pg_statiouser_tables"

I'm not counting system tables for now, but I think could be easy to
change "user_tables" with "all_tables", and add pg_statio_all_indx too.

Thanks in advance.

--
Fernando O. Papa