2017-03-07 57 views
11

我想我流浪的机器上运行psql,但我得到这个错误:Psql无法连接到服务器:没有这样的文件或目录,5432错误?

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

编辑 命令我为了安装使用和运行的Postgres:

  • sudo apt-get update
  • sudo apt-get install postgresql
  • sudo su postgres
  • psql -d postgres -U postgres
+0

您是否修正了此错误? –

回答

26

我有这个相同的问题,与我的pg_hba.conf文件(位于/etc/postgresql/9.6/main)的配置有关。请注意9.6是我正在使用的postgresql版本。

错误本身与postgresql的错误配置有关,这会导致服务器在启动之前崩溃。

我建议按照以下说明:

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

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

    9.6 -------主 - 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 on the status column.

  4. 中的复制版本和集群的信息,并使用像这样: pg_ctlcluster <version> <cluster> start ,所以在我的情况下,使用版本9.6和集群'主',这将是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

祝你好运!

2

是否/etc/postgresql/9.6/main/postgresql.conf显示,被分配的端口?在我的默认Xubuntu Linux安装中,由于某种原因,我的记录显示port = 5433,但我确实在同一个文件中注释了该行,说listen_addresses = 'localhost'并取消注释行listen_addresses = '*'。所以也许开始并在那里检查。希望有所帮助。

0

打开数据库管理器和执行该脚本

update pg_database set datallowconn = 'true' where datname = 'your_database_name'; 
0

我有同样的错误,当我创建一个虚拟机中的SQL数据库。我已将/etc/postgresql/9.3/main/postgresql.conf shared_buffers = 200MB的默认值更改为我总RAM的75%。那么,我忘了在虚拟机中实际分配这个RAM。当我发出命令创建新数据库时,我收到了同样的错误。

断开电源,给了宝宝它的瓶子(RAM),然后它就起作用了。

0

同样的事情发生在我身上,因为我改变了/etc/hosts文件中的内容。将它改回127.0.0.1 localhost它对我有用。

相关问题