【问题标题】:Unable to connect to PostgreSQL server: FATAL: Peer authentication failed for user "postgres"无法连接到 PostgreSQL 服务器:致命:用户“postgres”的对等身份验证失败
【发布时间】:2017-02-12 10:23:52
【问题描述】:

如何从 adminer 访问 postgres 数据库?

我已更改用户postgres的密码:

$ sudo -u postgres psql
$ postgres=# alter user postgres password 'secret';

结果:

ALTER ROLE

但我仍然在管理员上收到此错误:

Unable to connect to PostgreSQL server: FATAL: Peer authentication failed for user "postgres"

有什么想法吗?

我有这两个用户:

postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 root      | Superuser, Create role, Create DB                          | {}

但是当我使用此命令创建用户root 时,我没有设置密码:

sudo -u postgres createuser --interactive

输出(为什么不要求输入密码??):

Enter name of role to add: root
Shall the new role be a superuser? (y/n) y

但我仍然收到管理员错误:

Unable to connect to PostgreSQL server: FATAL: Peer authentication failed for user "root"

编辑:

这是我pg_hba.conf的一些片段

sudo nano /etc/postgresql/9.5/main/pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5

我把peer改成了ident

# Database administrative login by Unix domain socket
local   all             postgres                                ident

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     ident
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5

然后重新启动我的机器。但仍然没有运气。

【问题讨论】:

    标签: postgresql adminer


    【解决方案1】:

    here得到我的回答:

    local   all             postgres                                md5
    

    然后重启服务:

    sudo systemctl restart postgresql.service
    

    【讨论】:

      【解决方案2】:

      看起来您正在使用“对等身份验证”,而您希望使用“密码身份验证”。使用默认的 pg_hba.conf,您可以通过指定主机名或“127.0.0.1”来切换到密码验证。

      请参阅Postgres documentation for authentication methods

      【讨论】:

        猜你喜欢
        • 2020-02-25
        • 1970-01-01
        • 2020-11-30
        • 2013-07-23
        • 2021-07-03
        • 2013-02-24
        • 2018-10-09
        • 2014-03-17
        • 2011-02-25
        相关资源
        最近更新 更多