我可以肯定地说,我有一个用户,密码为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"
您必须检查您的hba文件。要检查它在哪里,请在psql上使用以下命令:
SHOW hba_file;
可能您的hba文件有一个本地连接类型配置为对等身份验证类型的条目。您可以从peer更改为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();