DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Connections and Authentication / Connection Settings

port

Sets the TCP port the server listens on.

  • Default: 5432
  • Type: integer
  • Range: 1 … 65535
  • Applies: Restart required

In plain words

The port number clients use to reach this server, 5432 by default. The same number is also part of the local socket file name, .s.PGSQL.5432.

Running several PostgreSQL clusters on one machine works by giving each a different port.

For DBAs and operators

One port is used for all addresses in listen_addresses, and the Unix-domain socket in each unix_socket_directories entry is named .s.PGSQL.<port> (plus a .s.PGSQL.<port>.lock file). A client that connects through the socket must therefore use the same port number (psql -p 5433), even though no TCP is involved.

If the port is busy at startup the server refuses to start: LOG: could not bind IPv4 address "127.0.0.1": Address already in use followed by FATAL: could not create any TCP/IP sockets (or, for the socket file, FATAL: lock file "/var/run/postgresql/.s.PGSQL.5432.lock" already exists).

Debian/Ubuntu packages assign 5432, 5433, … to each cluster created with pg_createcluster; pg_lsclusters shows the mapping. Connection poolers (PgBouncer, often 6432) listen on their own port and forward to this one. Clients default to the PGPORT environment variable or the port compiled into libpq, which is a common source of "wrong cluster" confusion when several versions are installed.

How to change it

Change in postgresql.conf or ALTER SYSTEM, then restart the server.

See it in context

Postmaster Wire protocol Server startup sequence

Related parameters

listen_addresses unix_socket_directories

All Connections and Authentication parameters