PostgreSQL服务器启动失败:对共享内存段的请求超出了内核的SHMMAX参数

我将PostgreSQL的共享缓冲区(其他设置)增加到4096M,现在PostgreSQL无法启动,下面给出了错误消息。

我应该将内核的SHMMAX参数更改为4096M吗? 该系统有16GB的RAM。 这应该怎么做? 我应该把SHMALL改成什么? 我希望更改是永久性的,并在重新启动后保持不变。

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

自由

  total used free shared buffers cached Mem: 24744200 1244936 23499264 0 77480 670240 -/+ buffers/cache: 497216 24246984 Swap: 16775160 0 16775160 

在我看来,就像你在你的configuration中编辑你默认的shared_buffers 。 而且你有很多的内存,所以你可能试图提高内核让你。

所以创build一个像

 /etc/sysctl.d/10-postgresql-shm.conf 

然后在其中有以下内容

 kernel.shmmax = 4414768 

用你想放在那里的号码代替。然后设置它运行以下

 sudo sysctl -p 

然后尝试启动postgresql

从PostgreSQL文档中 ,

最重要的共享内存参数是SHMMAX ,即共享内存段的最大大小(以字节为单位)。 如果从“无效参数”中得到shmget的错误信息,可能是超过了这个限制。 尽pipe可以使PostgreSQL以小于2MB的SHMMAX运行,但为了可接受的性能,您还需要更多。 理想的设置是从几百兆到几千兆。

在页面的下面是如何在Linux上进行更改的示例。 允许8 GB:

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

如果这样,你可以通过编辑/etc/sysctl.conf让设置在下一次启动时生效。

您select的值取决于您使用机器的其他function。 如果它是一个专用的PostgreSQL服务器,请继续,让PostgreSQL的机器的大部分内存用于共享内存。 如果你打算在同一台机器上运行其他的东西,那么你可能要更保守。