Postgresql服务器在本地计算机上运行但psql无法连接

时间:2017-06-20 20:51:37

标签: postgresql

执行brew install postgres后:

brew install postgres
brew link --overwrite postgresql

Postgres已经在运行:

/~ $brew services start postgresql
Service `postgresql` already started, use `brew services restart postgresql` to restart.

但是我们如何使用psql客户端进行连接?

13:47:28/~ $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"?

更新尝试了各种建议。

尝试重新启动..

 $brew services start postgresql
Service `postgresql` already started, use `brew services restart postgresql` to restart.
14:37:19/fastparquet $brew services restart postgresql
Stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)

14:37:39/fastparquet $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"?
14:37:55/fastparquet $

连接到localhost?

14:37:34/fastparquet $psql -h localhost
psql: could not connect to server: Connection refused
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?

1 个答案:

答案 0 :(得分:3)

来自a_horse_with_no_name的链接可以解决问题。具体来说:

initdb -D /usr/local/var/postgres/

(来自Homebrew postgres broken

然后

 createdb 

(后者来自psql: FATAL: database "<user>" does not exist