首页 > 代码库 > psql: 致命错误: 对用户"user1"的对等认证失败

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

操作系统:Debian8

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

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

打开以下文件,

$ sudo vi /etc/postgresql/9.4/main/pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD# "local" is for Unix domain socket connections onlylocal 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 onlylocal 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 --

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