重新启动我的Mac,我得到了可怕的Postgres错误:

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

发生这种情况的原因是由于一个无关的问题,我的macbook完全死机了,我不得不使用电源按钮进行硬重启。重启后,由于这个错误,我无法启动Postgres。


当前回答

我也遇到了同样的问题,这是由于从版本11升级到13.2后版本不兼容

检查错误日志:

/usr/local/var/log/postgres.log

给我:

DETAIL:  The data directory was initialized by PostgreSQL version 11, which is not compatible with this version 13.2.

为了解决这个问题,我跑了:

brew postgresql-upgrade-database

然后用brew启动postresql:

brew services start postgresql

其他回答

我也遇到了同样的问题,这是由于从版本11升级到13.2后版本不兼容

检查错误日志:

/usr/local/var/log/postgres.log

给我:

DETAIL:  The data directory was initialized by PostgreSQL version 11, which is not compatible with this version 13.2.

为了解决这个问题,我跑了:

brew postgresql-upgrade-database

然后用brew启动postresql:

brew services start postgresql

我的问题是,我使用的是Gas Mask (Mac主机文件管理器),在我使用的hosts文件中没有localhost的条目。

我补充说:

127.0.0.1 localhost

这解决了我的问题。

如果你在macOS上,并通过homebrew安装了postgres,请尝试重新启动

brew services restart postgresql

如果你使用的是Ubuntu,你可以用这两个命令中的任意一个重新启动它

sudo service postgresql restart

sudo /etc/init.d/postgresql restart

@Jagdish Barabari的回答给了我解决这个问题的线索。结果是安装了两个版本的postgresql,而只有一个在运行。清除所有postgresql文件并重新安装最新版本为我解决了这个问题。

进入/var/log/目录 运行cat postgres.log 在这里你会发现postgres失败的原因。 如果它是一个智能关闭,那么可能你的icu4c版本(Unicode的c++库)是不正确的,它与postgres链接。所以执行以下命令。

酿造升级 啤酒清理 这应该可以工作;)