pgbouncer-pool-modes

Configure PgBouncer pool modes for Django, FastAPI, and Celery stacks.

Updated Apr 22, 2026
One-click install
npx skills add https://github.com/Mercurium-Analytics/pg-search-vector --skill pgbouncer-pool-modes
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pgbouncer-pool-modes
Source: https://github.com/Mercurium-Analytics/pg-search-vector/tree/main/skills/pgbouncer-pool-modes
Command: npx skills add https://github.com/Mercurium-Analytics/pg-search-vector --skill pgbouncer-pool-modes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

PgBouncer pool modes determine how database connections are reused and can cause migrations to fail, prepared statements to break, or under- or over-utilization of connections if misconfigured.

Core Features & Use Cases

  • Guides optimal pool_mode selection (transaction, session, and statement) for Postgres behind PgBouncer across common stacks like Django, FastAPI, and Celery.
  • Outlines safe migration connectivity strategies, recommended defaults for pool sizing, and best practices to avoid prepared-statement issues.
  • Provides concrete use cases showing when to prefer each pool mode and how to avoid common pitfalls under load.

Quick Start

Explain how to configure PgBouncer pool_mode and related settings for a Django/FastAPI/Celery deployment behind PgBouncer.

Frequently Asked Questions about pgbouncer-pool-modes

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I choose the right PgBouncer pool mode for my Django or FastAPI application?

Choosing the right PgBouncer pool mode depends on your stack's connection lifecycle. Transaction pooling suits most web frameworks like Django and FastAPI, while session pooling is needed for features relying on session-level state.

Why do prepared statements break with PgBouncer transaction pooling?

Prepared statements break with PgBouncer transaction pooling because session state is reset between transactions. You must disable server-side prepared statements or use session pooling to maintain statement persistence across pooled connections.

What is the best way to run Django database migrations behind PgBouncer?

Running Django migrations behind PgBouncer requires a safe connectivity strategy. Bypass transaction pooling during migrations by connecting directly to Postgres or using a session-pooled admin connection to avoid locking conflicts.

How do I configure default_pool_size and max_client_conn for Postgres connection pooling?

Configure default_pool_size and max_client_conn to balance Postgres resource limits against client concurrency. Setting default_pool_size caps backend connections per database, while max_client_conn limits total incoming client connections to prevent overload.

When should I use session pooling instead of transaction pooling for Celery workers?

Session pooling is preferable for Celery workers when tasks require persistent session state or server-side prepared statements. Transaction pooling works better for short, independent tasks to maximize connection reuse and throughput.

What are the limitations of statement pooling in PgBouncer for Postgres applications?

Statement pooling in PgBouncer limits multi-statement transactions and breaks session-level features. It only works when queries never rely on transaction boundaries, making it unsuitable for most Django and FastAPI application workloads.