You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PostgreSQL连接报错:pg_hba.conf无对应条目,求解决方案

解决Sequelize-Auto连接PostgreSQL的pg_hba.conf错误

错误信息

ConnectionError [SequelizeConnectionError]: no pg_hba.conf entry for host "103.244.174.70", user "postgres", database "patientlist", no encryption
    at Client._connectionCallback (C:\Users\hamza\nx gen\patient record system\backend\node_modules\sequelize\lib\dialects\postgres\connection-manager.js:143:24)
    at Client._handleErrorWhileConnecting (C:\Users\hamza\nx gen\patient record system\backend\node_modules\pg\lib\client.js:327:19)
    at Client._handleErrorMessage (C:\Users\hamza\nx gen\patient record system\backend\node_modules\pg\lib\client.js:347:19)
    at Connection.emit (node:events:390:28)
    at C:\Users\hamza\nx gen\patient record system\backend\node_modules\pg\lib\connection.js:117:12)
    at Parser.parse (C:\Users\hamza\nx gen\patient record system\backend\node_modules\pg-protocol\dist\parser.js:40:17)
    at Socket.<anonymous> (C:\Users\hamza\nx gen\patient record system\backend\node_modules\pg-protocol\dist\index.js:11:42)
    at Socket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9) {
  parent: error: no pg_hba.conf entry for host "103.244.174.70", user "postgres", database "patientlist", no encryption
      at Parser.parseErrorMessage (C:\Users\hamza\nx gen\patient record system\backend\node_modules\pg-protocol\dist\parser.js:287:98)
      at Parser.handlePacket (C:\Users\hamza\nx gen\patient record system\backend\node_modules\pg-protocol\dist\parser.js:126:29)
      at Parser.parse (C:\Users\hamza\nx gen\patient record system\backend\node_modules\pg-protocol\dist\parser.js:39:38)
      at Socket.<anonymous> (C:\Users\hamza\nx gen\patient record system\backend\node_modules\pg-protocol\dist\index.js:11:42)
      at Socket.emit (node:events:390:28)
      at addChunk (node:internal/streams/readable:315:12)
      at readableAddChunk (node:internal/streams/readable:289:9)
      at Socket.Readable.push (node:internal/streams/readable:228:10)
      at TCP.onStreamRead (node:internal/stream_base_commons:199:23) 

有效解决步骤

  • 定位pg_hba.conf文件
    打开PostgreSQL命令行(psql),执行以下命令获取文件路径:

    SHOW hba_file;
    

    也可直接到PostgreSQL安装目录的data子文件夹中查找该文件。

  • 添加匹配的访问规则
    用文本编辑器打开pg_hba.conf,在现有规则前添加一行(规则匹配顺序从上到下,确保该行在不匹配的规则之前):

    host    patientlist    postgres    103.244.174.70/32    scram-sha-256
    

    说明:

    • patientlist:目标数据库名,也可用all匹配所有数据库
    • postgres:目标用户名,也可用all匹配所有用户
    • 103.244.174.70/32:允许连接的客户端IP(/32表示单个IP,若需允许整个子网可改为/24等)
    • scram-sha-256:认证方式,PostgreSQL 10+推荐使用,旧版本可改为md5
  • 重启PostgreSQL服务

    • Windows:打开「服务」面板,找到PostgreSQL服务右键重启
    • Linux:执行命令 sudo systemctl restart postgresql
    • Mac:执行命令 brew services restart postgresql
  • 处理加密相关问题
    错误提示包含no encryption,需同步调整:

    1. 若PostgreSQL要求加密连接:在Sequelize-Auto的配置中添加ssl: true参数
    2. 若无需加密:可在pg_hba.conf的规则中改用trust或md5,同时修改PostgreSQL配置文件postgresql.conf中的ssl = off,重启服务生效(生产环境不建议关闭加密)
  • 验证规则有效性
    用psql直接测试连接,确认规则生效:

    psql -h [你的PostgreSQL主机IP] -U postgres -d patientlist
    

额外排查点

  • 检查postgresql.conf中的listen_addresses是否设为*,确保PostgreSQL监听所有IP
  • 确认客户端IP未被防火墙/安全组拦截
  • 检查规则是否写错,比如IP地址、子网掩码、数据库/用户名拼写错误

内容的提问来源于stack exchange,提问作者Hamza Bilal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 14:17:06