当前位置: 首页 > 知识库问答 >
问题:

PSQL:错误:无法连接到服务器:致命:用户“Postgres”的对等身份验证失败

易祯
2023-03-14
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"
# 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
# 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

身份验证设置看起来还可以,所以我不确定从这里要做什么。

共有1个答案

夏侯星洲
2023-03-14

编辑-使它更有条理,更易用。

首先,您需要理解每一种身份验证方法的含义,这里有很多关于这方面的信息。长话短说,在这个阶段,您可能会感兴趣的是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服务,命令是:

 类似资料: