1

I am setting up a server that has more than one Postgres cluster running. By default, I set the main postgres cluster (the one whose default port is 5432) to not start automatically with the computer. I set, instead, two other Postgres clusters to start, one at port 5433 and the other at 5434.

All seems to be working perfectly fine, with one critical exception: I can't login to those clusters remotely. That is, when I try:

psql -h [my server ip] -p 5433 -U myusername -d mydatabase

I get:

psql: could not connect to server: Connection refused Is the server running on host "[my server IP here]" and accepting TCP/IP connections on port 5433?

Now, I know that past questions have been already asked on this issue. See for instance: "psql: could not connect to server: Connection refused" Error when connecting to remote database

However, I did follow all possible steps I found online. Let's see. All my Postgres clusters have their postgresql.conf already with listen_addresses = '*' (uncommented). Similarly, all my clusters' pg_hba.conf have host all all 0.0.0.0/0 md5 and host all all all md5.

I did open ports 5432, 5433 and 5434 with:

sudo ufw allow 5432/tcp
sudo ufw allow 5433/tcp
sudo ufw allow 5434/tcp

And I did restart the postgres services. In fact, I restarted the whole server machine. So now when I run sudo netstat -ltpn | grep "postgres" I get, for instance, for cluster at port 5433:

tcp      0      0 0.0.0.0:5433     0.0.0.0:*              LISTEN      3227/postgres
tcp6     0      0 :::5433          :::*                   LISTEN      3227/postgres

Still, remote connection to the Postgres cluster is not possible and throws the above mentioned error. What else can I try?

Juddy
  • 329
  • 1
  • 2
  • 7
  • Have you tried simple 'ping ? and 'telnet 5333'? In short, are you sure you can establish a TCP/IP connection from your machine to the DB server? – GMichael Jun 25 '19 at 11:40
  • @GMichael pinging works, but you were right to suggest `telnet`: I get 'Unable to connect to remote host: Connection refused'. I have no idea why, since 5432, 5433 and 5434 are already opened. – Juddy Jun 25 '19 at 17:28
  • It might be that the PG host does not allow incoming connection from your machine. I would completely disable UFW on the DB server (sudo ufw disable) and try again. If it works, try configuring other UFW things, like 'sudo ufw allow from ' – GMichael Jun 26 '19 at 07:48

0 Answers0