psql:严重:即使设置了密码,用户“ XXX”的对等身份验证也失败

时间:2018-12-12 10:20:55

标签: postgresql authentication

我可以肯定地说我有一个用户,密码为test。但是,无论如何,我无法通过此用户进行连接。

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

postgres=# alter user depotadmin password 'test';
ALTER ROLE

我正在设置用户密码:

hutber@laptop:~/site/depot_fe$ sudo -u postgres psql depotdb 
[sudo] password for hutber:        
psql (10.6 (Ubuntu 10.6-0ubuntu0.18.04.1))
Type "help" for help.

depotdb=# alter user depotadmin password 'test';
ALTER ROLE

但是现在我无法登录:

hutber@laptop:~/programs/pgAdmin4/pgAdmin4$ psql depotdb -U depotadmin -W
Password for user depotadmin: 
psql: FATAL:  Peer authentication failed for user "depotadmin"

1 个答案:

答案 0 :(得分:0)

您必须检查hba文件。要检查它在哪里,请在psql上使用以下命令:

SHOW hba_file;

您的hba文件可能具有一个配置为对等身份验证类型的本地连接类型的条目。您可以将对等更改为md5。像这样:

#old entry (connection type, database, user, auth type)
#This line means: every connection made by unix-domain sockets (local), 
#for any database and with any user will use peer auth type
local      *  *  peer   

#new entry
local      depotdb  depotadmin  md5   

在那之后,您必须重新启动集群或向后端发出信号以重新加载其配置:

SELECT pg_reload_conf();