Out-of-the-box postgresql.conf defaults (shared_buffers = 128MB, work_mem = 4MB, effective_cache_size = 4GB) are meant to boot cleanly on minimal hardware, not survive real production traffic. This calculator sizes your shared memory buffers, models worst-case RAM bursts so Linux does not invoke the OOM Killer, and exports a clean baseline alongside an optimal PgBouncer transaction pool target.
Exact Mathematical Formulas & OOM Prevention
The classic production outage comes from confusing work_mem with a per-connection cap. Per official PostgreSQL documentation, work_mem caps memory per individual sort or hash table operation, meaning a multi-join query across parallel workers can allocate several multiples of work_mem simultaneously.
Verified Official Sources
- PostgreSQL Docs — 19.4. Resource Consumption: baseline defaults (
shared_buffers = 128MB,work_mem = 4MB,maintenance_work_mem = 64MB) and concurrency multiplier behavior. - PostgreSQL Docs — Connections & max_connections: default
100limit, shared-memory scaling impact, and standby server constraints. - PostgreSQL Docs — Write-Ahead Log (WAL): automatic
wal_buffers = -1sizing at 1/32 ofshared_bufferscapped at one 16 MB WAL segment. - PostgreSQL Docs — Query Planning:
effective_cache_size(4GBdefault) andrandom_page_cost(4.0default vs.1.1on NVMe).
Real-World Production Sizing Benchmarks
| Scenario | RAM / vCPU | max_connections | shared_buffers | Safe work_mem | PgBouncer Pool |
|---|---|---|---|---|---|
| Small VPS App | 8 GB / 4 vCPU | 100 direct | 2 GB | 16 MB | 12 |
| SaaS OLTP (NVMe) | 32 GB / 8 vCPU | 200 direct | 8 GB | 36 MB | 24 |
| Unpooled Spike Trap | 32 GB / 8 vCPU | 800 direct | 8 GB | 4 MB (high OOM risk) | 24 (Recommended) |
| Analytics / pgvector Node | 128 GB / 32 vCPU | 80 via PgBouncer | 32 GB | 256 MB | 80 |
Frequently Asked Questions (FAQ)
Why shouldn't I give 70% of RAM directly to shared_buffers?
PostgreSQL relies heavily on the Linux OS page cache. Allocating beyond 25%–40% to shared_buffers increases checkpoint flush pressure while starving sort/hash working memory and OS filesystem buffers.
Does effective_cache_size allocate physical RAM?
No. As documented in Section 19.7 of the official PostgreSQL manual, it is strictly a cost-model hint telling the query planner how much combined buffer + OS page cache is available so it avoids unnecessary sequential scans.
When should I raise maintenance_work_mem?
Raising it to 1–2 GB dramatically cuts VACUUM, CREATE INDEX, and emergency REINDEX windows — especially after security upgrades like the 52 PostgreSQL CVEs and EOL 14 shutdown. Pair it with our SLA Uptime & Error Budget Calculator and browse the full Syncroma Engineering Tools suite.