How to do it…

By default, PostgreSQL gives access to clients who connect using Unix sockets, provided that the database user is the same as the system's username. Here, we'll show you how to enable other connections.

In this recipe, we mention configuration files, which can be located as shown in the Finding the current configuration settings recipe in Chapter 3, Configuration.

The steps are as follows:

  1. Add or edit this line in your postgresql.conf file:
listen_addresses = '*'
  1. Add the following line as the first line of pg_hba.conf to allow access to all databases for all users with an encrypted password:
# TYPE   DATABASE   USER        CIDR-ADDRESS   METHOD 
host all all 0.0.0.0/0 md5
  1. After changing listen_addresses, we restart the PostgreSQL server, as explained in the Updating the parameter file recipe in Chapter 3, Configuration.
This recipe assumes that postgresql.conf does not include any other configuration file, which is the case in a default installation. If changing listen_addresses in postgresql.conf does not seem to work, perhaps that setting is overridden by another configuration file. Check out the Updating the parameter file recipe in Chapter 3, Configuration, for more details.