0Pricing
Advanced PostgreSQL: Indexing, Partitioning, Replication · 강의

PgBouncer와 HAProxy를 활용한 연결 라우팅

현재 기본 서버로 클라이언트를 라우팅하고 읽기 트래픽을 복제본에 분산해 장애 조치 중에도 애플리케이션의 가용성을 유지하는 방법을 익혀 보세요.

PgBouncer와 HAProxy를 활용한 연결 라우팅은(는) CoddyKit의 무료 Advanced PostgreSQL: Indexing, Partitioning, Replication 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Advanced PostgreSQL: Indexing, Partitioning, Replication 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Advanced PostgreSQL: Indexing, Partitioning, Replication 강의에는 총 4개의 강의가 포함되어 있습니다.

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

The Routing Problem

After a failover the primary moves to a new host. Applications need a stable endpoint so they do not have to be reconfigured each time. Connection routing solves this.

PgBouncer Basics

PgBouncer is a lightweight connection pooler. It multiplexes many client connections onto a small set of server connections, reducing backend load.

Pooling Modes

PgBouncer offers three pool modes:

  • session — connection held for the whole client session
  • transaction — returned after each transaction (most common)
  • statement — returned after each statement

Basic Config

A minimal pgbouncer.ini points at the database and sets the pool mode.

[databases]
app = host=10.0.0.5 port=5432 dbname=app
[pgbouncer]
pool_mode = transaction
max_client_conn = 1000
default_pool_size = 20

HAProxy for the Primary

HAProxy can health-check backends and forward traffic only to the node that is currently the primary, giving clients one fixed write endpoint.

Detecting the Primary

HAProxy uses an HTTP health check against a tool like Patroni's REST API. Only the primary returns 200 on the leader endpoint.

option httpchk GET /primary
http-check expect status 200

Separate Read Endpoint

Define a second HAProxy frontend that balances across replicas (the /replica health check), so read-only queries scale across standbys.

listen postgres_read
  bind *:5433
  balance roundrobin
  option httpchk GET /replica

Read/Write Splitting

Applications connect to port 5432 for writes (primary) and 5433 for reads (replicas). Many drivers and ORMs support separate read/write data sources.

Replica Lag Caution

Replicas can lag behind the primary. Route only queries that tolerate slightly stale data to replicas; read-your-own-write paths should hit the primary.

Putting It Together

A common stack: app -> PgBouncer -> HAProxy -> Patroni-managed PostgreSQL cluster. PgBouncer pools, HAProxy routes by role, Patroni manages failover.

Failover Behavior

On failover, Patroni promotes a new primary, HAProxy health checks flip the leader within seconds, and pooled connections reconnect to the new endpoint with minimal disruption.

Quick Check

How does HAProxy keep sending writes to the right node after failover?

Recap

You learned to route connections for high availability: PgBouncer pools connections, HAProxy health-checks to find the primary and balance reads across replicas, and the whole stack flips automatically on failover.

자주 묻는 질문

“PgBouncer와 HAProxy를 활용한 연결 라우팅” 강의는 무료인가요?

네 — “PgBouncer와 HAProxy를 활용한 연결 라우팅” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Advanced PostgreSQL: Indexing, Partitioning, Replication 강의 전체를 잠금 해제할 수 있습니다. Advanced PostgreSQL: Indexing, Partitioning, Replication 강의에는 총 4개의 강의가 포함되어 있습니다.

“PgBouncer와 HAProxy를 활용한 연결 라우팅”에서 뭘 배우나요?

현재 기본 서버로 클라이언트를 라우팅하고 읽기 트래픽을 복제본에 분산해 장애 조치 중에도 애플리케이션의 가용성을 유지하는 방법을 익혀 보세요. 브라우저에서 직접 실행하는 실습 코드로 Advanced PostgreSQL: Indexing, Partitioning, Replication을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Advanced PostgreSQL: Indexing, Partitioning, Replication을(를) 시작하는 데 경험이 필요한가요?

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

“PgBouncer와 HAProxy를 활용한 연결 라우팅” 강의는 얼마나 걸리나요?

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

이 Advanced PostgreSQL: Indexing, Partitioning, Replication 강의에서 코드를 작성하고 실행할 수 있나요?

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

이 강의의 모든 강의

  1. 자동 장애 조치 도구(Patroni)
  2. 복제 상태 모니터링
  3. 재해 복구 전략
  4. PgBouncer와 HAProxy를 활용한 연결 라우팅
← Advanced PostgreSQL: Indexing, Partitioning, Replication(으)로 돌아가기