当前位置: 首页>>技术教程>>正文


如何修复 PostgreSQL 安装

, ,

问题描述

我最近从 Maverick 升级到 Natty,一切都很顺利,除了在 dist-upgrade 期间 PostgreSQL 出了点问题。从那以后,我尝试通过“sudo apt-get purge postgresql”重新安装、删除甚至清除它,但无论我做什么,它仍然会出现相同的错误。见下文。升级前它工作正常。任何帮助将不胜感激。谢谢!

Setting up postgresql-common (114) ...
 * Starting PostgreSQL 8.4 database server         * The PostgreSQL server failed to start. Please check the log output:
2011-05-19 11:49:41 EDT LOG:  could not bind IPv4 socket: Address already in use
2011-05-19 11:49:41 EDT HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2011-05-19 11:49:41 EDT WARNING:  could not create listen socket for "127.0.0.1"
2011-05-19 11:49:41 EDT FATAL:  could not create shared memory segment: Invalid argument
2011-05-19 11:49:41 EDT DETAIL:  Failed system call was shmget(key=5432001, size=37879808, 03600).
2011-05-19 11:49:41 EDT 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 37879808 bytes), reduce PostgreSQL's shared_buffers parameter (currently 4096) and/or its max_connections parameter (currently 103).
    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.

[fail]
invoke-rc.d: initscript postgresql, action "start" failed.
dpkg: error processing postgresql-common (--configure):
 subprocess installed post-installation script returned error exit status 1

最佳方法

您需要增加 Linux 内核允许一次分配的共享内存块的最大大小(称为 SHMMAX 参数)

您需要编辑 /etc/sysctl.conf 并添加以下行:

kernel.shmmax = 41943040

(其中 41943040 是以字节为单位的内存大小,即 40 兆字节。在生产系统上,您可能希望将此值设置得更高 – Postgres 文档建议从可用内存的 1/4 开始)

然后运行

sudo sysctl -p

并重新启动 postgres。

或者,您可以编辑 /etc/postgresql/<version>/main/postgresql.conf 并减小 shared_buffers 参数的值。

这是一个错误,更多信息在这里

https://bugs.launchpad.net/ubuntu/+source/linux/+bug/264336

(还有应该用于此目的的 /etc/sysctl.d/30-postgresql-shm.conf 文件,但它似乎并未包含在主配置中,因此对其进行编辑无效)

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/13523.html,未经允许,请勿转载。