【问题标题】:Trying to connect my herokuApp to an outside postgres试图将我的 herokuApp 连接到外部 postgres
【发布时间】:2019-02-05 10:25:36
【问题描述】:

我正在尝试将我的 Heroku 应用程序连接到外部 PostgreSQL。但我不断收到连接被拒绝错误:

ActionView::Template::Error (could not connect to server: Connection refused
2018-08-30T12:44:46.868880+00:00 app[web.1]: Is the server running on       host "localhost" (127.0.0.1) and accepting
2018-08-30T12:44:46.868882+00:00 app[web.1]: TCP/IP connections on port 5432?

在我的 Heroku Admin 中,我将 DATABASE_URL 设置为指向我的 PostgreSQL(无密码)

DATABASE_URL postgres://postgres:@localhost:5432/postgres

我的 database.yml 看起来像这样

default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see Rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

production:
  <<: *default
  url: <%= ENV['DATABASE_URL'] %>

当我输入命令 Heroku config 时,我肯定可以看到我的 DATABASE_URL。这里有什么问题?

【问题讨论】:

  • 为什么不使用 herokus Postgres dB?您可以导出本地免费托管。
  • 我们正在试验 Heroku 的功能。客户可能将他们的数据库分开
  • 外部 PostgreSQL 是指本地主机?
  • 是的。在 Heroku 之外
  • 我想如果你能改变heroku配置heroku config:set DATABASE_URL=postgres://user_name:password@host:port/database_name。确保您不在防火墙后面。

标签: ruby-on-rails postgresql heroku heroku-postgres


【解决方案1】:

DATABASE_URL postgres://postgres:@localhost:5432/postgres

这是将您的应用程序中使用的DATABASE_URL 配置变量设置为使用localhost 上的数据库,这将解析为运行应用程序的机器,因此会出现错误。

您可能想要做的是将“localhost”更改为运行 Postgres 实例的 IP 地址以及身份验证所需的凭据。

【讨论】:

  • 已经尝试用我的 ip 地址和公共地址替换 localhost 但仍然拒绝连接。 heroku 和 postgres 实例都在同一台机器上
  • 啊,好吧,所以您正在本地运行 postgres 并尝试将您的 Heroku 应用程序(在 Heroku 上运行 - 在 Amazon 上运行)连接到您的本地数据库?这指向网络配置问题。
猜你喜欢
  • 2018-06-09
  • 1970-01-01
  • 2018-01-31
  • 2018-09-05
  • 2020-07-30
  • 2021-08-02
  • 1970-01-01
  • 2023-02-19
  • 1970-01-01
相关资源
最近更新 更多