3

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

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

我正在使用 PostgreSQL 13 和 PgAdmin 4 v5。

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

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

4

2 回答 2

2

您需要重新加载数据库,然后再次设置用户的密码(可能使用超级用户帐户),以便用户再次拥有经过 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
于 2021-04-26T11:18:25.510 回答
2

I solved following these steps:

Change password_encryption to md5 in file postgresql.conf

Change the first 3 occurances of scram-sha-256 to trust in file pg_hba.conf

# "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

Restart postgresql service

Execute psql -U postgres (you won't be asked for password)

Change password with command /password

Change the first 3 occurances of trust to md5 in file pg_hba.conf

# "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

Restart postgresql service

于 2021-04-26T16:13:55.643 回答