Skip to content
/
Suscribirse Subscribe

Detrás del telón hay sistemas, no magia. Arquitectura de software, IA y computación de bajo nivel para las trincheras de producción.

Behind the curtain there are systems, not magic. Software architecture, AI, and systems engineering from the production trenches.

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.

Calculating memory headroom...
shared_buffers
-
effective_cache_size
-
work_mem (per operation)
-
maintenance_work_mem
-
wal_buffers
-
Worst-Case RAM Peak
-
Optimal PgBouncer Pool
-

    

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.

shared_buffers = Total_RAM * 0.25 (0.20 on shared hosts) effective_cache_size = Total_RAM * 0.75 (planner hint only; allocates zero RAM) wal_buffers = min(16 MB, shared_buffers / 32) Query_RAM_Budget = Total_RAM - shared_buffers - OS_Reserve(15%) - (max_connections * 10 MB) Safe_work_mem = Query_RAM_Budget / (max_connections * ops_per_query) Worst_Case_Peak_RAM = shared_buffers + OS_Reserve + (max_connections * 10 MB) + (max_connections * ops_per_query * work_mem)

Verified Official Sources

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.

Suscribirse Subscribe