无法连接到 PostgreSQL 服务器:致命:用户“postgres”的对等身份验证失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42186432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to connect to PostgreSQL server: FATAL: Peer authentication failed for user "postgres"
提问by laukok
How can how to access postgres databases from adminer?
如何从管理员访问 postgres 数据库?
I have changed the password for the user postgres
:
我已经更改了用户的密码postgres
:
$ sudo -u postgres psql
$ postgres=# alter user postgres password 'secret';
Result:
结果:
ALTER ROLE
But I still get this error on the adminer:
但是我仍然在管理员上收到此错误:
Unable to connect to PostgreSQL server: FATAL: Peer authentication failed for user "postgres"
Any ideas why?
任何想法为什么?
I have these two users:
我有这两个用户:
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 | {}
But I did not set password for user root
when I created it with this command:
但是root
当我使用以下命令创建用户时,我没有为用户设置密码:
sudo -u postgres createuser --interactive
Output (why doesn't it ask for password??):
输出(为什么不要求输入密码??):
Enter name of role to add: root
Shall the new role be a superuser? (y/n) y
But I still get the error on adminer:
但我仍然在 adminer 上收到错误消息:
Unable to connect to PostgreSQL server: FATAL: Peer authentication failed for user "root"
EDIT:
编辑:
THis is some bits of my pg_hba.conf
这是我的一些 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
I changed peer
to ident
:
我改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
Then restarted my machine. but still no luck.
然后重新启动了我的机器。但仍然没有运气。
回答by laukok
回答by Andomar
Looks like you're using "peer authentication" where you want to be using "password authentication". With the default pg_hba.conf, you can switch to password authentication by specifying a hostname, or "127.0.0.1".
看起来您正在使用“对等身份验证”,而您想在其中使用“密码身份验证”。使用默认的 pg_hba.conf,您可以通过指定主机名或“127.0.0.1”来切换到密码验证。
See the Postgres documentation for authentication methods.
有关身份验证方法,请参阅Postgres 文档。