postgresql - 无法从 python 脚本和命令行连接到数据库,但可以连接到 PGadmin - 致命:用户“postgres”的身份验证失败
问题描述
我知道类似的问题已经被问了大约 2000 次,但到目前为止我找到的答案都没有帮助我。
因此,我可以通过 SSH 隧道通过 PGAdmin 连接到我的数据库,我也可以使用su - postgres psql
,但是当我这样做时su - postgres
,psql -U postgres -h localhost
就会出现错误FATAL: Ident authentication failed for user "postgres"
。
当我尝试使用我的 python 脚本连接到数据库时,也会发生同样的事情。
当然,我尝试pg_hba.conf
以多种方式编辑我的文件,将所有内容设置为trust
,password
或md5
. 每次都说同样的话。
目前我的pg_hba.conf
样子是这样的:
local all all md5
host all all 127.0.0.1/32 md5
host all all ::1/128 md5
是的,我确实在更改之间重新启动了服务器。我不知道这里可能是什么问题,任何帮助将不胜感激!
解决方案
好的,我终于设法解决了这个问题!
此处的错误消息完全具有误导性。问题是“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
解决了问题。
希望这对将来的某人有所帮助:)
推荐阅读
- javascript - 函数对象中的方法是否没有隐式链接为成员?
- bash - 尝试执行简单计算的 bash shell 上的语法错误
- arrays - Numpy best way to assign array to a single point in another array (4D)
- python - Python:将日期列表从 DDMM 更改为 DD-MM
- java - 打开 .jnlp 并收到 JRE 版本的错误
- html - ID 选择器样式不适用于媒体查询
- android - 如何在 MediaStore.Downloads 集合中保存视频缩略图。安卓Q
- javascript - 单张(7 轨)专辑的简单音乐播放器(JavaScript 错误)
- ruby-on-rails - 在solidus 上读取的第一个文件是什么?
- ruby-on-rails - NoMethodError:Capybara 测试期间未定义的方法“last_comment”