psql: could not connect to server... Is the server running on host ... and accepting TCP/IP connections on port 5432?

3

I know this is a popular question. I have tried everything suggested in similar threads. I am trying to connect remotely to a postgresql database on an azure windows server 2012 machine. I have tried the following...

postgresql.conf

listen_addresses = '*'

pg_hba.conf

# IPv4 local connections:
host    all             all             0.0.0.0/0            md5

Firewall

New inbound rule (firewall) protocols and ports > protocol type > TCP

Local port > 5432 Remote port > All

Grab IP of remote machine

I copied from azure dashboard and also as indicated on top of remote desktop connection

enter image description here

CMD from local machine

Then from local machine tried the following.

psql -U postgres -h 13.xx.xx.xx 

Error message.

psql: could not connect to server: Connection timed out (0x0000274C/10060) Is the server running on host "13.xx.xx.xx" and accepting TCP/IP connections on port 5432?

I am not sure what else should be done.

postgresql
azure
tcp
azure-virtual-machine
asked on Stack Overflow Jan 13, 2018 by Noah Huntington • edited Jan 15, 2018 by Shui shengbao

1 Answer

3

After you modify configuration file, you need restart it. You could use netstat -ant|findstr 5432 to check it. It should listen like below:

C:\Users\shui>netstat -ant|findstr 5432
  TCP    0.0.0.0:5432           0.0.0.0:0              LISTENING       InHost
  TCP    [::]:5432              [::]:0                 LISTENING       InHost

It seems a firewall issue. You need open port 5432 on Azure NSG.

enter image description here

I test in my lab, it works for me.

enter image description here

answered on Stack Overflow Jan 15, 2018 by Shui shengbao

User contributions licensed under CC BY-SA 3.0