Unable to connect to PostGreSQL database on Ubuntu server


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!

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.