Back to TIL
db

Optimizing PostgreSQL Cache Hit Ratio

Learned to monitor the buffer cache hit ratio in PostgreSQL to ensure efficiency. Aim for 98%+ by checking with:

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;

One can combine this with \watch to have automatically refreshing monitoring.