在Heroku上从Mysql切换到postgres之后如何连接到pg; PG连接拒绝了

时间:2015-03-03 17:07:28

标签: ruby-on-rails postgresql heroku

我将我的rails 4.2应用程序从mysql切换到Heroku上的postgres。切换后一切正常,并且在postgre上完美运行但是当我尝试在Heroku上进行迁移时,我得到以下消息:

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

我的Heroku Env变量是:

 HEROKU_POSTGRESQL_BLACK_URL:     postgres://bbczqezwwklzqp:1jBcxlGoibmUuriNufTTx2fFOk@ec2-54-163-248-144.compute-1.amazonaws.com:5432/dcit0akvuomjtr
 LANG:                           en_US.UTF-8
 NEW_RELIC_AGGRESSIVE_KEEPALIVE: 1
 NEW_RELIC_LICENSE_KEY:          aaca6674945ff7f7f542e6db625cb7a509ad7746
 NEW_RELIC_LOG:                  stdout
 PAPERTRAIL_API_TOKEN:           Ckbl776aK5kMKkml7K41
 RACK_ENV:                       staging
 RAILS_ENV:                      staging
 SECRET_KEY_BASE:                3d21b4717dc1755ea7c924b6ad6e3d8770b0099b4d87892dbebd92b6f7b1c287831fd564115de2650bdf7339c472e7dd83a4b56ab6567863d9885f2097709065

我的database.yml是:

 development: &default
   adapter: postgresql
   database: lawgix_development
   encoding: utf8
   host: localhost
   min_messages: warning
   pool: 2
   timeout: 5000

 test:
   <<: *default
   database: lawgix_test

 staging:
   <<: *default
   database: lawgix_staging

 production:
   <<: *default
   database: lawgix

1 个答案:

答案 0 :(得分:0)

您似乎需要在Heroku中配置DATABASE_URL env变量。如果没有这个,Rails会回到你的database.yml并尝试localhost中的不存在的数据库

您可以尝试以下命令:

 heroku pg:promote HEROKU_POSTGRESQL_BLACK_URL

或者只是将其定义为自己模仿HEROKU_POSTGRESQL_BLACK_URL