If PostgreSQL is set to only listen and allow connections from localhost (127.0.0.1) then you can change the configuration to allow other or all IP addresses to connect.

First we will need to make sure PostgreSQL is listening for connections outside of local networking in the main configuration, which should be located somewhere such as /etc/postgresql/9.x/main/postgresql.conf (where 9.x is whichever version you have installed) so just uncomment the listen addresses line

However to make sure that the IP address you’re connecting from is also allowed you’ll need to change /etc/postgresql/9.x/main/pg_hba.conf to either add each IP address or set it to all (0.0.0.0)

Depending on your operating system you will need to restart the PostgreSQL server (for example service postgresql restart)