psql: could not connect to server: No such file or directory

有时候在主机上使用psql登录postgresql时,会报如下错误
$ 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)postgresql 没有启动,可以通过 ps -ef|grep -i postgres 确认
2)postgresql 根据 postgresql.conf 中的参数 unix_socket_directory 生成文件不在/tmp下

对应解决办法
1)启动postgresql
2)使用psql时指定 unix_socket_directory , 如下:

$ psql -h /var/run/postgresql/
psql (9.1.22)
Type "help" for help.

postgres=#
posted @ 2018-03-07 13:40  peiybpeiyb  阅读(716)  评论(0编辑  收藏  举报