If your new postgresql settings are causing your postgres server to not start with this error, it helpfully reminds you that it’s probably due to the kernel’s SHMMAX parameter being too low.
* Restarting PostgreSQL 8.4 database server
* The PostgreSQL server failed to start. Please check the log output:
2011-11-04 05:06:26 UTC FATAL: could not create shared memory segment: Invalid
2011-11-04 05:06:26 UTC DETAIL: Failed system call was shmget(key=5432001, size
2011-11-04 05:06:26 UTC HINT: This error usually means that PostgreSQL’s reques
t for a shared memory segment exceeded your kernel’s SHMMAX parameter. You can
either reduce the request size or reconfigure the kernel with larger SHMMAX. To
reduce the request size (currently 161849344 bytes), reduce PostgreSQL’s shared
_buffers parameter (currently 19200) and/or its max_connections parameter (curre
If the request size is already small, it’s possible that it is less than
your kernel’s SHMMIN parameter, in which case raising the request size or recon
figuring SHMMIN is called for.
The PostgreSQL documentation contains more information about shared memo
On my ubuntu system, the shmmax was 32 mb or something like that.
Check your systems shmmax
$> sudo cat /proc/sys/kernel/shmmax/ 33554432
Set a new shmmax value
As usual, I blog about this stuff when it breaks, so when I saw this, I just searched yuji shmmax.
$> sysctl -w kernel.shmmax=BYTES
Make shmmax persist across a reboot
The setting clearly didn’t persist when I last rebooted a few minutes ago and caused my postgres to fail.
$> sudo vim /etc/sysctl.conf # add kernel.shmmax = bytes kernel.shmmax = 134217728