Pre Provision Database
Last updated 07 March 2017
If your application tries to connect to the database on the first push it may not be able to if a database has not been added to your application yet.
If you are seeing an error like:
The driver encountered an unknown error: org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
could not connect to server: Connection refused Is the server running on host "127.0.0.1"
It is likely your application is trying to connect to a database that has not been provisioned on your application.
Provision a database
To avoid this error first provision a database
$ heroku addons:create heroku-postgresql Adding heroku-postgresql on blooming-refuge-2596... done, v4 (free) Attached as HEROKU_POSTGRESQL_CRIMSON_URL. Database has been created and is available ! This database is empty. If upgrading, you can transfer ! data from another database with pgbackups:restore. Use `heroku addons:docs heroku-postgresql` to view documentation.
Note: you will see a different app name and a different “color” url instead of
You can verify the database was added to your application by running:
$ heroku config DATABASE_URL: postgres://<username>:<password>@ec2-54-204-31-33.compute-1.amazonaws.com:5432/<db_name> HEROKU_POSTGRESQL_CRIMSON_URL: postgres://<username>:<password>@ec2-54-204-31-33.compute-1.amazonaws.com:5432/<db_name>
You can now try pushing your application again
$ git push heroku master
You should not get the same error message.
You may wish to have multiple databases to use as followers or to shard your data. That is why each database has a different “color”, to differentiate different databases. The primary database your application will use is stored in
DATABASE_URL. If you wish to promote a different database to your primary you can use the pg:promote command.