Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to postgresql from grafana

Connecting to postgresql-11.5.1 from grafana is not working. I installed postgres on my local and created a grafana and trying to connect, but i get the usual error: dial tcp 127.0.0.1:5432: connect: connection refused am NOT using postgresql on docker, its just on my local on windows 10. because the answers that is available on stackoverflow is related to docker. Please help..

like image 864
Sakthi Avatar asked Nov 07 '22 14:11

Sakthi


2 Answers

In my case, I deployed Grafana locally with Docker and was attempting to use the Postgres plugin to connect to my local installation of Postgres. I had to use host.docker.internal as the host instead of localhost which was causing the same error:

enter image description here

like image 73
João Matos Avatar answered Nov 15 '22 05:11

João Matos


Grafana normal installation

Please do check these configuration files for Postgresql.

  • /etc/postgresql//main/postgresql.conf

  • /etc/postgresql//main/pb_hba.conf

Client authentication is maintained by making changes to pb_hba.conf. Make sure it has this line for local authentication.

 [TYPE]    [DATABASE]    [USER]    [ADDRESS]    [METHOD]

 host        all           all      127.0.0.1/32    md5

Grafana installed with docker

The Grafana instance now lives in a different network and Postgres will have a remote connection with it. By default, the local connection is available only. To enable remote,

sudo vim /etc/postgresql//main/postgresql.conf

Change #listen_addresses = 'localhost' to #listen_addresses = '*'.

Obtain docker bridge network interface info in your terminal by typing.

 ip addr

........

docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group 
 default 
    link/ether 02:42:da:5e:5e:95 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
      valid_lft forever preferred_lft forever
    inet6 fe80::42:daff:fe5e:5e95/64 scope link 
       valid_lft forever preferred_lft forever

Here inet 172.17.0.1/16 refers to

  • Network : 172.17.0.0/16
  • IP : 172.17.0.1

Allow this network 172.17.0.0/16 from your machine in pb_hba.conf.

 host    all             all             172.17.0.0/16           md5

Now, use the ip address (172.17.0.1) obtained from ip addr from your machine in place of localhost as Grafana data source address.

Reference

Allow docker container to connect to a local/host postgres database

https://blog.jsinh.in/how-to-enable-remote-access-to-postgresql-database-server/#.XXYs2HUvNuS

like image 21
Muhtasim Ulfat Tanmoy Avatar answered Nov 15 '22 05:11

Muhtasim Ulfat Tanmoy