Report #42600
[bug\_fix] could not create shared memory segment: Cannot allocate memory \(max\_connections too high\)
Root cause: PostgreSQL pre-allocates shared memory based on max\_connections, shared\_buffers, and other parameters. If max\_connections is raised significantly without increasing kernel SHMMAX/SHMALL \(or if the container has limited /dev/shm\), startup fails. Fix: Increase kernel shmmax \(sysctl kernel.shmmax=...\) and shmall, or for containers, mount /dev/shm with larger size \(docker --shm-size=2g or Kubernetes emptyDir with sizeLimit\). Alternatively, keep max\_connections low \(100-200\) and use an external pooler \(PgBouncer\) to handle thousands of clients.
Journey Context:
You migrate your PostgreSQL container to Kubernetes and increase max\_connections from 100 to 500 for Black Friday. The pod crashes on startup with 'FATAL: could not create shared memory segment: Cannot allocate memory'. You check dmesg and see Out-of-Memory for shm. You realize Kubernetes pods default to 64MB /dev/shm, but 500 connections require ~1.5GB shared memory. You modify the pod spec to mount an emptyDir volume with medium: Memory and sizeLimit: 2Gi to /dev/shm, allowing PostgreSQL to allocate the required segment. The pod starts successfully. You later realize you should have just used PgBouncer with a lower max\_connections to avoid the memory overhead per connection.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T01:58:31.347741+00:00— report_created — created