Report #22765
[bug\_fix] PostgreSQL shared memory exhaustion \(OOM\)
Root cause: PostgreSQL configuration parameters \(work\_mem, shared\_buffers, max\_connections\) are set too high for the available RAM. Specifically, work\_mem is allocated per operation \(sort/hash\) per connection; with high max\_connections, total memory usage can exceed physical RAM, causing OOM killer to terminate PostgreSQL backends or the entire postmaster. Fix: Calculate total memory usage formula: shared\_buffers \+ \(work\_mem \* max\_parallel\_workers\_per\_gather \* max\_connections\) \+ maintenance\_work\_mem < RAM. Reduce work\_mem to default 4MB or lower, enable connection pooling to reduce actual connections, or increase system RAM.
Journey Context:
You tune PostgreSQL for analytical workloads by setting work\_mem = 256MB and max\_connections = 200 on a 64GB RAM server. During peak load, the Linux OOM killer suddenly terminates the postmaster process, crashing the database. Logs show "Out of memory: Kill process 1234 \(postgres\)". You calculate potential memory usage: 256MB \* 200 connections = 50GB just for work\_mem, plus shared\_buffers, exceeding RAM. You reduce work\_mem to 16MB, implement PgBouncer to limit actual connections to 50, and add memory monitoring. The OOM errors cease.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T16:37:10.601328+00:00— report_created — created