我使用此处的[https://www.postgresql.org/download/linux/redhat/]命令安装并设置了postgresql-12
yum 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身份验证设置看起来没问题,所以我不确定从这里该做什么。
发布于 2019-10-30 05:09:35
编辑-使其更有条理,更易于使用。
首先,您需要了解每种身份验证方法的含义,在here中有大量关于这方面的信息。长话短说,在这个阶段,您可能感兴趣的是md5,它是一个哈希密码,或者trust,它不是密码。
在计算机上安装postgres后,您需要成为postgres用户,然后尝试使用psql
~# su -l postgres --assume you're postgres
~$ psql --connect
psql (xx.x ))
Type "help" for help.
postgres=#进入后,您可以为该用户设置新密码:
postgres=# \password postgres为了防止这种情况发生,您需要询问postgres hba文件在哪里:
postgres=# SHOW hba_file;使用您最喜欢的文本编辑器并对其进行修改以满足您的需要。
此外,您还需要确保重新加载postgresql服务,命令为:
sudo systemctl reload postgresql-12.service
https://stackoverflow.com/questions/58615425
复制相似问题