Getting error when adding PostgreSQL as data source in Grafana

I am not able to add PostgreSQL as data source in Grafana,
I have installed Grafana using Docker… And installed PostgreSQL as a normal software (NOT through Docker)
So Is it possible to add PostgreSQL as data source?

And What should be filled in the Host field?
I am getting error while adding, Please help

I’ll assume that you’re trying to run Grafana and PostgreSQL on your local machine. If that’s not the case, could you share more details on your setup?

An application running in a Docker container typically can’t connect to services running on the host machine (the machine running Docker itself).

I’d recommend running both Grafana and PostgreSQL in Docker containers, or install them both on the host machine, as normal software as you put it.

If you end up installing both on your host machine, you can connect to PostgreSQL with the hostname http://localhost:5432 (or whatever port you’ve configured PostgreSQL to use).

If you run both as Docker containers, it’s a little more trickier, as you need to create the network to connect them yourself.

Feel free to let me know which works best for you and I’ll help you with the next steps.

Thank you for responding,
1.Yes I have both Grafana and PostgreSQL in my local machine
2.So you say that my Grafana which is Docker Container and PostgreSQL which is NOT a docker container(normal Software) both cant be connected?
3. You suggest me to install both as a normal software(NOT as Docker container)?
4. If yes then I should enter “http://localhost:5432” in Host field of Grafana Settings page-(where we enter PostgreSQL details while adding data source)? and also please tell what to select for SSL mode?

  1. If the container was able to access the host machine, this would be a major security flaw.
  2. I believe this is the simplest option.
  3. Yes. If you’re only using PostgreSQL to develop locally, and you don’t care about security, you can set SSL mode to disable.

If you end up deciding on instead running both as Docker container, you should read up on connecting them with a network.

1 Like

Thank you, Its working now after following steps provided by you :slight_smile:

1 Like