inet_server_addr()

A system function returning the server IP address

inet_server_addr() is a system function which returns the IP address which the current client is connected to.

inet_server_addr() was added in PostgreSQL 8.0.

Usage

inet_server_addr () → inet

inet_server_addr() is called without any arguments, and returns the server IP address as the inet data type, or NULL if the current connection is via a Unix-domain socket.

Known bug

In PostgreSQL 13 and earlier, inet_server_addr() 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_addr();
 inet_server_addr
------------------
 10.11.9.1
(1 row)

Example output when connected via a Unix-domain socket:

postgres=# SELECT inet_client_addr();
 inet_server_addr
------------------

(1 row)

Categories

System function

See also

inet_server_port(), inet_client_addr()