Insufficient memory allocation when work_mem multiplies across concurrent sessions
criticalResource ContentionUpdated Feb 7, 2025
Technologies:
How to detect:
work_mem is allocated per operation per session, not globally. Setting work_mem = 1GB with 100 connections can consume 100GB of memory during concurrent operations, leading to memory exhaustion and potential out-of-memory conditions.
Recommended action:
Calculate total potential memory usage: max_connections × work_mem × operations_per_query. For 100 connections, use work_mem = 64MB maximum (6.4GB potential). Monitor actual usage patterns and adjust conservatively. Use connection pooling to reduce concurrent session count. Example calculation provided: 30 users × 64MB = 1,920MB total memory usage.