Skip to content
Tomas Vondra Postgres Blog·

Tomas Vondra Reexamines PostgreSQL random_page_cost

Some more thoughts on random_page_cost

Key Takeaway

Tomas Vondra argues that random_page_cost also compensates for PostgreSQL cost-model gaps around memory, cache locality, and concurrent resource contention.

Test conditions

The post reframes random_page_cost as a proxy for memory, cache locality, and contention effects, and recommends tuning it through workload monitoring rather than storage benchmarks alone.

Technical Breakdown · Distilled from the original source

Storage benchmarks do not directly determine the setting

  • Vondra estimated a random_page_cost of about 125 on rotational SATA drives, two to four times the SSD estimates and far above the default of 4.0. The SSD results being closer to the default does not mean the default represents the raw cost of random I/O.

How scan choices affect caching and concurrency

  • On a cold 100 GB table with 1 GB of matching data, a sequential scan may displace about 100 GB of other data from shared buffers or the OS page cache, even with work_mem set to 4 MB. An index scan may touch only about 1 GB. Its random reads may take longer, but it can evict less unrelated data.
  • Index scans typically touch only the data of interest, helping keep the active set in memory. Sequential scans can expand that set. The planner accounts for caching only in limited cases, such as within a single query, and does not model bandwidth contention across queries. A sequential scan may work well for one backend, while 100 backends doing sequential scans can saturate storage bandwidth.

Validate changes against the workload

  • Lowering random_page_cost favors plans that touch a smaller portion of the data, but storage benchmarks alone cannot tell you where to set it. Use pg_stat_statements to identify top queries that might benefit, then try an adjustment and monitor whether those queries improve or others regress.
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