SQL Performance Lab
SQL 튜닝은 느린 query를 빠르게 만드는 한 번의 작업이 아니라, workload에서 대상을 찾고 실행 계획으로 가설을 세운 뒤 같은 조건에서 검증하는 과정입니다. 이 Lab은 PostgreSQL 18을 기준으로 EXPLAIN ANALYZE, planner statistics, index, join, sort, hash, parallel execution과 production 회귀 관리를 직접 실험합니다.
모든 실습은 결과가 달라지는 이유를 기록하도록 구성했습니다. “Index를 만들었더니 빨라졌다”에서 끝내지 않고 planning time, execution time, buffer, WAL, temporary I/O, row estimate와 동시성 부작용을 비교합니다.
차례
- Part I. Lab 준비: dataset, 측정 기준, 안전한 실행
- Part II. EXPLAIN 읽기: plan tree, estimate, buffer, WAL
- Part III. Planner Statistics: ANALYZE, skew, extended statistics
- Part IV. Scan과 Index: seq, index, bitmap, index-only, partial
- Part V. Join: nested loop, hash, merge, join order
- Part VI. Sort, Aggregate, Parallel: work_mem, spill, parallel, JIT
- Part VII. Production Tuning: pg_stat_statements, lock, 회귀, runbook
시작하기
Docker Compose Lab, init.sql, workbook.sql을 같은 directory에 내려받습니다.
docker compose -f compose.yml up -d
psql 'postgresql://lab:lab@127.0.0.1:55432/perflab' -f workbook.sql
실습 password와 port는 local 전용입니다. 외부 interface에 공개하지 않습니다. EXPLAIN ANALYZE는 query를 실제 실행하므로 production DML에 사용할 때 transaction과 rollback 전략을 먼저 준비합니다.