Reference: StackOverflow Answer by Me.
It is a 3 step process to connect to a PostgreSQL server remotely.
1. Enable Remote Listening
PostgreSQL listens on localhost by default. To accept remote connections, edit /etc/postgresql/X.X/main/postgresql.conf:
listen_addresses = '*'
2. Relax Access Controls
Allow incoming connections by editing /etc/postgresql/X.X/main/pg_hba.conf:
# TYPE DATABASE USER ADDRESS METHOD
host all all 0.0.0.0/0 md5
Note: 0.0.0.0/0 allows any IP. For better security, restrict to your specific client IP/subnet.
3. Restart PostgreSQL
Apply the changes:
sudo service postgresql restart