Skip to content

Instantly share code, notes, and snippets.

@fonglh
Created November 18, 2015 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fonglh/ee5127ccdcdcd3295f23 to your computer and use it in GitHub Desktop.
Save fonglh/ee5127ccdcdcd3295f23 to your computer and use it in GitHub Desktop.
Configuring PostgreSQL for Remote connections

Configuring PostgreSQL to accept Remote Connections

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.

Enable listening on Network Interface

  1. Open /etc/postgresql/9.4/main/postgresql.conf and look for the listen_addresses setting. The default is localhost. Change it to *.

Allow Remote Authentication

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.

Set a Database User Password

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';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment