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

Rails连接外部PostgreSQL数据库报错:无法解析主机名

Rails连接外部PostgreSQL数据库报错解决

错误提示could not translate host name "https://hostdb.com.br/" to address: Name or service not known的核心原因是**database.yml中host字段配置错误**。

PostgreSQL的host参数仅需填写数据库服务器的纯域名或IP地址,不需要添加https://协议前缀,也不能保留末尾的斜杠,否则会导致域名解析失败。

修改后的database.yml配置

external_db:
  adapter: postgresql
  encoding: utf8
  database: db_name
  host: hostdb.com.br
  username: user
  password: pass
  port: 5734

你的ExternalDb抽象模型代码是正确的,修改配置后重新执行查询语句即可。

额外检查项

  • 确认外部数据库的5734端口对你的Rails应用服务器开放
  • 核对数据库名称、用户名、密码是否完全匹配
  • 若外部数据库要求SSL连接,需添加sslmode: require配置项到external_db节点中

内容的提问来源于stack exchange,提问作者Diogo Amaral

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 15:22:02