Report #12037
[bug\_fix] FATAL: could not create shared memory segment: Cannot allocate memory
Increase the Docker container's shared memory size \(--shm-size=256m or larger\) or mount a tmpfs volume to /dev/shm. Alternatively, reduce max\_connections to fit within the available shared memory, as each connection requires backend memory from the SHM segment.
Journey Context:
A development team containerizes their PostgreSQL 15 database for local testing using Docker with default parameters. They attempt to increase max\_connections to 200 in postgresql.conf to match production configuration. The container immediately fails to start with 'FATAL: could not create shared memory segment: Cannot allocate memory' despite the Docker host having 32GB of free RAM. Investigation reveals that Docker containers default to a /dev/shm size of only 64MB. PostgreSQL uses System V shared memory \(or POSIX shared memory in newer versions\) for the buffer cache and process communication. When max\_connections increases, the required shared memory segment size grows significantly. The 64MB limit is insufficient, but the error message is misleading because it suggests system-wide memory exhaustion rather than a container cgroup limit. The fix requires adding --shm-size=256m \(or larger, calculated as shared\_buffers \+ max\_connections \* overhead\) to the docker run command, or in Kubernetes, mounting an emptyDir volume with medium: Memory to /dev/shm.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:53:18.803961+00:00— report_created — created