【问题标题】:Cannot connect to database from python script and command line, but can connect with PGadmin - FATAL: Ident authentication failed for user "postgres"无法从 python 脚本和命令行连接到数据库,但可以连接到 PGadmin - 致命:用户“postgres”的身份验证失败
【发布时间】:2020-08-07 10:11:59
【问题描述】:

我知道类似的问题已经被问了大约 2000 次,但到目前为止我找到的答案都没有帮助我。

所以我可以通过 SSH 隧道通过 PGAdmin 连接到我的数据库,我也可以使用su - postgres psql,但是当我使用su - postgrespsql -U postgres -h localhost 之类的东西时,我收到错误FATAL: Ident authentication failed for user "postgres"

当我尝试使用我的 python 脚本连接到数据库时,也会发生同样的事情。

当然,我尝试以多种方式编辑我的pg_hba.conf 文件,将所有内容设置为trustpasswordmd5。每次都说同样的话。

目前我的pg_hba.conf 看起来像这样:

local all all md5

host all all 127.0.0.1/32 md5

host all all ::1/128 md5

是的,我确实在更改之间重新启动了服务器。我不知道这里可能是什么问题,非常感谢任何帮助!

【问题讨论】:

    标签: postgresql centos7


    【解决方案1】:

    好的,我终于设法解决了这个问题!

    这里的错误信息完全具有误导性。问题是“localhost”没有解析为 127.0.0.1,因为 /etc/hosts 文件有两行指定 localhost:

    127.0.0.1 localhost.localdomain localhost localhost4.localdomain4 localhost4

    ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

    使用 127.0.0.1 或仅保留 ::1 localhost6 localhost6.localdomain6 解决了问题。

    希望这对将来的人有所帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-21
      • 1970-01-01
      • 1970-01-01
      • 2020-02-25
      • 2016-05-20
      • 1970-01-01
      • 2021-07-03
      相关资源
      最近更新 更多