【问题标题】:How to use postgres with rails on heroku如何在heroku上使用带有rails的postgres
【发布时间】:2013-07-16 23:45:49
【问题描述】:

我在 database.yml 中有以下内容

production:
  adapter: postgresql
  database: dbname
  host: host.compute-1.amazonaws.com
  username: user
  password: pass_word
  DATABASE_URL: postgres://user:pass_word@host.compute-1.amazonaws.com:5432/dbname

但是在 git push heroku master 上,我收到以下错误。

could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?

我是否也需要针对其他环境进行更改?

【问题讨论】:

  • 请从 database.yml 中删除 DATABASE_URL
  • 我是在之前得到错误后才添加的,但错误没有任何变化
  • 您在 git push 时遇到了错误,所以请您粘贴您在 git push heroku master 时遇到的全部错误
  • 请同时检查stackoverflow.com/questions/16124490/…config.assets.initialize_on_precompile = false

标签: ruby-on-rails heroku configuration


【解决方案1】:

heroku 在部署时自动生成 database.yml

你需要 .git 忽略database.yml

您可以通过设置ENV['DATABASE_URL'] (use heroku config:add DATABASE_URL=....)来选择另一个数据库

更多信息请查看heroku documentation

【讨论】:

    【解决方案2】:

    DATABASE_URL 不是必需的。或者你可以查看这个http://railsapps.github.io/rails-heroku-tutorial.html

    【讨论】:

    • 请查看我们的 cmets
    【解决方案3】:

    这个错误

    could not connect to server: Connection refused
    Is the server running on host "127.0.0.1" and accepting
    TCP/IP connections on port 5432?
    

    在推送期间发出,因为默认情况下 Rails 会启动以预编译资产,其中一部分是 Rails 试图连接到数据库。在构建期间,您的应用程序配置不存在,因此 Rails 尝试回退到使用 localhost 的默认设置(不存在)。

    有几种方法可以阻止这种情况发生。一种(推荐的方式)是设置

    config.assets.initialize_on_precompile = false
    

    在你的production.rb

    第二种方法是启用user-env-compile labs 功能,该功能将允许您的 PG 配置在构建时存在。

    $ heroku labs:enable user-env-compile -a <YOUR_APP_NAME>
    

    【讨论】:

      猜你喜欢
      • 2015-10-31
      • 2021-06-21
      • 1970-01-01
      • 2012-04-15
      • 2012-09-08
      • 2019-06-12
      • 2019-02-04
      • 2014-04-30
      • 1970-01-01
      相关资源
      最近更新 更多