Tuning the Query Planner Cost Constants
Learn how planner cost constants like random_page_cost and effective_cache_size shape plan choices, and how to adjust them to match your hardware and data.
The Planner Needs Hints About Hardware
The planner estimates the cost of each plan using constants that model your hardware. If those constants do not match reality, it may pick a sequential scan when an index scan would be far faster, or vice versa.
seq_page_cost vs random_page_cost
Two key constants:
seq_page_cost(default 1.0): cost to read a page sequentiallyrandom_page_cost(default 4.0): cost to read a page at random
The 4:1 ratio assumes spinning disks where random reads are slow.
All lessons in this course
- postgresql.conf Key Parameters
- Memory (shared_buffers, work_mem) Tuning
- Disk I/O and Checkpoint Tuning
- Tuning the Query Planner Cost Constants