Postgresql Physical Reads and Buffer Reads

postgresqlpostgresql-performance

in PostgreSQL how to identify the number of page reads from disk or Shared Buffer
How to find the Hit Ratio for the Shared Buffers
Any queries to support this.

Best Answer

If you want to know it per database:

SELECT datname, blks_read, blks_hit
FROM pg_stat_database;

If you are interested in values per table, use

SELECT * FROM pg_statio_all_tables;

If you want to have statistics per query, install pg_stat_statements and use

SELECT query, shared_blks_read, shared_blks_hit
FROM pg_stat_statements;

Don't forget that since PostgreSQL uses buffered I/O, a “block read” might come from the kernel cache rather than from disk.