3
 Failed system call was shmget(key=5432001, size=16498688, 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 16498688 bytes), reduce PostgreSQL's shared_buffers parameter (currently 1536) and/or its max_connections parameter (currently 104).
    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.
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
Subba Rao
  • 10,576
  • 7
  • 29
  • 31

4 Answers4

9

You can set the memory for the current session using the commands:

sudo sysctl -w kern.sysv.shmmax=16777216
sudo sysctl -w kern.sysv.shmall=4096

Which will allow Postgres to start.

To get that to stick across restarts you need to create or edit the file /etc/sysctl.conf to include:

kern.sysv.shmmax=16777216
kern.sysv.shmall=4096
Shaun McDonald
  • 6,436
  • 2
  • 25
  • 23
4

Editing /etc/sysctl.conf and restarting did the trick for me:

kern.sysv.shmmax=1610612736
kern.sysv.shmmin=1
kern.sysv.shmmni=256
kern.sysv.shmseg=64
kern.sysv.shmall=393216

Oddly enough, the PostgreSQL installer already complained about wrong shared memory settings and proposed to change sysctl.conf. But apparently, the values for shmmax and shmall were still too small.

Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
2

As Ortwin mentions, you need to edit the /etc/sysctl.conf file. This file doesn't actually exist on a clean Mac OS/X Lion install, you'll need to create it. The parameters listed above are reasonable for a large machine - this allocates up to 1.5gb for shared memory. If you've only got 2gb, you might want to use less than that.

On my mac, I allocate 256MB to shared memory, with the following line:

kern.sysv.shmmax=268435456

Two links that I found helpful when researching this are the following:

http://www.spy-hill.net/help/apple/SharedMemory.html - discusses shared memory on Darwin

and

http://archives.postgresql.org/pgsql-patches/2006-02/msg00176.php

gives some history of this problem with regard to postgresql.

Pete Clark
  • 584
  • 4
  • 8
1

This has to do with the Shared Memory parameter (shared_buffers) in the PostgreSQL configuration file. Linux also has settings in place to limit the amount of memory an application can request. These settings are stored in three files :-

/proc/sys/kernel/shmall

/proc/sys/kernel/shmmax

/proc/sys/kernel/shmmni

One or more of these files need to be amended or by using the "sysctl" executable. Ask your system administrator to do this. The error message tells you what the values should be. PostgreSQL should then be able to startup properly.

If you are unable to change the values, reduce the shared_buffers parameter to a point where it is below the threshold

Imraan
  • 657
  • 1
  • 5
  • 10