【发布时间】:2020-02-25 03:57:55
【问题描述】:
我使用此处的命令 [https://www.postgresql.org/download/linux/redhat/]
安装并设置了 postgresql-12yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install postgresql12
yum install postgresql12-server
/usr/pgsql-12/bin/postgresql-12-setup initdb
systemctl enable postgresql-12
systemctl start postgresql-12
然后我尝试登录数据库
psql postgres postgres
我收到了错误
psql: error: could not connect to server: FATAL: Peer authentication failed for user "postgres"
我的系统上有两个 pg_hba.conf 文件。我按照此处的建议检查了身份验证设置,如下所示 [psql: FATAL: Ident authentication failed for user "postgres"
/data/pg_data_dir/pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
host all all 0.0.0.0/0 md5
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
/var/lib/pgsql/12/data/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 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
身份验证设置看起来不错,所以我不知道从这里做什么。
【问题讨论】:
-
您需要重新加载配置文件才能使用更新的
pg_hba.conf文件——您可以在尝试psql之前重新启动postgres 或su - postgres。一旦你进入psql,发出select pg_reload_conf(); -
您的错误消息指出
peer身份验证失败。您显示的pg_hba.conf文件不包含使用peer身份验证方法的规则。您确定没有其他pg_hba.conf文件吗?检查postgresql.conf文件中的hba_file条目。
标签: postgresql