inet_server_port()

A system function returning the server IP port

inet_server_port() is a system function which returns the IP port which the current client is connected to.

inet_server_port() was added in PostgreSQL 8.0.

Usage

inet_server_port () → integer

inet_server_port() is called without any arguments, and returns the client IP address as an integer, or NULL if the current connection is via a Unix-domain socket.

Known bug

In PostgreSQL 13 and earlier, inet_server_port() will always return NULL if executed by a parallel worker. This has been fixed for PostgreSQL 14 (commit 5a6f9bce), but has not been backpatched to earlier versions.

Change history

Examples

Example output when connected via TCP/IP:

postgres=# SELECT inet_server_port();
 inet_server_port 
------------------
             5433
(1 row)

Example output when connected via a Unix-domain socket:

postgres=# SELECT inet_server_port();
 inet_server_port
------------------

(1 row)

Categories

System function

See also

inet_server_addr(), inet_client_port()