重新启动MacBook Pro后,我无法启动数据库服务器:

could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

我检查了日志,下面的行出现了一遍又一遍:

FATAL:  database files are incompatible with server
DETAIL:  The data directory was initialized by PostgreSQL version 9.2, which is not compatible with this version 9.0.4.

9.0.4是mac上预装的版本。4]是我通过Homebrew安装的版本。

如前所述,这在重新启动之前是可以工作的,因此它实际上不可能是编译问题。我还重新运行了initdb /usr/local/var/postgres -E utf8,文件仍然存在。


当前回答

试试这个: https://gist.github.com/joho/3735740

这对我来说非常有效。 最后,它还生成2个bash脚本来检查数据库并删除旧的集群。 真的太棒了。

参见:http://www.postgresql.org/docs/9.2/static/pgupgrade.html了解更多。

其他回答

当在Docker中运行新的Postgres时,旧的卷没有更新,也会发生这种情况。

如果你不需要保存你的数据,最简单的方法是清除docker文件夹中的旧卷,在Linux中:

/var/lib/docker/volumes

一个过时的邮政局长。Pid文件导致了这一点。

简单地导航到你的postgres目录/Users/st/Library/Application Support/ postgres /,对我来说,就是:

cd '/Users/<username>/Library/Application Support/Postgres/var-10'

然后删除postmaster.pid文件。重新启动postgres,它将工作。

当我试图用postgres11挂载卷启动Postgres12时,就发生了这种情况。只要删除postgres11的挂载卷并重新启动就可以了。

之前我用的是:

docker run -d --name my_database -v /Users/champ/postgres:/var/lib/postgresql/data -p 54320:5432 postgres:11

我删除了/Users/champ/postgres并重新启动postgres 12,使用

docker run -d --name my_database -v /Users/champ/postgres:/var/lib/postgresql/data -p 54320:5432 postgres:12

正如@Gowtham提到的,您可以通过执行brew命令来解决这个问题

酿造postgresql-upgrade-database 上面的命令取自brew info postgres的输出

但是,不要忘记在执行postgres服务之前停止它,使用以下命令: ' brew服务停止postgresql

您可能需要重新启动服务。

所以命令的最终顺序是:

brew services stop postgresql
brew postgresql-upgrade-database
brew services start postgresql  

在网上找到的,这个解决方案对我来说很好。

当我试图在升级到OS X 10.10 Yosemite后启动postgresql服务器时,我遇到了下一个问题:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

好的,让我们来看看服务器日志:

cat /usr/local/var/postgres/server.log

FATAL: database files are incompatible with server
DETAIL: The data directory was initialized by PostgreSQL version 9.2, which is not compatible with this version 9.3.5.

所以,在升级postgresql后,我们需要遵循以下几个步骤:

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

mv /usr/local/var/postgres /usr/local/var/postgres92

brew update

brew upgrade postgresql

initdb /usr/local/var/postgres -E utf8

pg_upgrade -b /usr/local/Cellar/postgresql/9.2.3/bin -B /usr/local/Cellar/postgresql/9.3.5_1/bin -d /usr/local/var/postgres92 -D /usr/local/var/postgres

cp /usr/local/Cellar/postgresql/9.3.5_1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

rm -rf /usr/local/var/postgres92

就是这样。