Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 731
Euphe Avatar asked Nov 24 '13 13:11

Euphe


3 Answers

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

like image 129
Seliestel Avatar answered Nov 14 '22 08:11

Seliestel


See this article. The solution is to set

config.assets.initialize_on_precompile = false
like image 4
Simone Carletti Avatar answered Nov 14 '22 09:11

Simone Carletti


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)

like image 1
rassom Avatar answered Nov 14 '22 09:11

rassom