首页 » PostgreSQL/GaussDB » openGauss Connecting to database FATAL : no pg_hba.conf entry for host”x.x.x.x”, user”xxx”, database”postgres”, SSL off

openGauss Connecting to database FATAL : no pg_hba.conf entry for host”x.x.x.x”, user”xxx”, database”postgres”, SSL off

一个客户应用原来直接使用opengauss 驱动连接正常,但是出于加密的应用需求,外包了一层增加了应用驱动,在连接串不变前提下,连接数据库报错:

Error Connecting to database FATAL : no pg_hba.conf entry for host"x.x.x.x", user"weejar", database"postgres", SSL off

应用的连接串

Classname: com.opengauss.Driver
 Url= jdbc:openguass://ip:27000/anbob?currentSchema=weejar

原因

Error Connecting to database FATAL : no pg_hba.conf entry错误表示对数据库的身份验证尝试失败,因此无法建立连接。发生这种情况的原因可能有很多:

  • 配置文件 pg_hba.conf中缺少配置认证
  • 身份验证失败,因为用户/密码凭据无效
  • 身份验证失败,因为连接未使用 SSL 加密:(SSL off)。
  • 因为客户端环境之前已配置为基于证书的 Postgres 身份验证 (mTLS),但当前服务器未配置基于证书的身份验证。

客户端身份验证由配置文件控制,该文件通常名为 pg_hba.conf,存储在数据库集群的数据目录中。像上面的案例,我们的数据库为anbob,用户为weejar, 业务就没有使用postgres数据库,可能应用原来是基于postgreSQL开发,存在默认的访问postgres数据库,需要增加授权访问。

解决方法
将应用程序服务器的 IP 地址添加到 , pg_hba.conf 并确保方法未设置为 reject。您需要修改 xxx.xxx.xxx.xxx 并输入 IP 地址以允许连接。

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD
 
# IPv4 local connections:
host    all         all         127.0.0.1/32          md5
host    all  	    all  	xxx.xxx.xxx.xxx       md5

-- or --
host postgres  anbob  xxx.xxx.xxx.xxx md5

更新 pg_hba.conf 后,在数据库中运行以下命令重新加载新添加的信息。

SELECT pg_reload_conf()
打赏

目前这篇文章还没有评论(Rss)

我要评论