////

PostgreSQL planner control

PostgreSQL 쿼리는 실행 계획 없이 실행될 수 없으므로 planner/optimizer를 완전히 비활성화할 수는 없다. 디버깅이나 실험 목적이라면 enable planner GUC와 join collapse limit, from collapse limit 같은 설정으로 선택지를 제한해 계획 변화를 관찰한다.

////

Summary#

PostgreSQL 쿼리는 실행 계획 없이 실행될 수 없으므로 planner/optimizer를 완전히 비활성화할 수는 없다. 디버깅이나 실험 목적이라면 enable_* planner GUC와 join_collapse_limit, from_collapse_limit 같은 설정으로 선택지를 제한해 계획 변화를 관찰한다.

Problem#

개발자가 PostgreSQL query optimization을 완전히 꺼서 “최적화되지 않은 기본 실행 경로”를 보거나 특정 단순 실행 방식을 강제하고 싶어 한다.

Solution#

  • PostgreSQL은 모든 쿼리에 대해 실행 계획을 만들어야 하므로 optimizer/planner를 완전히 끄는 방식은 없다.
  • 실험 목적이라면 세션 단위에서 planner method 설정을 조정한다.
  • 예: SET enable_seqscan = off;, SET enable_hashjoin = off;, SET enable_nestloop = off;, SET enable_mergejoin = off;
  • 단, 일부 설정은 완전한 금지가 아니라 planner가 해당 방식을 덜 선호하게 만드는 비용 조정에 가깝다.
  • 조인 재정렬 영향을 줄이고 명시한 FROM/JOIN 순서를 더 강하게 반영하려면 다음을 실험한다.
  • SET join_collapse_limit = 1;
  • SET from_collapse_limit = 1;
  • 계획 확인은 EXPLAIN 또는 실제 실행 비용까지 볼 때 EXPLAIN (ANALYZE, BUFFERS)를 사용한다. ANALYZE는 실제 쿼리를 실행하므로 쓰기 쿼리에는 주의한다.

Failure Modes#

  • optimizer를 끄면 사용할 수 있는 “기본 plan”이 있다고 가정하는 것.
  • planner GUC를 글로벌로 바꿔 다른 쿼리와 벤치마크를 왜곡하는 것.
  • 디버깅용 forced plan을 production 최적화로 오해하는 것.
  • enable_* = off를 절대 금지로 해석하는 것. PostgreSQL은 실행 가능한 대안이 없으면 비선호 경로도 사용할 수 있다.
  • 조인 순서 실험을 실제 데이터 분포, 통계, 인덱스, work_mem 조건과 분리해 해석하는 것.
  • personal_vault/knowledge/dev/postgresql-advanced.md
  • personal_vault/projects/ops/librarian/capsules/PostgreSQL 심화 가이드 Capsule.md

Sources#

  • PostgreSQL Official Documentation — Query Planning: https://www.postgresql.org/docs/current/runtime-config-query.html
  • PostgreSQL Official Documentation — Planner Method Configuration: https://www.postgresql.org/docs/current/runtime-config-query.html#RUNTIME-CONFIG-QUERY-ENABLE
  • PostgreSQL Official Documentation — Genetic Query Optimizer / join collapse behavior: https://www.postgresql.org/docs/current/geqo-pg-intro.html
  • PostgreSQL Official Documentation — EXPLAIN: https://www.postgresql.org/docs/current/sql-explain.html
  • PostgreSQL Official Documentation — Using EXPLAIN: https://www.postgresql.org/docs/current/using-explain.html

Sagwan Revalidation 2026-07-03T01:29:42Z#

  • verdict: ok
  • note: planner GUC와 조인 collapse 설명은 현재 PostgreSQL 관행과도 일치함

Sagwan Revalidation 2026-07-04T12:33:21Z#

  • verdict: ok
  • note: planner GUC와 조인 collapse 설명이 현 PostgreSQL practice와 부합함

Sagwan Revalidation 2026-07-05T14:33:26Z#

  • verdict: ok
  • note: planner GUC와 조인 collapse 설명은 현재 PostgreSQL practice와 일치함

Sagwan Revalidation 2026-07-06T21:20:28Z#

  • verdict: ok
  • note: PostgreSQL planner GUC와 조인 collapse 설명은 최신 문서와 여전히 일치함

Sagwan Revalidation 2026-07-08T04:05:41Z#

  • verdict: ok
  • note: PostgreSQL planner GUC와 조인 collapse 설명은 현재 문서 기준으로도 유효하다.

Sagwan Revalidation 2026-07-10T02:20:46Z#

  • verdict: ok
  • note: PostgreSQL planner GUC와 collapse_limit 설명은 현재도 유효하다.

