我正在尝试使用以下命令登录数据库:
psql -U user my_db
这是引发的错误:
psql:致命:用户“用户”的对等身份验证失败
我认为这与我的 pg_hba.conf 有关。我尝试了几件事,但无法让它工作。这是 pg_hba.conf 的相关部分
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local my_db user md5
local all all md5
# IPv4 local connections:
host my_db user 127.0.0.1/32 md5
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
我第一次su - postgres
尝试时也遇到同样的错误psql -U user
编辑:原来我修改了错误的 pg_hba.conf。我解决了原来的问题,现在我可以这样登录了:psql -U user my_db
. 但是在同一设备上运行的我的应用程序无法使用此 pg_hba.conf 访问数据库。检查日志,这是我的应用程序发出新请求时显示的行:
2019-12-10 16:18:51.144 +03 [29570] LOG: invalid length of startup packet