PostgreSQL 将密码加密从 SCRAM 降级到 md5

问题描述

我需要将用户 postgres 的密码加密从 scram-sha-265 降级到 md5

我尝试修改 pg_hba.confpostgresql.conf 文件,将密码加密从 scram-sha-256 更改为 md5 但之后我无法连接到数据库

我使用的是 Postgresql 13 和 PgAdmin 4 v5。

感谢您的任何帮助和建议!

PS:我必须这样做,因为 RStudio 无法使用 Scram 身份验证管理连接。

解决方法

您需要重新加载数据库,然后再次设置用户密码(可能使用超级用户帐户),以便用户再次拥有 MD5 哈希密码。以超级用户身份使用 psql 连接到数据库,然后:

SELECT pg_reload_conf();

-- to verify the settings are like you want:

SHOW password_encryption;
SELECT * FROM pg_hba_file_rules();

-- change the password

\password myuser
,

我按照以下步骤解决了:

在文件 postgresql.conf

中将 password_encryption 更改为 md5

在文件 pg_hba.conf

中将 scram-sha-256 的前 3 次出现更改为 trust
# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust

重启 postgresql 服务

执行psql -U postgres(不会要求你输入密码)

使用命令/password

更改密码

在文件 pg_hba.conf

中将 trust 的前 3 次出现更改为 md5
# "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

重启 postgresql 服务