我试图在我的 Vagrant 机器上运行 psql
,但是我得到这个错误:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting connections on
Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
注意:Vagrant 1.9.2 盒子:ubuntu/trusty64,https://atlas.hashicorp.com/ubuntu/boxes/trusty64
编辑 我用来安装和运行 postgres 的命令:
sudo apt-get update
sudo apt-get install postgresql
sudo su postgres
psql -d postgres -U postgres
最佳答案
我遇到过同样的问题,与我的 pg_hba.conf 文件(位于 /etc/postgresql/9.6/main
中)的配置有关。请注意,9.6 是我使用的 postgresql 版本。
错误本身与postgresql配置错误有关,导致服务器在启动前崩溃。
我建议遵循这些说明:
- 使用
sudo service postgresql start
证明 postgresql 服务正在运行 - 运行
pg_lsclusters
从您的终端 检查你正在运行的集群是什么,输出应该是这样的:
版本 - 集群端口状态所有者数据目录
9.6 -------- main -- 5432 在线 postgres/var/lib/postgresql/9.6/main
Disregard the '---' signs, as they are being used there only for alignment. The important information are the version and the cluster. You can also check whether the server is running or not in the status column.
- 从版本和集群中复制信息,然后像这样使用:
pg_ctlcluster <version> <cluster> start
,所以在我的例子中,使用版本 9.6 和集群“main”,它将是pg_ctlcluster 9.6 main start
- 如果出现问题,postgresql 将生成一个日志,可以在
/var/log/postgresql/postgresql-<version>-main.log
上访问该日志,所以在我的例子中,完整的命令是sudo nano /var/log/postgresql/postgresql-9.6-main.log
. - 输出应该显示错误是什么。
2017-07-13 16:53:04 BRT [32176-1] LOG: invalid authentication method "all"
2017-07-13 16:53:04 BRT [32176-2] CONTEXT: line 90 of configuration file "/etc/postgresql/9.5/main/pg_hba.conf"
2017-07-13 16:53:04 BRT [32176-3] FATAL: could not load pg_hba.conf - 通过
sudo service postgresql restart
修复错误并重启postgresql服务应该没问题。
我搜索了很多才找到这个,归功于这个 post .
祝你好运!
关于postgresql - Psql 无法连接到服务器 : No such file or directory, 5432 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42653690/