Tutorial :Setting SHMMAX etc values on MAC OS X 10.6 for PostgreSQL



Question:

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.


Solution:1

Warning: this answer has been made obselete by newer versions of OS X. Please reference Paul Legato's answer below.

In Mac OS X you cannot change shmmax after the system has booted. You need to edit /etc/rc or /etc/sysctl.conf, and keep in mind that it needs to be a multiple of 4096. See here http://www.postgresql.org/docs/8.4/static/kernel-resources.html


Solution:2

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.


Solution:3

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.


Solution:4

I know this is an old question, but I think it might be worth noting that if you're just using PostgreSQL for development purposes you might be safe to just go into postgres.conf (the data directory after you've done initdb) and change the shared_buffers variable to something a little lower. It defaults to 28MB or something. But this way you're not messing around with system shared memory variables.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »