listen_addresses

A server parameter determining the TCP/IP addresses to listen on

listen_addresses is a configuration parameter determining which TCP/IP address or addresses the server should listen on.

listen_addresses was added in PostgreSQL 8.0.

Usage

listen_addresses can consist of a comma-seperated list containing one or more of the following elements:

  • a hostname
  • an IP address (IPv4 and IPv6)
  • 0.0.0.0 to indicate the server should listen on all IPv4 addresses
  • :: to indicate the server should listen on all IPv6 addresses
  • * to indicate the server should listen on all available addresses

If listen_addresses is set to an empty string, the server will not listen on any IP interface, and connections will only be possible via Unix-domain sockets.

If listen_addresses contains multiple values, they will be evaluated in the order they were provided. If a later value conflicts with a previous value, making it impossible to bind to the specified address, a LOG entry will be emitted. For example, if listen_addresses is set to 127.0.0.1,*, PostgreSQL will bind to 127.0.0.1 but no other IPv4 addresses (but will bind to all IPv6 addresses, if available). See example below.

Default value

The default value for listen_addresses is: localhost.

Change history

Examples

Log entries when listen_addresses is set to *:

[2022-08-20 08:28:43 UTC]    LOG:  00000: listening on IPv4 address "0.0.0.0", port 5432
[2022-08-20 08:28:43 UTC]    LOG:  00000: listening on IPv6 address "::", port 5432
[2022-08-20 08:28:43 UTC]    LOG:  00000: listening on Unix socket "/tmp/.s.PGSQL.5432"
[2022-08-20 08:28:43 UTC]    LOG:  00000: database system was shut down at 2022-08-20 08:28:43 UTC
[2022-08-20 08:28:43 UTC]    LOG:  00000: database system is ready to accept connections

Log entries when listen_addresses is set to 127.0.0.1,*:

[2022-08-20 09:13:42 UTC]    LOG:  00000: listening on IPv4 address "127.0.0.1", port 5432
[2022-08-20 09:13:42 UTC]    LOG:  XX000: could not bind IPv4 address "0.0.0.0": Address already in use
[2022-08-20 09:13:42 UTC]    HINT:  Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
[2022-08-20 09:13:42 UTC]    LOG:  00000: listening on IPv6 address "::", port 5432
[2022-08-20 09:13:42 UTC]    LOG:  00000: listening on Unix socket "/tmp/.s.PGSQL.5432"
[2022-08-20 09:13:42 UTC]    LOG:  00000: database system was shut down at 2022-08-20 09:13:42 UTC
[2022-08-20 09:13:42 UTC]    LOG:  00000: database system is ready to accept connections

Categories

Connection management, GUC configuration item

See also

port, inet_server_addr()