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


当前回答

如果你是邮政局长。Pid已经消失,你不能重新启动或做任何事情,这样做:

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

正如这里最初解释的那样

其他回答

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

我补充说:

127.0.0.1 localhost

这解决了我的问题。

导致这种情况发生的另一类原因是由于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

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

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

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

命令:sudo service postgresql restart。

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