我知道有人问过这个或类似的问题 在其他地方过。其他答案都没有对我有用。
机器是 Macbook Pro 2014 / OS X Yosemite 10.10,通过 Homebrew 安装了 Postgres 9.3.5。
如果我没有指定主机,我只能连接到我的本地 postgres 实例。这有效:
psql -Umyuser -d mydb
sql (9.4.4)
Type "help" for help.
myuser=#
Run Code Online (Sandbox Code Playgroud)
-h localhost 才不是:
psql -Umyuser -d mydb -h localhost
psql: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
Run Code Online (Sandbox Code Playgroud)
在我收到这条消息之前,它暂停了很长时间。
我正在尝试设置一个似乎想要指定 localhost 的第三方工具,因此不能仅将其关闭。
如果我理解我在其他地方正确阅读的内容,那么如果您使用 TCP/IP 并指定-h localhost强制使用,则 postgres 的行为会有所不同。因此,我在 中添加了以下内容pg_hba.conf:
local all …Run Code Online (Sandbox Code Playgroud)