Postgres read-stream support grew out of a long-running effort to make large scans more efficient. In 2007, Heikki Linnakangas proposed a small shared-buffer ring for scanning tables larger than memory, limiting damage to other cached data; that change arrived in Postgres 8.3. Luke Lonergan then advocated reading several adjacent pages per operation, while others noted that effective multi-buffer reads would need scatter-gather and eventually asynchronous I/O. In 2009, Postgres 8.4 added prefetching for bitmap heap scans, with a setting to control its intensity. Thomas Munro’s 2023 proposal led to read streams in Postgres 17: they gather nearby blocks and use `preadv` to read them together, such as 16 pages in one 128 KiB operation rather than 16 separate 8 KiB reads. Postgres 18 added a limit on how many pages can be combined.
A key complication is that a page already present in shared buffers interrupts a combined disk read. If pages 0-15 are requested but page 8 is cached, Postgres reads pages 0-7, skips the cached page, then issues another read for pages 9-15. With alternating cached and missing pages, one range can become many separate requests. Combining reduces request count; asynchronous I/O instead lets scans begin work before they need the results, keeping more reads in flight. Work described in 2025 proposed retaining pinned buffers across split reads to avoid repeated lookup and pinning. In 2026, Andres Freund adjusted look-ahead behavior and proposed separating how far ahead Postgres searches for blocks from how far ahead it issues I/O.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.