【问题标题】:PostgreSQL error: could not connect to database template1: could not connect to server: No such file or directoryPostgreSQL错误:无法连接到数据库模板1:无法连接到服务器:没有这样的文件或目录
【发布时间】:2015-07-17 16:48:12
【问题描述】:

我需要创建数据库。

首先我运行:sudo su - postgres,然后:createdb test

我不断收到此错误:

createdb: could not connect to database template1: 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"

这出乎意料,我从来没有遇到过psql的任何问题,但是这次我没有得到什么问题。而且没有外接服务器,我是本地连接的。

我在 Ubuntu 上运行。

【问题讨论】:

  • 您最近升级了吗? postgresql 是否正在运行(ps -ef | grep "post")?
  • 你好@Patrick 今天是全新安装,ps -ef | grep "post" 的输出是:root 1025 1015 0 11:27 pts/0 00:00:00 sudo su - postgres root 1026 1025 0 11:27 pts/0 00:00:00 su - postgres postgres 1027 1026 0 11:27 pts/0 00:00:00 -su postgres 1031 1027 0 11:29 pts/0 00:00:00 ps -ef postgres 1032 1027 0 11:29 pts/0 00:00:00 grep post
  • 您应该检查您的pg_hba.conf 文件。通过 Unix 套接字的本地连接应该可以工作,但最好确保。其他问题可能是端口,您可以在postgresql.conf 文件中检查。
  • 我的系统上不存在类似的文件
  • 如果这些文件不存在,说明你没有安装 Postgres。 Here's a nice summary of installing Postgres on Ubuntu

标签: postgresql ubuntu psql


【解决方案1】:

错误信息提示:

服务器是否在本地运行

根据在 cmets 中发布的ps -ef | grep "post" 的结果,答案是肯定的server processes 不存在,服务器没有运行。

你写的这一事实我从来没有遇到过 psql 的任何问题, 表明它之前已经安装并工作过,在这种情况下,请查看 /var/log/postgresql 中的最新日志文件以检查指示服务器未启动原因的任何致命错误消息。

【讨论】:

    【解决方案2】:

    错误意味着 Postgres 服务器没有运行。尝试启动它:

    sudo systemctl start postgresql
    

    我相信服务名称是 postgresql,但如果这不起作用,请尝试输入

    sudo systemctl start postgres

    然后按 Tab 键自动完成。

    确保服务器在启动时启动:

    sudo systemctl 启用 postgresql

    【讨论】:

      【解决方案3】:
      1. 安装并运行 postgreSQL

      createdb -h localhost -p 5432 -U postgres testdb password ******

      【讨论】:

      • createdb:命令行参数太多(首先是“******”
      【解决方案4】:

      就我而言,我执行了以下操作来消除此错误:

      sudo apt remove --purge postgres*
      sudo apt remove --purge pg*   #optional
      sudo apt autoremove
      sudo apt autoclean
      sudo apt clean
      

      那么……

      sudo apt update
      sudo apt upgrade
      sudo apt install -y postgresql-10 postgresql-contrib postgresql-client
      sudo apt install -y postgresql-server pgadmin4 ] -> this you may need for metasploit
      sudo reboot
      

      最后,在检查是否已安装 Postgresql 后,如果它已关闭,则执行以下操作:

      列出您设备上运行的所有 Postgres 集群:
      pg_lsclusters

      重启pg_ctlcluster:
      sudo pg_ctlcluster 10 main start

      重启PostgreSQL服务:
      sudo service postgresql restart

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-11-29
        • 1970-01-01
        • 1970-01-01
        • 2021-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多