0Pricing
PostgreSQL Performance & Query Optimization · 강의

쿼리 플래너 비용 상수 조정

random_page_cost와 effective_cache_size 같은 플래너 비용 상수가 계획 선택에 미치는 영향과 하드웨어 및 데이터에 맞게 이를 조정하는 방법을 배워 보세요.

쿼리 플래너 비용 상수 조정은(는) CoddyKit의 무료 PostgreSQL Performance & Query Optimization 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 PostgreSQL Performance & Query Optimization 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. PostgreSQL Performance & Query Optimization 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

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.

Tuning for SSDs

On SSDs random reads are nearly as cheap as sequential ones. Lowering random_page_cost makes the planner favor index scans appropriately.

SET random_page_cost = 1.1;

effective_cache_size

This tells the planner how much memory the OS and PostgreSQL together are likely to use for caching data. It does not allocate memory — it only influences cost estimates for index scans.

SET effective_cache_size = '12GB';

Why effective_cache_size Matters

A large value tells the planner that repeated index lookups will likely hit cache, making index scans look cheaper and more attractive for large tables. Set it to roughly 50-75% of total RAM.

CPU Cost Constants

Finer constants weigh CPU work:

  • cpu_tuple_cost: per-row processing
  • cpu_index_tuple_cost: per index entry
  • cpu_operator_cost: per operator/function call

These are rarely changed but matter for CPU-heavy expressions.

Testing a Change at Session Level

Test constants with SET in your session before making them permanent. Compare plans with EXPLAIN.

SET random_page_cost = 1.1;
EXPLAIN SELECT * FROM orders WHERE customer_id = 42;

Making It Permanent

Once satisfied, set the value cluster-wide and reload, or edit postgresql.conf.

ALTER SYSTEM SET random_page_cost = 1.1;
SELECT pg_reload_conf();

Beware of Over-Tuning

Do not chase a single slow query by skewing constants globally — you may break thousands of other plans. Fix the root cause (missing index, stale stats) first; adjust constants only for genuine hardware mismatches.

Per-Tablespace Tuning

If some data sits on SSD and some on HDD, you can set random_page_cost per tablespace so the planner reasons about each storage medium correctly.

ALTER TABLESPACE fast_ssd
SET (random_page_cost = 1.1);

Verifying the Effect

After changing a constant, confirm the planner actually switched plans. Run EXPLAIN before and after and look for a Seq Scan turning into an Index Scan (or vice versa).

EXPLAIN SELECT * FROM orders WHERE customer_id = 42;
SET random_page_cost = 1.1;
EXPLAIN SELECT * FROM orders WHERE customer_id = 42;

Quick Check

Test your planner-tuning knowledge.

Recap

You learned planner cost tuning:

  • Cost constants model your hardware for the planner
  • Lower random_page_cost on SSDs to favor index scans
  • Set effective_cache_size to ~50-75% of RAM
  • Test with SET and EXPLAIN before ALTER SYSTEM
  • Fix indexes/stats before skewing constants globally

자주 묻는 질문

“쿼리 플래너 비용 상수 조정” 강의는 무료인가요?

네 — “쿼리 플래너 비용 상수 조정” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 PostgreSQL Performance & Query Optimization 강의 전체를 잠금 해제할 수 있습니다. PostgreSQL Performance & Query Optimization 강의에는 총 4개의 강의가 포함되어 있습니다.

“쿼리 플래너 비용 상수 조정”에서 뭘 배우나요?

random_page_cost와 effective_cache_size 같은 플래너 비용 상수가 계획 선택에 미치는 영향과 하드웨어 및 데이터에 맞게 이를 조정하는 방법을 배워 보세요. 브라우저에서 직접 실행하는 실습 코드로 PostgreSQL Performance & Query Optimization을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

PostgreSQL Performance & Query Optimization을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 PostgreSQL Performance & Query Optimization은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“쿼리 플래너 비용 상수 조정” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 PostgreSQL Performance & Query Optimization 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 PostgreSQL Performance & Query Optimization 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. postgresql.conf 주요 매개변수
  2. 메모리(shared_buffers, work_mem) 튜닝
  3. 디스크 I/O 및 체크포인트 튜닝
  4. 쿼리 플래너 비용 상수 조정
← PostgreSQL Performance & Query Optimization(으)로 돌아가기