Heroku pg: psql not working

I tried to connect to Postgres database for my heroku application by running "heroku pg: psql" command 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 connect to my database correctly. Thanks in advance!

+3


source to share


2 answers


Try the following:



heroku pg:psql DATABASE_URL

      

0


source


As already hinted at using DATABASE_URL, there are a few more things to consider.

If you have multiple applications on Heroku, it is always a good idea to specify which application you want to connect to where the database is added. The same applies if you have multiple databases to specify the DB name (if it is something other than the default DATABASE_URL).

Some connection examples:

-- 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 should be kept in mind, as stated here https://devcenter.heroku.com/articles/heroku-local#copy-heroku-config-vars-to-your-local-env-file :

Be aware that your deployed production application may connect to different services than your local development application. For example, your deployed production application may have a DATABASE_URL configuration that references the Heroku Postgres database, but your local application may have a DATABASE_URL in a .env file that references your local Postgres installation.

Heroku guideline - https://devcenter.heroku.com/articles/heroku-postgresql#pg-psql (but it does little to explain cases with multiple databases and multiple applications).

Heroku Guideline for Connecting Outside - https://devcenter.heroku.com/articles/connecting-to-heroku-postgres-databases-from-outside-of-heroku

0


source







All Articles