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

x33g5p2x  于2022-02-07 转载在 其他  
字(1.3k)|赞(0)|评价(0)|浏览(290)

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=#

相关文章

微信公众号

最新文章

更多