Report this

What is the reason for this report?

Unable to connect to PostGreSQL database on Ubuntu server

Posted on October 24, 2019

Hi,

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

Here is my: postgresql.conf file :

port=5432
listen_addresses='*'

pg_hba.cong:

host  all  all 0.0.0.0/0 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 127.0.0.53:53           0.0.0.0:*               LISTEN      608/systemd-resolve 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      842/sshd            
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      2922/postgres       
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      1055/master         
tcp        0      0 0.0.0.0:80              0.0.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!



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!

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.

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.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.