重新启动我的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。


当前回答

这个答案对我有用:在我的ubuntu系统上是https://stackoverflow.com/a/45454567/15067545。

命令:sudo service postgresql restart。

其他回答

我刚刚得到了相同的问题,因为我已经把我的机器(ubuntu)更新,并得到以下错误:

无法连接到服务器:没有这样的文件或目录是服务器吗 在Unix域套接字上本地运行并接受连接 “/ var /运行/ postgresql / .s.PGSQL.5432”?

完成更新过程后,当我重新启动系统时,我的错误消失了。它的工作就像以前一样迷人。我猜这是在pg更新和另一个进程启动时发生的。

为了解决这个问题,我不得不多次查阅这篇文章。还有另一个修复程序,它也适用于其他正在运行的程序的类似问题。

我刚刚发现您可以使用以下两个命令。

美元上

这将显示当前运行的所有操作及其pid编号。当你找到postgres和相关的pid

杀死pid_number美元

我也遇到了同样的问题,这是由于从版本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

导致这种情况发生的另一类原因是由于Postgres的版本更新。

你可以通过查看postgres日志来确认这是一个问题:

tail -n 10000 /usr/local/var/log/postgres.log

看到这样的条目:

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

在这种情况下(假设你在Mac上使用brew),只需运行:

brew postgresql-upgrade-database

(奇怪的是,它在第一次运行时失败了,在第二次运行时工作了,所以在放弃之前尝试两次)

这是我的方法:

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
rm /usr/local/var/postgres/postmaster.pid
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist