Dial tcp connect: connection refused

I am trying to connect Postrgre with following setting:

  1. localhost:5432
  2. Database: database_1
  3. User: postgres
  4. pwd:
  5. SSL Mode: disable
    and getting following error:
    dial tcp connect: connection refused

Can someone please help.


Well, do you have a Postgres server running on localhost and listening on port 5432?

You can verify the connectivity using another Postgres client and go back to trying to connect from Grafana once you’ve confirmed that. Maybe you’ve already taken such other troubleshooting steps, but none were mentioned in your question.

  • Have the same problem as mentioned :frowning_face:.
  • I can connect to Postgres through the command line (psql, port 5432, ssl disabled).
  • Grafana simply refuses to recognise the data source.


It appears that I had to specify the docker host IP address instead.

ip add

3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN > group default
link/ether 02:42:e1:c9:03:b7 brd ff:ff:ff:ff:ff:ff
inet brd scope global docker0

I then specified the IP address and all was fine :slight_smile:


1 Like

If your container is running on Windows or MacOS then you should also be able to access the docker host’s network at the domain name host.docker.internal.


Thank you!
Your comment also helped me connecting to db from golang.

const ( // DB connection info
host = “host.docker.internal”
port = 5432
user = “postgres”
password = “postgresPass”
dbname = “postgres”

Thanks, Docker IP helped me :slight_smile:

same problem, Sir. I do not use docker. Should I really need to use docker to get rid of that error?

No, the problem was caused by the docker install, the solution was how to fix a docker problem.
Tell us more about your setup.

Had the same problem on Win10. putting host.docker.internal as host solved my problem.
Followed instruction below:

Same problem here…

  • Don’t use docker
  • PostgreSQL runs local on my machine
  • tried localhost:5432 and
    error: dial tcp connect: connection refused

has anyone found another solution yet??


as @rostislaved said. I was trynig to connect to postgres from golang and this is what solved it.
Thank you @fcnz !

Curious to know if there’s a solution. Brand new install, trying to connect a local Postgresql as data source, getting same error. I’ve tried most things related to pg_hba.conf and postgresql.conf I’ve found online and no dice.