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

Postgresql server is running on local machine but psql can not connect

做完brew install postgres之后:

1
2
brew install postgres
brew link --overwrite postgresql

Postgres已经在运行:

1
2
/~ $brew services START postgresql
Service `postgresql` already started, USE `brew services restart postgresql` TO restart.

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

1
2
3
4
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"?

更新尝试了各种建议。

尝试重新启动..

1
2
3
4
5
6
7
8
9
10
11
12
 $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?

1
2
3
4
5
6
7
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?


来自a_horse_with_no_name的链接起了作用。 特别:

1
initdb -D /usr/LOCAL/var/postgres/

(来自Homebrew postgres破碎)

然后

1
 createdb

(后者来自psql:FATAL:数据库""不存在)