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


当前回答

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

我补充说:

127.0.0.1 localhost

这解决了我的问题。

其他回答

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

命令:sudo service postgresql restart。

导致此错误的原因有很多,因此首先定位您的日志文件并检查其线索。它可能在/usr/local/var/log/ postgress .log或/usr/local/var/ postgress /server.log或其他地方。如果你安装了Homebrew,你可以在~/Library/LaunchAgents/ Homebrew .mx .postgresql.plist找到这个位置。

我在这里遇到了类似的问题,我解决了这个问题,如下所示。

实际上postgres进程已经死亡,要查看postgres的状态,请运行以下命令

sudo /etc/init.d/postgres status

它会说进程已死,只要启动进程

sudo /etc/init.d/postgres start

也许这是不相关的,但类似的错误出现当你升级postgres到一个主要版本使用brew;使用brew info postgresql发现这有助于:

To migrate existing data from a previous major version of PostgreSQL run:
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