port
port
is a configuration parameter determining which TCP/IP port the server should listen on.
port
was added in PostgreSQL 7.1.
Usage
The provided port must be in the range 1
and 65535
. Note that depending on operating system and configuration, not all port ranges may be available to the system user under which PostgreSQL runs.
The provided port number is also used when determining the unix socket name.
PostgreSQL can only listen on one port, so it is not possible to provide multiple values.
Default value
The default value for port
is: 5432
.
Change history
- PostgreSQL 7.1
- added (commit 6a68f426)
Examples
At startup, PostgreSQL will report the addresses
and port it is listening on in the log:
[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
It is not possible to provide multiple ports:
postgres=# ALTER SYSTEM SET port=5432,5433; ERROR: SET port takes only one argument postgres=# ALTER SYSTEM SET port='5432,5433'; ERROR: invalid value for parameter "port": "5432,5433"
If multiple ports are provided in the configuration file, the server will fail to start or restart with a message similar to the following:
waiting for server to start....2022-08-20 00:18:11.565 GMT [19024] LOG: syntax error in file "/var/lib/pgsql/postgresql.conf" line 3, near token ","
References
- PostgreSQL documentation: port