I have a Postgres database with a total data size of 115GB. The server has ~60GB of memory. The index cache hit rate is holding at 99%+ but the table cache hit rate has fallen to ~97%.
I am trying to identify if there are particular queries or access patterns we are making that are contributing to the drop. We may be able to optimize the app if so.
I have used the below query to identify tables that have a low hit rate...
SELECT relname,
CASE (sum(heap_blks_hit) + sum(heap_blks_read))
WHEN 0 THEN 1
ELSE sum(heap_blks_hit) / (sum(heap_blks_hit) + sum(heap_blks_read))
END as hitrate,
pg_size_pretty(sum(heap_blks_hit) + sum(heap_blks_read)) AS total_read,
pg_size_pretty(sum(heap_blks_read)) AS total_miss
FROM pg_statio_user_tables
GROUP BY relname
ORDER BY hitrate
I am not sure where to go from here though. Is there a way to track if certain queries are commonly producing misses for the tables I know are low?
perf
by trapping when a backend increments the cache miss counter.pg_stat_statements
extension: postgresql.org/docs/9.3/static/pgstatstatements.html. That includes columns showing shared cache hits / disk reads. Not sure about overhead but it's almost certainly lower thanauto_explain
withauto_explain.log_analyze
andauto_explain.log_buffers
turned on. You'd have to manually link statements to tables, however.