2017-02-12 170 views
1

如何从adminer访问postgres数据库?无法连接到PostgreSQL服务器:FATAL:用户“postgres”的对等验证失败

我已经为用户postgres更改密码:

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

结果:

ALTER ROLE 

但是我还是对adminer此错误:

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

enter image description here

任何想法为什么?

我有这两个用户:

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 

但我仍然得到adminer错误:

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 

我改变peerident一些位:

# 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 

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

回答

1

得到了我的回答here

local all    postgres        md5 

,然后重新启动服务:

sudo systemctl restart postgresql.service 
相关问题