heroku pg:psql not working

5

I tried to connect to the Postgres database for my app on heroku by running the command "heroku pg:psql" and got the following error message:

psql: could not connect to server: Connection timed out (0x0000274C/10060)
    Is the server running on host "URL.com"(IP address)  and accepting
    TCP/IP connections on port 5432?

I also tried to connect using Pgadmin and get the error:

Server doesn't listen. Is the server running on host "URL.com" (IP address) and accepting
    TCP/IP connections on port 5432?

Can anyone tell me how to fix these errors and correctly connect to my database. Thanks in advance!

heroku
asked on Stack Overflow Jan 22, 2013 by Long Wan • edited Apr 13, 2017 by Community

2 Answers

2

Try this:

heroku pg:psql DATABASE_URL
answered on Stack Overflow Oct 13, 2016 by Yoni Rabinovitch
0

As started to hint already using DATABASE_URL there are few more things to consider.

If you have multiple apps in Heroku it is always good to specify to what app you want to connect to where DB is added. Same applies if you have multiple databases to specify DB name (if it is something else than default DATABASE_URL).

Some examples how to connect:

-- Defining to what DB and app you want to connect to:
heroku pg:psql [lower case generated name] -a myapp
heroku pg:psql [lower case generated name] --app myapp
heroku pg:psql HEROKU_POSTGRESQL_[upper case generated name]_URL -a myapp

-- This will fall back to default DATABASE_URL part of your app:
heroku pg:psql -a myapp

Also to keep in mind as said here https://devcenter.heroku.com/articles/heroku-local#copy-heroku-config-vars-to-your-local-env-file:

Keep in mind that your deployed production app may be connecting to different services than your local development app. For example, your deployed production app might have a DATABASE_URL config var that references a Heroku Postgres database, but your local app might have a DATABASE_URL variable in the .env file that references your local installation of Postgres.

Heroku guideline – https://devcenter.heroku.com/articles/heroku-postgresql#pg-psql (but it explains little about multi-database and multi-apps cases).

Heroku guideline for connecting externally - https://devcenter.heroku.com/articles/connecting-to-heroku-postgres-databases-from-outside-of-heroku

answered on Stack Overflow Oct 13, 2016 by Kristo Mägi

User contributions licensed under CC BY-SA 3.0