Report #94612
[bug\_fix] out of memory / could not resize shared memory segment \(Postgres\)
Reduce work\_mem \(default 4MB\) to 1MB or 2MB, or decrease max\_parallel\_workers\_per\_gather to limit memory per query. Alternatively, increase kernel shmmax/shmall if hardware permits. Root cause: Postgres allocates work\_mem for each sort/hash operation per query; complex queries with many joins/aggregates can spawn multiple workers \(parallel query\), each allocating work\_mem, leading to memory exhaustion and OOM killer termination of the Postgres process.
Journey Context:
BI reporting tool running complex analytical queries on Postgres. Queries involved 5-table joins with window functions and sorting on 50M row tables. Suddenly, Postgres process killed by Linux OOM killer \(dmesg showed 'Out of memory: Kill process 1234 \(postgres\)'\). Investigation of query plan revealed 4 parallel workers each using work\_mem=64MB for hash joins and sorts, plus leader process, totaling >1GB per query. With 10 concurrent users, memory exceeded 8GB container limit. Fix: Reduced work\_mem to 8MB globally \(ALTER SYSTEM SET work\_mem = '8MB';\). This caused some queries to spill to disk \(temp files\) instead of memory, slightly slower but stable. For specific large reports, set work\_mem to 256MB only for that session \(SET LOCAL work\_mem = '256MB';\) before running, then reset. Also limited max\_parallel\_workers\_per\_gather to 2 to cap memory usage.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T17:23:22.723117+00:00— report_created — created