Reputation: 113
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..
Upvotes: 10
Views: 10152
Reputation: 1
Try docker network ls
and then inspect the network on which your container is running (for me it was bridge)
Then, run docker network inspect postgres_container_network_name
It will show the "IPv4Address": "172.xx.x.x/16" for that container, try using that in Grafana Datasource as host:port
Upvotes: 0
Reputation: 1003
On my setup, Grafana and postgreSQL run on the same machine.
Connection worked only if I used
127.0.0.1:2345
and it did not work with the local IP of the machine! (192.168.x.x:2345
).
Upvotes: 1
Reputation: 6950
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:
Upvotes: 8
Reputation: 1438
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
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
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
Upvotes: 1