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

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

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

  1. [root@iZbp1hdum7hefdeb75mnyfZ ~]# psql -d postgres -U postgres -W
  2. Password for user postgres:
  3. psql (9.6.24)
  4. Type "help" for help.
  5. postgres=#
  6. postgres=#
  7. postgres=#

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

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

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

修改

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

将IPv6等注释掉

  1. # TYPE DATABASE USER ADDRESS METHOD
  2. # "local" is for Unix domain socket connections only
  3. local all postgres md5
  4. # IPv4 local connections:
  5. #host all all 127.0.0.1/32 ident
  6. host all all 0.0.0.0/0 md5
  7. host replication replica 10.29.0.0/16 md5
  8. # IPv6 local connections:
  9. #host all all ::1/128 ident
  10. # Allow replication connections from localhost, by a user with the
  11. # replication privilege.
  12. #local replication postgres peer
  13. #host replication postgres 127.0.0.1/32 ident
  14. #host replication postgres ::1/128 ident

重新启动postgresql

  1. systemctl restart postgresql-9.6.service

再次链接就好用了

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

相关文章