Timeout Errror when trying to connect to postgresql server through a python script.

Hey , i’ve been running a discord bot script on my digital ocean droplet(ubuntu 16.04) for going on 3 years now. Recently i’ve been trying to rewrite it to a newer library but for whatever reason my postgresql connect command consistently throws a Timeout Error when i try to run it from my desktop. However the same script running on the vps itself works perfectly fine for some reason.

This would lead me to think that it’s a firewall error however i have double checked and my sql server port is forwarded which is also evidenced by the fact that i can consistently use PGAdmin to view the database from my desktop.

Another point of notice is that sometimes my droplet starts acting up where even ssh’ing into it using putty times out and i have to try a handful of times before i can get in which makes me guess that it’s a digital ocean side issue ?

I have checked my internet connection and it’s stable so that’s not the issue either. I’m fairly confused about this as i’ve never had any troubles in the 3 years i’ve been using DO before this ; any insight and help is appreciated.

This is the exact error my script raises on my desktop. TimeoutError: [Errno 10060] Connect call failed (‘my ip’, 5432)

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.

Hi there @AAnsari1998,

I believe that you would need to enable remote connections on PostgreSQL server. To do that you need to edit your pg_hba.conf configuration file and add the following:

host  all  all your_home_ip_address_or_range/32  md5

After that change:

listen_addresses = 'localhost'


listen_addresses = '*'

And finally, restart your PostgreSQL service.

Also as you mentioned, make sure that port 5432 is open for TCP connections from your IP address.

Hope that this helps! Regards, Bobby