random_page_cost
Planner cost of a non-sequential page read, relative to seq_page_cost (1.0).
- По умолчанию
4.0- Range
- 0 upward (float)
- Restart needed
- Нет
- Default checked on
- PostgreSQL 18
Что оно делает
The default 4.0 models spinning disks with mostly cached data. On SSDs random reads cost little more than sequential ones, and a high value makes the planner shy away from index scans.
Значение по умолчанию
4.0. 4.0 (PostgreSQL 18); seq_page_cost is 1.0.
Check the current value
SHOW random_page_cost; SELECT setting, unit, boot_val, context, source, pending_restart FROM pg_settings WHERE name = 'random_page_cost';
Change it
SET random_page_cost = 1.1; -- this session ALTER ROLE reporting SET random_page_cost = 1.1; -- new sessions of one role ALTER SYSTEM SET random_page_cost = 1.1; SELECT pg_reload_conf();
No restart. Any role can SET it for a session or with SET LOCAL for one transaction; a server-wide ALTER SYSTEM change applies after a reload (context is user).
When to change it
On SSD, NVMe or cloud storage, 1.1-1.5 is common. Can also be set per tablespace.
What can go wrong
Too low leads to index scans on data that is not cached and not fast to read randomly.
Questions about random_page_cost
What is the default value of random_page_cost in PostgreSQL?
4.0. 4.0 (PostgreSQL 18); seq_page_cost is 1.0.
Does changing random_page_cost require a restart?
No. No restart. Any role can SET it for a session or with SET LOCAL for one transaction; a server-wide ALTER SYSTEM change applies after a reload (context is user).
When should I change random_page_cost?
On SSD, NVMe or cloud storage, 1.1-1.5 is common. Can also be set per tablespace.
Back to all PostgreSQL settings, or check the PostgreSQL manual for every option.
Check random_page_cost on your own server
SQLly runs the query above against PostgreSQL and the other engines in this reference, from one desktop app on macOS, Windows and Linux.