Skip to content
Tomas Vondra Postgres Blog·

PostgreSQL random_page_cost Costs More Than the Default Suggests

The real cost of random I/O

Key Takeaway

Tomas Vondra’s experiments estimate random_page_cost at about 25–35 on local SSDs, far above the default 4. 0, with an even larger gap on Azure remote SSDs.

Why It Matters

The experiments quantify how random_page_cost diverges from real I/O behavior and connect GUC tuning with caching, prefetching, and planner cost-model improvements.

Technical Breakdown · Distilled from the original source

How the experiment isolated caching

  • Vondra set both shared_buffers and effective_cache_size to 128 MB and enabled direct I/O to exclude the operating system’s page cache. The table’s physical row order was randomized so that scanning by index key produced nearly random heap access.
  • In the 10-million-row example, the sequential scan read 454,546 pages in about 708 ms, while the index scan took about 393 seconds. The rough per-page estimates of 1.559 and 39.298 microseconds yielded a relative cost of 25.2.

Plan crossover and prefetching

  • Comparing only sequential and plain index scans, the default of 4.0 made the planner switch to a sequential scan at about 2.2% selectivity, although it was already faster at about 0.2%. Setting the cost to 30 nearly aligned those crossovers. In practice, bitmap scans reduce the risk by making heap access more sequential and supporting prefetching.
  • effective_io_concurrency changes prefetch behavior and runtime, not estimated costs. Disabling prefetch lowered the inferred ratio from about 30 to about 10 because sequential scans slowed down; plain index scans in the experiment did not prefetch, so random reads did not become faster.

When a lower setting can still make sense

  • If an OLTP workload’s hot set fits in memory, index scans may require little physical I/O. A full table scan can instead read cold pages and evict hot pages needed by other queries. Vondra recommends evaluating tuning with query latency monitoring or pg_stat_statements snapshots rather than adopting the experimental value directly.
Source: Tomas Vondra Postgres Blog· vondra.me

PG Radar summarizes verified changes and impact. Read the original post for full technical details and code samples.

Read Official Source

Related PostgreSQL Reference