Psql无法连接到服务器:没有这样的文件或目录,5432错误? [英] Psql could not connect to server: No such file or directory, 5432 error?
问题描述
我正在尝试在我的Vagrant计算机上运行 psql
,但是出现此错误:
I'm trying to run psql
on my Vagrant machine, but I get this error:
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"?
注意:无业游民1.9.2
框:ubuntu / trusty64, https://atlas.hashicorp.com/ubuntu/boxes/trusty64
Note: Vagrant 1.9.2 Box: ubuntu/trusty64, https://atlas.hashicorp.com/ubuntu/boxes/trusty64
编辑
我用来安装和运行postgres的命令:
EDIT Commands I've used in order to install and run postgres:
-
sudo apt-get update
-
sudo apt-get install postgresql
-
sudo su postgres
-
psql -d postgres- U 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
中)。请注意,我使用的是PostgreSQL版本9.6。
I've had this same issue, related to the configuration of my pg_hba.conf file (located in /etc/postgresql/9.6/main
). Please note that 9.6 is the postgresql version I am using.
错误本身与postgresql的配置错误有关,这会导致服务器在启动之前崩溃。
The error itself is related to a misconfiguration of postgresql, which causes the server to crash before it starts.
我建议遵循以下说明:
- 使用以下命令验证Postgresql服务正在运行
sudo服务postgresql启动
- 从终端运行
pg_lsclusters
-
检查您正在运行的群集是什么,输出应该类似于:
- Certify that postgresql service is running, using
sudo service postgresql start
- Run
pg_lsclusters
from your terminal Check what is the cluster you are running, the output should be something like:
版本-群集端口状态所有者数据目录
Version - Cluster Port Status Owner Data directory
9.6 ------- main-5432在线postgres /var/lib/postgresql/9.6/main
9.6 ------- main -- 5432 online 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> <群集>开始
,所以在我的情况下,使用版本9.6和群集 main,它将是 pg_ctlcluster 9.6 main start
/var/log/postgresql/postgresql-<version>-main.log
,因此在我的情况下,完整的命令将是 sudo nano /var/log/postgresql/postgresql-9.6-main.log
。pg_ctlcluster <version> <cluster> start
, so in my case, using version 9.6 and cluster 'main', it would be pg_ctlcluster 9.6 main start
/var/log/postgresql/postgresql-<version>-main.log
, so in my case, the full command would be sudo nano /var/log/postgresql/postgresql-9.6-main.log
.
2017-07-13 16:53:04 BRT [32176-1]日志:无效的身份验证方法全部
2017-07-13 16:53:04 BRT [32176-2] 上下文:配置文件 /etc/postgresql/9.5/main/pg_hba.conf的第90行
2017-07-13 16:53:04 BRT [32176-3]致命:无法加载pg_hba.conf
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服务postgresql重新启动
重新启动postgresql服务,应该没问题。
sudo service postgresql restart
and it should be fine.我已经进行了很多搜索,找到了这个,这归功于发布。
I have searched a lot to find this, credit goes to this post.
祝您好运!
这篇关于Psql无法连接到服务器:没有这样的文件或目录,5432错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!