Postgres read streams can turn 16 small disk reads into a single 128 KiB request. They also have a quirk: if one page in the middle of that range is already cached, the read gets cut in two. A developer who hit the effect in production followed it back through years of discussion among Postgres contributors.
The 2007 argument that started it
In 2007, Heikki Linnakangas proposed a roadmap for sequential scans. He worried about tables far bigger than shared buffers, perhaps 5 or 10 times bigger, where caching brought little gain. Such scans also evicted other tables’ pages. He proposed that large tables cycle through a small ring of buffers. That idea was merged in Postgres 8.3.0.
Luke Lonergan replied with a bigger idea: readahead inside the heap scan. The kernel did its own readahead, but Postgres still requested a single 8 KiB page per syscall. He wanted Postgres to run N buffers ahead and issue contiguous reads, each far larger than one page.
Linnakangas was skeptical, since the OS should handle readahead anyway. Andreas Zeugswetter noted that doing it properly would need scatter-gather I/O, meaning one call that fills several buffers. Gregory Stark said the real win would need asynchronous I/O.
Prefetching arrives, then read streams
Stark followed up in 2009. Postgres 8.4 added posix_fadvise prefetching for bitmap heap scans, plus effective_io_concurrency to tune how eagerly pages are prefetched through the OS.
The next big step came in 2023, when Thomas Munro opened a thread that became read streams in Postgres 17. It built on a preadv wrapper that Postgres had carried since version 14. The function takes a list of memory buffers and fills them from one contiguous range of a file. Pages don’t have to sit next to each other in shared buffers, which was the exact thing the 2007 participants had been discussing.
With a read stream, the scan supplies the next block through a callback. Postgres peeks ahead, gathers blocks, and merges neighbors up to io_combine_limit in Postgres 18.
Where a cached page breaks the read
Picture a scan that needs pages 0 through 15 while page 8 sits in shared buffers. Postgres won’t fetch page 8 from disk, so the read ends before it and a fresh one begins at page 9. A code comment in bufmgr.c gives the reason: a block that is already valid can’t join the pending I/O.
That leaves one read for pages 0 to 7, a hit, and one read for pages 9 to 15. Less data moves, yet the disk sees two requests. With alternating cached pages, the range degrades into eight single-page reads of 8 KiB each.
Combining and asynchronous I/O solve different problems. Combining reduces the number of requests. Async I/O lets Postgres start a read before it needs the result and keep several reads in flight while it processes earlier pages. Munro’s 2023 proposal planned for both: larger synchronous reads first, with an API that could later use async I/O without changing again. The infrastructure for async I/O arrived in Postgres 18.
What contributors are changing now
Andres Freund flagged the split in January 2025 and called it a very common pattern: several misses, then a hit. A month later Munro walked through a case. A request for 8 blocks where the sixth is cached needs disk reads for only the first five. Blocks seven and eight may need I/O as well, but StartReadBuffers() should not launch two I/Os, so the cached sixth block ends the search.
In the same email Munro suggested keeping the extra buffers pinned and handing them back to StartReadBuffers on the next call. Postgres would then avoid unpinning and looking them up again. The cached page would still divide the read, but handling the split would cost less work.
Look-ahead distance is the other open area. The old rule cut the distance by 1 on every hit and doubled it on every miss. Freund pointed out that under it, a miss followed by a hit can never push the distance past 2. In April 2026 he changed how far ahead a stream looks. In a separate thread on index prefetching he also posted an unfinished patch that splits one internal distance into two settings: how far ahead to start I/O, and how far ahead to search for blocks worth combining.
What it means for database teams
For people running Postgres, the takeaway is practical. Read performance depends on what is cached as well as on the disk. A table with a scattering of warm pages can generate more, smaller requests than a cold one. Anyone tuning io_combine_limit or effective_io_concurrency should expect that pattern.
The fixes under discussion, pinned buffers and a split look-ahead distance, are still patches and proposals. Postgres 18 ships the async I/O groundwork, and the current work aims to make combined reads hold up when a cached page lands in the middle of a range.
Source: frn.sh