0Pricing
PostgreSQL Performance & Query Optimization · Lesson

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 sequentially
  • random_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

  1. postgresql.conf Key Parameters
  2. Memory (shared_buffers, work_mem) Tuning
  3. Disk I/O and Checkpoint Tuning
  4. Tuning the Query Planner Cost Constants
← Back to PostgreSQL Performance & Query Optimization