Report #90748
[bug\_fix] FATAL: could not create shared memory segment: Cannot allocate memory during PostgreSQL startup
Increase the kernel parameter kernel.shmmax to a value larger than PostgreSQL's shared memory request \(typically shared\_buffers \+ max\_connections \* work\_mem \+ autovacuum\_max\_workers \* autovacuum\_work\_mem\), or reduce PostgreSQL's shared\_buffers/max\_connections. Root cause: PostgreSQL allocates a large contiguous shared memory segment at startup; the Linux kernel enforces a maximum size per segment via shmmax, and if PostgreSQL's configuration exceeds this, startup fails.
Journey Context:
You edited postgresql.conf to increase max\_connections from 100 to 1000 for a new microservice deployment and restarted the database. It fails to start, logging 'FATAL: could not create shared memory segment: Cannot allocate memory' followed by 'Failed system call was shmget'. You check the current kernel limits with sysctl kernel.shmmax and see 33554432 \(32 MB\), a default common in older containerized environments. You calculate that your new configuration requests roughly 1000 connections \* 4MB work\_mem = 4GB plus shared\_buffers of 2GB, far exceeding 32MB. You realize that PostgreSQL attempts to allocate a single large shared memory segment whose size is determined by shared\_buffers and various connection-related buffers. You edit /etc/sysctl.conf to set kernel.shmmax = 17179869184 \(16GB\), run sysctl -p to apply, and restart PostgreSQL successfully. You document that scaling max\_connections requires kernel-level shared memory tuning, not just changing the config file.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T10:54:58.712208+00:00— report_created — created