我正在我的Mac(High Sierra,10.13.3(上运行Homebrew Installed Postgres版本9.6.3,今天早上,我发现Postgres遇到了一些问题。昨晚的工作正常,然后我让电脑入睡...今天早上我醒来并试图运行凤凰应用程序时,我得到了
[error] Postgrex.Protocol (#PID<0.306.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
运行psql
返回
psql: 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"?
因此,似乎服务器已经停止了...但是,运行我的别名pg-start
,它转化为launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
返回
/usr/local/Cellar/postgresql/9.6.3/homebrew.mxcl.postgresql.plist: service already loaded
所以这令人困惑,因为似乎一个命令表明Postgres没有运行,而另一个命令则表明它是。
我不能肯定地记得,但是我可能已经停止了服务器,然后才能将计算机昨晚入睡,实际上我通常不这样做...我的pg-stop
别名是launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
虽然我看不出为什么会引起问题,但这是我唯一想做的事情,这是我可能做过的"不同"的事情。
我尝试重新启动我的机器,但是问题仍然存在。我在调试此类问题方面并不经验丰富,因此,任何指导或建议都将不胜感激。
好吧,我解决了它,尽管我不确定确切的问题是什么。要获取更多错误信息,我运行
postgres -D /usr/local/var/postgres
给了我
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 323) running in data directory "/usr/local/var/postgres"?
我以前遇到过的,所以我有点知道如何进行...
这是我解决此问题的步骤:
首先,我跑了
pg_ctl -D /usr/local/var/postgres start
返回的
pg_ctl: another server might be running; trying to start server anyway
server starting
My-MBP:~ me$ FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 1188) running in data directory "/usr/local/var/postgres"?
然后我运行了我的别名pg-stop
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
接着
pg_ctl -D /usr/local/var/postgres start
再次。这次,它返回
server starting
My-MBP:~ me$ LOG: database system was shut down at 2018-02-07 11:10:43 EST
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
现在Postgres运行正确 - psql
命令等
但是,现在我的别名pg-stop
无法正常工作 -
/Users/me/Library/LaunchAgents/homebrew.mxcl.postgresql.plist: Could not find specified service
我运行
pg_ctl -D /usr/local/var/postgres stop
,然后我的pg-stop
别名恢复了。因此,现在pg-start
和pg-stop
正常工作。
我希望这对将来的人有帮助,但是如果有人能解释这里发生的事情,我真的很感谢对出了什么问题有更深入的了解。