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

11,922

Solution 1

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

Solution 2

From the PostgreSQL documentation,

The most important shared memory parameter is SHMMAX, the maximum size, in bytes, of a shared memory segment. If you get an error message from shmget like "Invalid argument", it is likely that this limit has been exceeded. [...] While it is possible to get PostgreSQL to run with SHMMAX as small as 2 MB, you need considerably more for acceptable performance. Desirable settings are in the hundreds of megabytes to a few gigabytes.

Further down the page are example of how to make the changes on Linux. To allow 8 GB:

$ sysctl -w kernel.shmmax=8589934592
$ sysctl -w kernel.shmall=2097152

If that works, you cam make the settings take effect at the next boot by editing /etc/sysctl.conf.

The value you select would depend on what else you are using the machine for. If it's a dedicated PostgreSQL server, go ahead and allow most of the memory of the machine to be used for shared memory by PostgreSQL. If you intend to run other stuff as well on the same machine, then you may want to be more conservative.

Share:
11,922

Related videos on Youtube

Nyxynyx
Author by

Nyxynyx

Hello :) These days its web development: PHP, Codeigniter, node.js, Javascript, jQuery, MySQL, mongoDB, HTML/CSS

Updated on September 18, 2022

Comments

  • Nyxynyx
    Nyxynyx over 1 year

    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