PostgreSQL 无法启动,因为它“无法分配内存”

dwl*_*wlz 5 postgresql linux kernel linux-kernel

我在 Ubuntu 10.04 上运行 PostgreSQL 8.4.5。我运行了一个 EC2 实例,其中有几个站点在 nginx 上运行。大多数这些站点在 Django 上运行并连接到这个 Postgres 实例。

出于某种原因,今晚 8 点 45 分,Postgres 宕机了。我登录到机器,我看到这个错误信息:

 * Starting PostgreSQL 8.4 database server
 * The PostgreSQL server failed to start. Please check the log output:
2011-04-17 04:46:49 UTC FATAL:  could not create shared memory segment: Cannot allocate memory
2011-04-17 04:46:49 UTC DETAIL:  Failed system call was shmget(key=5432001, size=16211968, 03600).
2011-04-17 04:46:49 UTC HINT:  This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space. To reduce the request size (currently 16211968 bytes), reduce PostgreSQL's shared_buffers parameter (currently 1792) and/or its max_connections parameter (currently 53).
        The PostgreSQL documentation contains more information about shared memory configuration.
   ...fail!
Run Code Online (Sandbox Code Playgroud)

我做的第一件事是更改 Linux 共享内存分配。

sysctl -w kernel.shmmax=367108864>
sysctl -p /etc/sysctl.conf
Run Code Online (Sandbox Code Playgroud)

那没有做到。然后我编辑/etc/postgresql/8.4/main/postgresql.conf并降低了max_connections值。这工作......大约10分钟。

现在我得到了同样的错误,不管有多低max_connections。我需要将它设置为至少 9(因为这是需要访问此 Postgres 服务器的 Django 项目的数量)。

关于我如何解决这个问题的任何想法?

jan*_*neb 4

您可以使用“ipcs”命令列出所有 SHM 段。如果程序崩溃而没有删除它们,则它们可能正在消耗内存;您可以使用“ipcrm”命令手动删除它们。