The default configuration after installing PostgreSQL 9.4 only allows localhost tcp connections, or using Unix domain sockets. This isn't sufficient when setting up a database server separate from the app server.
- Open
/etc/postgresql/9.4/main/postgresql.conf
and look for thelisten_addresses
setting. The default islocalhost
. Change it to*
.
Authentication methods are controlled by the /etc/postgresql/9.4/main/pg_hba.conf
file.
TO allow another host to connect, add a line allowing its IP address. It is also possible to specify a range of addresses with a subnet.
For example,
host db_name username 192.168.15.1/32 md5
See PostgreSQL's documentation on pg_hba.conf for more details.
If md5
authentication is set, the user must have a password. This can be done with the following command.
ALTER ROLE username WITH PASSWORD 'password';