Postgres Setup
Remote Access
For accessing the postgres database from outside the host or from a docker container on the host, you must setup the Postgres instance to listen on a network adapter other than localhost.
To do this, locate the postgresql.conf file in: /etc/postgresql/xx/main.
Locate the line with: “listen_addresses”.
Uncomment it, and set it to listen to a particular network address or “*” for all network addresses.
Like this:
Next, you will need to add an entry to the pg_hba.conf (same folder as previous), for the subnet or host that will gets access to the postgres database.
Adding entries to this file allows incoming access. For example, the following host entry, allows access from the 172.17.0.0/16 subnet. This subnet happens to be the docker subnet on the example host.
NOTE: The above example has two entries added. This is necessary if your remote host is in a different network, such as a docker network. For example, the above two entries say that 10.116.0.2/32 is the source of connections, that originate from a remote network of 172.17.0.0/16.
Once those two config files are updated, you need to restart the postgres intance for the changes to take effect:
sudo service postgresql restart
You can now test access to the postgres instance, with this command:
psql --username=postgresclient --dbname=dbprojectcontrols --host=10.116.0.2 --port=5432