Postgres not allowing localhost but works with 127.0.0.1

后端 未结 2 1408
梦如初夏
梦如初夏 2021-02-05 12:10

Postgres not accepting connection if I say -h localhost but it works if I say -h 127.0.0.1

[root@5d9ca0effd7f opensips]# psql -U postgre         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-05 12:54

    The Problem

    Postgres will potentially use IPv6 when specifying -h localhost which given the above pg_hba.conf specifies ident, a password prompt will be returned.

    However when -h 127.0.0.1 is specified, it forces Postgres to use IPv4, which is set to trust in above config and allows access without password.


    The Answer

    Thus the answer is to modify the IPv6 host line in pg_hba.conf to use trust:

    # IPv6 local connections:
    host    all         all         ::1/128               trust
    

    Remembering to restart the Postgres service after making config changes.

提交回复
热议问题