Sub topic 12
I/O concurrency and prefetching settings
This chapter assumes you can run queries in psql, read a basic EXPLAIN plan, and change settings in postgresql.conf. It also assumes you know that PostgreSQL reads data through its own buffer cache and the operating system page cache. The settings here tell PostgreSQL how many read requests it may keep in flight at once, so storage that handles parallel requests well isn't left idle.
What problem prefetching solves
A normal read is synchronous. The backend asks for a block, waits until it arrives, processes it, then asks for the next one. On a spinning disk this is close to the best you can do. On an SSD, NVMe drive, or network volume such as a cloud block device, the device can serve many requests at once. A backend that asks for one block at a time uses a small fraction of that capacity.
Prefetching fixes this. When PostgreSQL knows which blocks it will need soon, it tells the operating system to start reading them before the backend asks. By the time the backend gets to a block, the block is often already in the OS page cache.
The two settings that control how far ahead PostgreSQL looks are effective_io_concurrency and maintenance_io_concurrency.
The settings
| Setting | Used by | Default (PostgreSQL 13 to 17) | Default (PostgreSQL 18) |
|---|---|---|---|
| `effective_io_concurrency` | Queries, such as bitmap heap scans | 1 | 16 |
| `maintenance_io_concurrency` | Maintenance work and WAL replay prefetching | 10 | 16 |
Both can be changed by a reload and need no restart. You can set them per session, per role, or per database. effective_io_concurrency can also be set per tablespace, which is useful when one tablespace sits on fast storage and another on slow storage. A value of 0 turns prefetching off.
Since PostgreSQL 13, the value is roughly the number of blocks PostgreSQL may have requested ahead of the one it is processing. Older releases applied a formula to the value, so advice written before 2020 may not translate directly. Check the documentation for your major version before reusing numbers from old blog posts.
Where each setting applies
effective_io_concurrency has long applied to bitmap heap scans. A bitmap index scan first collects the matching row locations, sorts them by block number, and then visits the table blocks in order. That sorted list gives PostgreSQL a known sequence of upcoming reads, so it can prefetch them. Newer releases route more operations through a shared read-ahead mechanism, and PostgreSQL 18 adds an asynchronous I/O subsystem with an io_method setting. The set of operations that benefit differs between versions, so read the release notes for the version you run.
maintenance_io_concurrency covers maintenance work. It also covers prefetching of data blocks during WAL replay (crash recovery and standby replay) when recovery_prefetch is enabled.
Plain index scans, with no bitmap step, don't read far ahead by design. Their next block depends on the previous index entry. If an index scan is slow because of random reads, a higher effective_io_concurrency won't change it.
Choosing a value
The right value depends on how many requests your storage can serve in parallel before latency rises.
| Storage | Starting value |
|---|---|
| Single spinning disk | 1 to 4 |
| RAID of N spinning disks | About N |
| SATA SSD | 100 to 200 |
| NVMe SSD | 200 or more |
| Network block storage with provisioned IOPS | 100 to 200, then measure |
These are starting points, not rules. Returns diminish. Past some value, the device queue is already full, and a larger setting adds queueing delay without adding throughput. Test a few values on your own workload, such as 0, 16, 64, and 200.
Prefetching does nothing for data that is already cached. If your hot data fits in shared_buffers and the OS cache, changing these settings will not move your numbers. The call to the operating system still costs a little CPU, so gains appear only when the queries are limited by storage reads.
Setting the values
Change them for a session while you experiment, then make the chosen value permanent.
SET effective_io_concurrency = 200;
SHOW effective_io_concurrency;To apply a value to every session, use ALTER SYSTEM and reload.
ALTER SYSTEM SET effective_io_concurrency = 200;
ALTER SYSTEM SET maintenance_io_concurrency = 100;
SELECT pg_reload_conf();If different tablespaces sit on different hardware, set the value per tablespace. The tablespace value overrides the global value for tables and indexes stored there.
ALTER TABLESPACE fast_nvme SET (effective_io_concurrency = 256);
ALTER TABLESPACE slow_hdd SET (effective_io_concurrency = 2);You can confirm where a value comes from in pg_settings.
SELECT name, setting, source, context
FROM pg_settings
WHERE name IN ('effective_io_concurrency', 'maintenance_io_concurrency');Measuring the effect
Turn on I/O timing so EXPLAIN reports how long reads took. You need superuser rights or the appropriate privilege to set track_io_timing. The overhead is small on most modern Linux systems, and you can measure it with the pg_test_timing tool.
The following example builds a table where matching rows are spread across many blocks, which is the situation where bitmap heap scans benefit most.
CREATE TABLE io_demo AS
SELECT g AS id,
(random() * 1000000)::int AS key,
repeat('x', 200) AS payload
FROM generate_series(1, 2000000) AS g;
CREATE INDEX io_demo_key_idx ON io_demo (key);
ANALYZE io_demo;
SET track_io_timing = on;
SET effective_io_concurrency = 0;
EXPLAIN (ANALYZE, BUFFERS)
SELECT count(payload) FROM io_demo WHERE key BETWEEN 1000 AND 20000;The plan should contain a Bitmap Heap Scan node. If the planner picks a different plan, the test doesn't apply, so check that node first. Look at three things in the output:
Buffers: shared read=...is the number of blocks that were not inshared_buffers.I/O Timings: shared read=...is the total time spent waiting for those reads.Execution Timeat the bottom.
Then run the same statement with SET effective_io_concurrency = 64; and compare. For a fair comparison, both runs need the same cache state. A second run is usually faster simply because the data is now cached, which hides the effect you want to measure. To get a cold start, restart PostgreSQL and drop the OS page cache. On Linux, run sync and then write 3 to /proc/sys/vm/drop_caches as root. Do this only on a test machine, never on a production host.
For a server-wide view, PostgreSQL 16 and later provide the pg_stat_io view, which breaks down reads, writes, and time spent by backend type and I/O context.
SELECT backend_type, object, context, reads, read_time
FROM pg_stat_io
WHERE reads > 0
ORDER BY read_time DESC NULLS LAST;read_time is filled only when track_io_timing is on.
Common errors
- Raising the value on cached workloads. The query is not waiting on storage, so nothing improves. Check
I/O Timingsfirst. If read time is a small part of execution time, look elsewhere. - Expecting plain index scans to speed up. Prefetching helps bitmap scans and other operations that know their upcoming blocks. It does not make a plain index scan read ahead.
- Copying numbers from an old article. The meaning of the value changed in PostgreSQL 13, and the defaults changed again in 18.
- Setting one value for mixed storage. Use tablespace-level settings so slow disks don't receive requests sized for NVMe.
- Ignoring the platform. Prefetching relies on operating system support. On a system without it, PostgreSQL ignores the setting or rejects non-zero values, depending on version. Check the value with
SHOWafter setting it. - Testing with warm caches. Always say which cache state each measurement used.
Tuning order
Treat these settings as late-stage tuning. Fix work_mem spills, checkpoint behavior, and planner cost settings first. Then, if EXPLAIN (ANALYZE, BUFFERS) still shows long read waits on bitmap heap scans and the storage has headroom, raise effective_io_concurrency in steps and measure each step. Keep the smallest value that gives most of the gain.
Exercise
A query uses a Bitmap Heap Scan and I/O Timings: shared read accounts for most of its execution time. The data lives on an NVMe volume, and effective_io_concurrency is 1. Which change do you try, how do you apply it without a restart, and what do you compare afterward?
Show answer
Raise effective_io_concurrency, for example to 200, with SET in a session for testing, or ALTER SYSTEM SET effective_io_concurrency = 200; followed by SELECT pg_reload_conf(); to make it permanent. No restart is needed. Rerun EXPLAIN (ANALYZE, BUFFERS) with track_io_timing on, starting from the same cache state as the first run, and compare I/O Timings: shared read and Execution Time.
Exercise
You raised effective_io_concurrency from 1 to 200 and a slow query that uses a plain Index Scan did not get faster. Give one reason, and say what you would check next.
Show answer
A plain index scan does not read ahead, because each next block depends on the index entry just read, so prefetching does not apply. Another possible reason is that the data was already cached, so the query was not waiting on storage. Check the plan type and the I/O Timings line. If the planner could use a bitmap scan but chose an index scan, look at the planner cost settings such as random_page_cost.