postgresql安装后链接报错psql: FATAL: Ident authentication failed for user “postgres“

本文介绍了解决 PostgreSQL 在本地和远程连接时出现的 Ident 认证失败问题的方法。通过修改 pg_hba.conf 文件中的认证方式,并重启 PostgreSQL 服务,最终实现了正常连接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

postgresql 安装成功后,使用链接语句链接

[root@iZbp1hdum7hefdeb75mnyfZ ~]# psql -d postgres -U postgres -W
Password for user postgres: 
psql (9.6.24)
Type "help" for help.

postgres=# 
postgres=# 
postgres=# 

这样链接并没有报错,但是这样登录就会报错误

[root@iZbp1hdum7hefdeb75mnyfZ ~]# psql -hlocalhost -d postgres -U postgres -W
Password for user postgres: 
psql: FATAL:  Ident authentication failed for user "postgres"
[root@iZbp1hdum7hefdeb75mnyfZ ~]# psql -h127.0.0.1 -d postgres -U postgres -W
Password for user postgres: 
psql: FATAL:  Ident authentication failed for user "postgres"

Navicat的远程链接也会报错Ident authentication failed for user “postgres”

修改

vim /var/lib/pgsql/9.6/data/pg_hba.conf

将IPv6等注释掉


# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             postgres                                md5
# IPv4 local connections:
#host    all             all             127.0.0.1/32            ident
host    all             all             0.0.0.0/0               md5
host    replication     replica         10.29.0.0/16            md5

# IPv6 local connections:
#host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            ident
#host    replication     postgres        ::1/128                 ident

重新启动postgresql

systemctl restart postgresql-9.6.service

再次链接就好用了

[root@iZbp1hdum7hefdeb75mnyfZ ~]# psql -h localhost -p 5432 -U postgres
Password for user postgres: 
psql (9.6.24)
Type "help" for help.

postgres=# 

当出现类似于"psql: error: FATAL: Peer authentication failed for user 'postgres'"的错误提示时,这通常表示登录PostgreSQL数据库时认证失败。这个错误通常发生在使用Peer认证方法和相应的身份验证配置不正确的情况下。 Peer认证是一种基于操作系统用户身份验证的方法,它要求登录用户的操作系统用户必须与PostgreSQL的用户一致。换句话说,你需要使用与PostgreSQL用户相同的操作系统用户来登录。 如果你是通过使用"psql -U postgres"命令登录PostgreSQL遇到这个错误,那么这意味着你正在尝试使用名为"postgres"的操作系统用户来登录PostgreSQL,但是该用户没有通过Peer认证验证。 解决这个问题,你可以尝试以下几种方法: 1. 使用与PostgreSQL用户相匹配的操作系统用户来登录。确保你正在使用正确的用户名和密码,以及正确的Peer认证配置。 2. 如果你想使用名为"kmjy"的用户登录PostgreSQL,你可以尝试使用以下命令登录: "psql -U kmjy"。确保你已经在PostgreSQL中创建了该用户,并且使用正确的密码进行登录。 3. 如果你无法解决这个问题,你可以尝试修改PostgreSQL的身份验证配置文件pg_hba.conf。在这个文件中,你可以更改或添加适当的身份验证方法来满足你的需求。 总结来说,当出现"psql: error: FATAL: Peer authentication failed for user"的错误时,这意味着登录PostgreSQL时认证失败。你可以尝试使用与PostgreSQL用户相匹配的操作系统用户来登录,或者使用正确的用户名和密码来登录。如果仍然无法解决问题,你可以尝试修改PostgreSQL的身份验证配置文件。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [psql: error: FATAL: Peer authentication failed for userpostgres](https://blog.csdn.net/FatalFlower/article/details/114025262)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [【PostgreSQLpsql: error: FATAL: Peer authentication failed for userpostgres”](https://blog.csdn.net/wuyy0224/article/details/126737268)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MonkeyKing.sun

对你有帮助的话,可以打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值