简体   繁体   中英

Heroku Rails deploy fails with error “could not connect to server: Connection refused”

Everything works fine locally, but I get that error when I try to push to heroku:

Running: rake assets:precompile

  Connecting to database specified by DATABASE_URL rake aborted! 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? 

/tmp/build_1903c764-07ce-4d06-aa45-6e78dec68af8/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `initialize'

  /tmp/build_1903c764-07ce-4d06-aa45-6e78dec68af8/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/postgresql_adapter.rb:1216:in `new' 

... etc

I suspect it has to do something with database.yml, so here it is:

development:
  adapter: mysql2
  encoding: utf8
  database: dev-db
  pool: 5
  timeout: 5000
  socket: /tmp/mysql.sock

test:
  adapter: mysql2
  encoding: utf8
  database: test-db
  pool: 5
  timeout: 5000
  socket: /tmp/mysql.sock

production:
  adapter:  postgresql
  encoding: utf8
  database: prod-db
  pool: 5
  timeout: 5000
 # socket: /tmp/mysql.sock

It might be something related with the fact that you haven't pre-provisioned your database before pushing to heroku. At least, I had a similar error and I solved it by running:

heroku addons:create heroku-postgresql

You can verify the database was added to your application by running:

heroku config

And you can read all about this question here: https://devcenter.heroku.com/articles/pre-provision-database

See this article . The solution is to set

config.assets.initialize_on_precompile = false

I know this is solved, but for others who see this, you might have to promote the database (in case you created a new one, restored to a new one or similar):

heroku pg:promote HEROKU_POSTGRESQL_IVORY (replace IVORY)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM