Search code examples
ruby-on-railsrubyheroku

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

Solution

  • See this article. The solution is to set

    config.assets.initialize_on_precompile = false