psql: 致命错误: 对用户"user1"的对等认证失败

操作系统:Debian8

登录pg时可能会有提示错误:

$ psql -U user1 -d exampledb
psql: 致命错误: 对用户"user1"的对等认证失败

打开以下文件,

$ sudo vi /etc/postgresql/9.4/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

将 peer 改为md5:

# TYPE DATABASE USER ADDRESS METHOD

# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5

然后重启服务:

$ sudo service postgresql restart

再登录即可:

$ psql -U user1 -d exampledb

-- End --

posted @ 2016-10-14 19:01  ibg  阅读(6985)  评论(0编辑  收藏  举报