在 MAC OS X 10.6 for PostgreSQL 上设置 SHMMAX 等值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2017004/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 23:58:06  来源:igfitidea点击:

Setting SHMMAX etc values on MAC OS X 10.6 for PostgreSQL

postgresqlconfigurationmacos

提问by primeminister

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

我正在尝试在我的本地机器上启动我的 PostgreSQL 服务器。但是我收到一条错误消息说:

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.

我搜索并查看了文档,但我尝试设置 kern.sysv.shmmax 和 kern.sysv.shmall 的一切都在工作。Snow Leopard 的正确设置是什么?我用 macports 安装了 postgres。

采纳答案by alvherre

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

警告:此答案已被较新版本的 OS X 废弃。请参考下方 Paul Legato 的答案。

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

在 Mac OS X 中,您无法在系统启动后更改 shmmax。您需要编辑 /etc/rc 或 /etc/sysctl.conf,并记住它需要是 4096 的倍数。请参阅此处 http://www.postgresql.org/docs/8.4/static/kernel-资源.html

回答by Paul Legato

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.)

您必须将内核的最大共享内存限额增加到高于 Postgres 尝试分配的限额。(您还可以减少 postgresql.conf 中的共享缓冲区或最大连接数设置,以使 Postgres 要求更少的内存,但对于大多数用例而言,默认值已经相当小了。)

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.

根据您的 Postgres 设置更改确切的数字;它必须大于 Postgres 在日志文件中要求的任何内容。完成这两项操作后,您应该可以启动 Postgres。

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

要使更改在重新启动后保持不变,请编辑 /etc/sysctl.conf 并在其中设置相同的值。

回答by Christophe

Apple documents how to adjust them for Snow Leopard here:

Apple 在此处记录了如何为 Snow Leopard 调整它们:

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

http://support.apple.com/kb/HT4022:MacOS X Server v10.6:调整共享内存段值

sysctl does allow you to change them temporarily.

sysctl 确实允许您临时更改它们。

回答by oliverseal

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

我知道这是一个老问题,但我认为可能值得注意的是,如果您只是将 PostgreSQL 用于开发目的,您可以安全地进入 postgres.conf(完成 initdb 后的数据目录)和将shared_buffers变量更改为稍低一些。它默认为 28MB 或其他大小。但是这样你就不会弄乱系统共享内存变量。