GEARFLOW LAB // CLIENT-SIDE DATABASE UTILITY 100% In-Browser JS · Zero Network Calls

PostgreSQL & PgBouncer Memory & Connection Pool Calculator

Calculate safe shared_buffers, effective_cache_size, per-sort work_mem, max_connections, and PgBouncer pool limits from your container RAM and peak client concurrency. Grounded in our Docker lab benchmark where PgBouncer 1.23.1 cut 450-connection backend RSS from 739.5 MiB down to 84.8 MiB.

Quick Presets:

1. Container & Workload Parameters

Clamped safely to 0.5–4096 GB (or 256–4,194,304 MiB).
110 clients
Total worker threads across n8n, FastAPI, Node.js, or PHP-FPM pods (5–10,000).
Supports fractional Docker CPU quotas (0.5–256 vCores) to size default_pool_size.
Advanced Parameter Overrides (Optional)
High OOM / SQLSTATE 53300 Risk (100% of Container RAM) Estimated peak memory (4079 MiB) exceeds safe headroom for a 4096 MiB container. Switch Pooling Mode to Transaction or increase container RAM to avoid Linux cgroup Exit Code 137 OOM kills.
shared_buffers
1GB
25% of container RAM
Safe work_mem
56MB
Per sort/hash operation
max_connections
60
default_pool_size = 20
Backend RSS Overhead
173.7 MiB
Saves 574.3 MiB vs unpooled
Estimated Peak Container Memory Footprint 4,117 MiB / 4,096 MiB

Without PgBouncer, 110 direct backends consume ~748.0 MiB in per-process RSS alone (~6.8 MiB/backend). With PgBouncer Transaction pooling, active backend + pooler RSS drops to ~173.7 MiB (verified against our PostgreSQL & PgBouncer Docker connection-pooling benchmark: 739.5 MiB unpooled vs 84.8 MiB pooled).

postgresql.conf

pgbouncer.ini

Why Unpooled PostgreSQL Connections Exhaust Container RAM

PostgreSQL spawns a dedicated OS backend process (postgres: user db [client]) for every client TCP connection instead of multiplexing sockets inside a single thread pool. Even an idle backend initializes local catalog caches, lock tables, and process state totaling roughly 6.5 MiB to 9.5 MiB of private RSS once it touches a few relations. Raising max_connections to 500 on a 1 GB or 2 GB Docker container without a pooler invites two failure modes: immediate FATAL: sorry, too many clients already (SQLSTATE 53300) during webhook bursts, or kernel cgroup OOMKilled (Exit Code 137) when concurrent sorts allocate multiple work_mem buffers simultaneously.

In our PostgreSQL & PgBouncer Docker connection-pooling benchmark, holding 450 direct PostgreSQL connections consumed 739.5 MiB of container RSS. Placing PgBouncer 1.23.1 in front of PostgreSQL in transaction mode served 110 concurrent clients across a 20-backend pool (default_pool_size = 20) at just 84.8 MiB combined RSS with zero dropped queries.

Architecture Matrix: Unpooled Postgres vs PgBouncer vs SQLite WAL

Database Topology Observed RAM / Concurrency Behavior Best Fit Stack
Direct PostgreSQL (No Pooler) ~6.5 to 9.5 MiB RSS per backend; 450 backends used 739.5 MiB RSS; hits SQLSTATE 53300 above max_connections. Low-client internal jobs (< 30 persistent connections) or session-lock workers.
PostgreSQL + PgBouncer (transaction) 84.8 MiB combined RSS serving 110 clients via 20 server backends (~2 KiB per queued client socket). Production n8n PostgreSQL queue stacks, FastAPI, Next.js serverless functions.
SQLite WAL + Application Mutex Zero separate DB daemon; 200/200 writes succeeded at 129.7 ms p95 under 50-way HTTP burst when serialized in-process. Single-container embedded apps (see SQLite WAL benchmark).

PostgreSQL & PgBouncer Sizing FAQ

Why can high work_mem crash PostgreSQL even when shared_buffers is only 25% of RAM?

PostgreSQL allocates shared_buffers once at startup, whereas work_mem can be allocated multiple times per active query for every hash join or sort node. Fifty unpooled backends running two sort nodes each with work_mem = 64MB can demand 6,400 MiB of anonymous memory and trigger a Linux cgroup OOM kill.

Does PgBouncer transaction pooling support PostgreSQL prepared statements?

PgBouncer 1.21 and newer (including 1.23.1) support protocol-level prepared statements in transaction mode when you set max_prepared_statements = 100 (or higher) in pgbouncer.ini. On older PgBouncer releases, clients had to disable prepared statements to avoid prepared statement does not exist errors.

How should max_connections relate to PgBouncer default_pool_size?

Set PostgreSQL max_connections higher than the sum of PgBouncer default_pool_size plus reserve_pool_size across all database pools, leaving 10 to 15 spare slots above superuser_reserved_connections = 3 for pg_dump backups, migrations, and interactive psql debugging.

TOPIC CLUSTER HUB & COMPANION BROWSER UTILITIES

Deploy Your Tuned Database Stack in Production

PgBouncer Docker Compose blueprints, n8n SQLite-to-PostgreSQL migrations, SQLite WAL benchmarks, and volume backups.

Docker Run to Compose Converter →

Generate Compose v2 YAML with mem_limit, 127.0.0.1 port bindings, and healthchecks for Postgres.

Nginx 502/504 & SSE Timeout Generator →

Align upstream Nginx proxy timeouts (60s–3600s), SSE streaming rules, and PHP-FPM workers with your database pool.

Local LLM VRAM & KV Cache Calculator →

Size GGUF/AWQ weights, GQA KV cache across parallel slots, decode tok/s, and Ollama, vLLM, or llama.cpp flags.

Mac & 5K2K Monitor PPI Calculator →

Compute macOS 2x HiDPI framebuffer Unified Memory (MiB), Retina PPI zones, and DP 1.4 / TB4 / TB5 DSC link bandwidth.