Sagwan Revalidation 2026-07-11T19:59:43Z#

  • verdict: ok
  • note: PostgreSQL planner GUC와 조인 순서 제어 설명은 현재도 유효함

Sagwan Revalidation 2026-07-13T15:04:42Z#

  • verdict: ok
  • note: PostgreSQL planner GUC와 조인 collapse 설명은 현재 문서 기준 여전히 유효함

Sagwan Revalidation 2026-07-15T14:13:52Z#

  • verdict: ok
  • note: planner GUC와 조인 collapse 설명이 최신 PostgreSQL 관행과 부합함

Sagwan Revalidation 2026-07-17T14:52:00Z#

  • verdict: ok
  • note: planner GUC와 조인 collapse 설정 설명이 현재 PostgreSQL 문서와 부합함

Sagwan Revalidation 2026-07-19T16:12:45Z#

  • verdict: ok
  • note: PostgreSQL planner GUC와 조인 collapse 설명은 최신 문서 기준 여전히 유효함

Sagwan Revalidation 2026-07-21T17:58:53Z#

  • verdict: ok
  • note: PostgreSQL planner GUC와 EXPLAIN 관련 설명은 현행 문서와 부합한다.

Sagwan Revalidation 2026-07-23T19:05:59Z#

  • verdict: ok
  • note: 핵심 주장과 GUC 사용법이 현재 PostgreSQL practice와도 일치한다.

Sagwan Revalidation 2026-07-25T21:20:14Z#

  • verdict: ok
  • note: PostgreSQL planner GUC와 EXPLAIN 주의사항은 현재 문서와 실무에 부합함

Sagwan Revalidation 2026-07-28T03:47:18Z#

  • verdict: ok
  • note: planner 비활성화 불가와 GUC 기반 실험 권장은 현재도 유효함

Sagwan Revalidation 2026-07-30T08:38:27Z#

  • verdict: ok
  • note: PostgreSQL planner 제어 설명과 주의점은 현재도 유효하다.

Sagwan Revalidation 2026-08-01T19:17:35Z#

  • verdict: ok
  • note: PostgreSQL planner GUC와 조인 collapse 설명은 최신 관행과 문서에 부합함

Sagwan Revalidation 2026-08-04T08:19:21Z#

  • verdict: ok
  • note: PostgreSQL planner GUC와 조인 순서 제어 설명은 현재도 유효하다.

Sagwan Revalidation 2026-08-08T04:30:26Z#

  • verdict: ok
  • note: [chatgpt HTTP 401] {

Sagwan Revalidation 2026-08-10T16:12:39Z#

  • verdict: ok
  • note: [chatgpt HTTP 401] {

Sagwan Revalidation 2026-08-13T04:34:27Z#

  • verdict: ok
  • note: [chatgpt HTTP 401] {

Sagwan Revalidation 2026-08-15T16:58:20Z#

  • verdict: ok
  • note: [chatgpt HTTP 401] {

Sagwan Revalidation 2026-08-18T04:57:45Z#

  • verdict: ok
  • note: [chatgpt HTTP 401] {

Sagwan Revalidation 2026-08-20T17:22:52Z#

  • verdict: ok
  • note: [chatgpt HTTP 401] {

Sagwan Revalidation 2026-08-23T06:27:34Z#

  • verdict: ok
  • note: [chatgpt HTTP 401] {

Sagwan Revalidation 2026-08-25T18:27:47Z#

  • verdict: ok
  • note: [chatgpt HTTP 401] {

Sagwan Revalidation 2026-08-28T07:10:20Z#

  • verdict: ok
  • note: [chatgpt HTTP 401] {

Sagwan Revalidation 2026-08-30T19:08:00Z#

  • verdict: ok
  • note: [chatgpt HTTP 401] {

Sagwan Revalidation 2026-09-02T09:14:04Z#

  • verdict: ok
  • note: PostgreSQL planner GUC와 collapse 설정 설명은 현재 문서와 practice에 부합함

Sagwan Revalidation 2026-09-08T11:51:06Z#

  • verdict: ok
  • note: [chatgpt HTTP 404] {

Sagwan Revalidation 2026-09-11T01:11:25Z#

  • verdict: ok
  • note: PostgreSQL planner GUC와 조인 순서 제어 설명은 현재 문서와 부합한다.

Sagwan Revalidation 2026-09-13T21:20:18Z#

  • verdict: ok
  • note: enable_* GUC 동작·join_collapse_limit·EXPLAIN 구문 모두 PostgreSQL 17.x에서 그대로 유효하며 기술 내용에 낡은 부분 없음.

Reviews

Support
0
Dispute
0
Neutral
0
Visible Reviews
1