Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting SHMMAX etc values on MAC OS X 10.6 for PostgreSQL

I'm trying to startup my PostgreSQL server on my local machine. But I got an error message saying:

FATAL:  could not create shared memory segment: Invalid argument
DETAIL:  Failed system call was shmget(key=5432001, size=9781248, 03600).
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 9781248 bytes), reduce PostgreSQL's shared_buffers parameter (currently 1024) and/or its max_connections parameter (currently 13).
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.  

I search and looked at the docs but everything I tries about setting the kern.sysv.shmmax and kern.sysv.shmall is working. What are the right settings on Snow Leopard? I installed postgres with macports.

like image 472
primeminister Avatar asked Jan 06 '10 23:01

primeminister


2 Answers

You have to increase the kernel's maximum shared memory allowance to something higher than what Postgres is trying to allocate. (You could also decrease the shared buffers or maximum connections settings in postgresql.conf to make Postgres ask for less memory, but the default values are already rather small for most use cases.)

To do this as a one-off, lasting until next reboot:

sudo sysctl -w kern.sysv.shmmax=12582912
sudo sysctl -w kern.sysv.shmall=12582912

Change the exact number as appropriate for your Postgres settings; it has to be larger than whatever Postgres says it's asking for in the log file. After doing both of these, you should be able to start Postgres.

To make the change persist across reboots, edit /etc/sysctl.conf and set the same values there.

like image 114
Paul Legato Avatar answered Nov 19 '22 18:11

Paul Legato


Apple documents how to adjust them for Snow Leopard here:

http://support.apple.com/kb/HT4022: Mac OS X Server v10.6: Adjusting Shared memory segment values

sysctl does allow you to change them temporarily.

like image 8
Christophe Avatar answered Nov 19 '22 20:11

Christophe