Linux – PostgreSQL server failed to start: request for a shared memory segment exceeded your kernel’s SHMMAX parameter

linuxpostgresqlshmmaxUbuntuubuntu-12.04

I increased PostgreSQL's shared buffer (among other settings) to 4096M and now PostgreSQL fails to start, giving the error message below.

Should I change the kernel's SHMMAX parameter to 4096M? The system has 16GB of RAM. How should this be done? What should I change SHMALL to? I want the changes to be permanent and persists after reboots.

* Starting PostgreSQL 9.1 database server                                       
* The PostgreSQL server failed to start. Please check the log output:

2013-04-15 06:15:53 UTC FATAL: could not create shared memory segment: Invalid argument
2013-04-15 06:15:53 UTC DETAIL: Failed system call was shmget(key=5432001, size=4418322432, 03600).
2013-04-15 06:15:53 UTC HINT: This error usually means that PostgreSQL's request 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 4418322432 bytes), reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.
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 reconfiguring SHMMIN is called for.
The PostgreSQL documentation contains more information about shared memory configuration.

free

             total       used       free     shared    buffers     cached
Mem:      24744200    1244936   23499264          0      77480     670240
-/+ buffers/cache:     497216   24246984
Swap:     16775160          0   16775160

Best Answer

Looks to me like you edited yout shared_buffers in your config from the default. And you have a lot of memory so you are probably trying to up that more then the kernel is letting you.

So create a file like

/etc/sysctl.d/10-postgresql-shm.conf

Then have the following in it

kernel.shmmax = 4414768

Replace the number with what you want to put there.. Then to set it run the following

sudo sysctl -p

Then try to start postgresql

Related Topic