How to connect remotely to the Postgres DB on the server from the local/client machine?

May 26, 2015 3.7k views
PostgreSQL DigitalOcean

Hi! Can someone explain how to enable remote connection (from my local/client machine) to the the Postgres db which I set on the server?

First, I got this couldn't connect to server connection refused. Then I tried to edit configurations in


by adding this:

host    all             all           trust

and changing 'localhost' in




Still was no result:

sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
2 Answers

Did you restart postgres after the change? If so, install lsof and check lsof -i :5432 -n.

  • Yes I restarted.
    sudo service postgresql restart

    What is lsof and what should I see there?

  • Ok. Solved. I have not noticed that listen_addresses='*' was commented with # by default... crazy.

Have another answer? Share your knowledge.