如何解决 Postgresql SCRAM 身份验证问题?

问题描述:

将项目移至生产环境后出现错误.用生产服务器运行时报错如下

I am getting an error after moving the project to production. The error is as follows while running with production server

pg_connect():无法连接到 PostgreSQL 服务器:SCRAM 身份验证需要 libpq 10 或更高版本.

这是我的 postgreSQL 版本:

Here is my postgreSQL version:

开发版本:

PostgreSQL 11.5 on x86_64-pc-linux-gnu,由 gcc (GCC) 4.8.5 编译 20150623(红帽 4.8.5-36),64 位

PostgreSQL 11.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), 64-bit

生产版本:

PostgreSQL 11.5 (EnterpriseDB Advanced Server 11.5.12) on x86_64-pc-linux-gnu,由 gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36) 编译,64 位

PostgreSQL 11.5 (EnterpriseDB Advanced Server 11.5.12) on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), 64-bit

您的应用程序使用与 PostgreSQL 客户端 C 库 libpq 链接的 API.

Your application uses an API that is linked with the PostgreSQL client C library libpq.

该库的版本必须是 9.6 或更低版本,并且在 v10 中引入了 SCRAM 身份验证.

The version of that library must be 9.6 or older, and SCRAM authentication was introduced in v10.

升级libpq 在应用端并重试.

如果不需要scram-sha-256认证,可以恢复为md5:

If you don't need scram-sha-256 authentication, you can revert to md5:

  • postgresql.conf
  • 中设置password_encryption = md5
  • pg_hba_conf中的认证方式改为md5
  • 重新加载 PostgreSQL
  • 修改用户密码,获取MD5加密密码