postgresql - Psql 无法连接到服务器 : No such file or directory, 5432 错误?

标签 postgresql vagrant

我试图在我的 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配置错误有关,导致服务器在启动前崩溃。

我建议遵循这些说明:

  1. 使用 sudo service postgresql start 证明 postgresql 服务正在运行
  2. 运行 pg_lsclusters从您的终端
  3. 检查你正在运行的集群是什么,输出应该是这样的:

    版本 - 集群端口状态所有者数据目录

    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.

  4. 从版本和集群中复制信息,然后像这样使用: pg_ctlcluster <version> <cluster> start ,所以在我的例子中,使用版本 9.6 和集群“main”,它将是 pg_ctlcluster 9.6 main start
  5. 如果出现问题,postgresql 将生成一个日志,可以在 /var/log/postgresql/postgresql-<version>-main.log 上访问该日志,所以在我的例子中,完整的命令是 sudo nano /var/log/postgresql/postgresql-9.6-main.log .
  6. 输出应该显示错误是什么。

    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

  7. 通过sudo service postgresql restart修复错误并重启postgresql服务应该没问题。

我搜索了很多才找到这个,归功于这个 post .

祝你好运!

关于postgresql - Psql 无法连接到服务器 : No such file or directory, 5432 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42653690/

相关文章:

postgresql - 在 Amazon EC2 上安装和使用 PostgreSQL 9.3

linux - 如何升级 pg_dumpall

vagrant - 无法获得干净的 Vagrant Box "Remove"或 "Destroy"

vagrant - 在 Travis-CI 中启动 Vagrant VM

vagrant - 无法在 Vagrant 中同步主目录

ubuntu - 从用户 shell 执行命令的 Ansible 剧本

postgresql - 如何使用 PostgreSql 在代码优先方法中自动创建表

PostgreSQL 从日期字段 PSQL 中减去一年

ruby-on-rails - Rails 4 - 如何在开发中使用 sqlite3 并在生产中使用 PostgreSQL w/Heroku

ruby - `block in activate_dependencies' : 可以 't satisfy ' windows-pr (= 1.2.1) ', already activated ' windows-pr-1.2.2' (Gem::LoadError)