5
Connecting to a Server
1. The lines of pg_hba.conf are searched from top to bottom
2. The first line that corresponds to the provided connection
settings (type, database, user, address) will be used
# TYPE DATABASE USER ADDRESS METHOD
local all postgres peer
local all all peer
host all all 127.0.0.1/32 scram-sha-256
host all all ::1/128 scram-sha-256
local — socket all — any role
host — TCP/IP role name
all — any DB all — any IP
database name IP/mask
domain name
listen_addresses
For each new client, the server has to evaluate whether a database
connection should be allowed. Connection settings are defined in the
pg_hba.conf configuration file (hba stands for host-based authentication).
As with the main configuration file (postgresql.conf), changes come into
effect only after the server reloads this file, either via the pg_reload_conf()
SQL function or the reload command of the management utility.
When a new client appears, the server reads the configuration file from top
to bottom to find the line that matches the requested connection. The match
is defined by four fields: connection type, database name, user name, and
IP address.
Here we list only the main basic options.
Connection: local (unix sockets) or host (a TCP/IP connection).
Database: all (corresponds to any database) or the name of a particular
database.
User: all or the name of a particular role.
Address: all, IP address range, or a domain name. The address is omitted
for the local connection type. By default, PostgreSQL listens only for
connections coming from localhost; the listen_addresses parameter is
usually set to * (listen on all interfaces), while the access is controlled using
pg_hba.conf settings.