【发布时间】:2018-05-18 00:31:01
【问题描述】:
我无法登录和使用创建的数据库,因为我收到密码或对等身份验证失败。下面概述了我是如何设置的,我是如何尝试解决遇到的问题的,以及更多潜在的相关信息。
我正在使用postgresql-9.5,当我下载 postgres 时,它使用的 linux mint 用户/用户名与我目前尝试访问的不同。以下所有命令都是从新用户/用户名发送的。
我使用以下命令创建了一个新的 postgres 数据库和一个带有密码的新用户:sudo su - postgres
$ psql
postgres=# CREATE DATABASE PostgresDB;
postgres=# CREATE USER PostgresUser WITH PASSWORD 'password';
postgres=# ALTER ROLE PostgressUser SET default_transaction_isolation TO 'read committed'
postgres=# GRANT ALL PRIVILEGES ON DATABASE PostgresDB TO PostgresUser;
然后我继续尝试以多种方式登录:
psql -d PostgresDB -U PostgresUser
返回:psql: FATAL: Peer authentication failed for user "PostgresUser"
-
psql -d PostgresDB -U PostgresUser -W和密码输入 -
psql -d、psql -U PostgresUser -h 127.0.0.1 -d PostgresDB和密码输入
每个返回:psql: FATAL: password authentication failed for user "PostgresUser"
在重置密码之前和之后,我进行了上述所有尝试登录:ALTER PostgresUser WITH PASSWORD 'password'
我检查了 pg_hba.conf 文件,其中的重要部分如下:
# 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
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all md5
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
【问题讨论】:
标签: postgresql ubuntu-16.04 linux-mint postgresql-9.5