postgresql failing with below error on lion os x

余生长醉 提交于 2019-12-30 11:27:06

问题


 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.

回答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




回答2:


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



回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/6861945/postgresql-failing-with-below-error-on-lion-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!