A shared buffer is a preallocated PostgreSQL memory area that caches pages from regular tables and indexes. Query plans report whether PostgreSQL found pages in memory or had to load them from disk. section 4.4
Read the Buffers metrics as follows:
- shared hit=3 means PostgreSQL accessed three cached pages without reading them from disk. section 4.4
- shared hit=3 read=4 means three pages were already cached and four pages came from disk. section 4.4
- Use EXPLAIN (analyze, buffers on) to execute a query and include its buffer activity in the plan. section 4.4
Inspecting cached pages
EXPLAIN (analyze, buffers on) SELECT username, level, score FROM game.player_stats WHERE player_id = 250; A plan containing Buffers: shared hit=3 shows that the index scan and table lookup used three pages already held in shared buffers. section 4.4
EXPLAIN (analyze, buffers on) SELECT username, level, score FROM game.player_stats WHERE player_id = 250;
Run the query in a PostgreSQL session to inspect shared-buffer usage alongside the execution plan. section 4.4
