Conceptual
Login

Buffer Hit Versus Disk Read: Why the Same Query Is Fast the Second Time

Every page a query needs is either already in the buffer pool, which is a hit, or has to be fetched from storage, which is a miss. A hit costs roughly a microsecond and a miss roughly a hundred, so two runs of the identical query can differ by a factor of fifty with nothing changed but what happened to be cached. PostgreSQL 18 prints buffer counts with EXPLAIN ANALYZE by default, so you can see hits and reads directly, and knowing the difference stops you from declaring a query fixed when all you did was warm the cache.

Questions this Concept answers

  • Why can two runs of the same unchanged query differ in time by a factor of fifty?