Failure to connect to PostgreSQL installed in portainer on a server from my local pC

165 views Asked by At

I have synology DS920 at home connecter to my router. I installed portainer (container management) and started a container for PostgreSQL. From pgAdmin 4 I can see and access my database (for instance I can run a query SELECT version(); and get an answer). My problem is the access from my local PC. I would like to use psycopg2 but I am running into a few errors...

import psycopg2

conn = psycopg2.connect(
    host="localhost",
    database="Test",
    user="***",
    password="***"
)

I tried using localhost as host but that fails since the database is in a container on a server, so not on my local machine. I tried to use the IP of my server but I get the following error message (same error message as in the case of localhost):

psycopg2.OperationalError: connection to server at "x.x.x.x", port 5432 failed: Connection refused (0x0000274D/10061) Is the server running on that host and accepting TCP/IP connections?

What host should be used? With portainer I have access to the containers IP Address (one container for pgAdmin, one for portainer and one for PostgreSQL). I tried all three and the one for PostgreSQL (which is publishing on ports 2665:5432) and I get the same error message:

psycopg2.OperationalError: connection to server at "x.x.x.x", port 5432 failed: Connection timed out (0x0000274C/10060) Is the server running on that host and accepting TCP/IP connections?

Besides the host, where can I see the list of users allowed to access the database? is there anything I should change in the postgresql.conf file? I am using listen_addresses = '*'

1

There are 1 answers

0
Hotone On

Well after many attempts I figured out that I needed to specify the port that I should be listening to (2665 and not the 5432 port being used by default). As host I used the IP address of my server.