2

I am having the following contents in a database.yml

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

However on a git push heroku master, I am getting the following error.

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?

Do I need changes for other environments as well?

4
  • Please remove DATABASE_URL from the database.yml Commented Jul 18, 2013 at 6:54
  • I have added it only after getting the error earlier, but without any change in error Commented Jul 18, 2013 at 6:55
  • you got the error while git push so can you please paste the total errors which you got while git push heroku master Commented Jul 18, 2013 at 6:58
  • 1
    Please also check stackoverflow.com/questions/16124490/… and also check config.assets.initialize_on_precompile = false Commented Jul 18, 2013 at 7:00

3 Answers 3

3

heroku autogenerates database.yml on the deploy.

You need to .git ignore database.yml

You may choose another database by setting the ENV['DATABASE_URL'] (use heroku config:add DATABASE_URL=....)

For more information please check the heroku documentation

Sign up to request clarification or add additional context in comments.

Comments

0

DATABASE_URL is not required. Or you can check this one http://railsapps.github.io/rails-heroku-tutorial.html

1 Comment

Please see our comments
0

This error

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?

is emitted during push, because be default Rails will spin up to precompile assets, and part of that is Rails trying to connect to the database. During build time, your application configuration is not present, hence why Rails tries to fall back to the default of using localhost (which doesn't exist).

There's a couple of ways to stop this happening. One (the recommended way) is to set

config.assets.initialize_on_precompile = false

in your production.rb.

A second way, is to enable the user-env-compile labs feature that will allow your PG config to exist at build time.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.