Unable to connect to PostGreSQL database on Ubuntu server

Posted October 24, 2019 5k views


Having a time trying to connect to a PostGreSQL database on Ubuntu 18.04 server.

Here is my:
postgresql.conf file :



host  all  all md5

firewall is currently disabled

here is the output when I did the command (saw in another thread to do this…):

sudo netstat -ltpnActive Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 *               LISTEN      608/systemd-resolve 
tcp        0      0    *               LISTEN      842/sshd            
tcp        0      0*               LISTEN      2922/postgres       
tcp        0      0    *               LISTEN      1055/master         
tcp        0      0    *               LISTEN      867/nginx: master p 
tcp6       0      0 :::22                   :::*                    LISTEN      842/sshd            
tcp6       0      0 :::25                   :::*                    LISTEN      1055/master         
tcp6       0      0 :::80                   :::*                    LISTEN 

I have restarted postgresql each time using the command ‘sudo service postgresql restart’.

I have tried to access the db using the python library psycopg2 on macOS and getting this error

could not connect to server: Connection refused
    Is the server running on host "<ip_address>" and accepting
    TCP/IP connections on port 5432?

What am I missing?

Thanks in advance!

edited by MattIPv4

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hello, @masonbaran

Can you see if you’re able to access the server on this port using telnet? The exact command on your MAC will be:

telnet IP 5432

Let me know how it goes.