INET_SERVER_ADDR

Return the IP address of the server that accepted the current session.

Category: miscReturns: STRINGDialect: PostgreSql

Syntax

INET_SERVER_ADDR()

Description

## Overview Returns the IP address of the server that accepted the current session, as a string. Use this function for diagnostics in multi-node deployments where identifying the specific compute node that served a query is useful for tracing and performance investigation. Returns NULL when the connection is local or when the address is otherwise unavailable. ## Session context - The value is fixed at connection establishment and does not change during the session. - Takes no arguments. - Returns NULL for local (non-IP) connections. ## Behavior - Returns a STRING containing either an IPv4 or IPv6 address. - Deterministic for the duration of the session. - Side effect free. ## Compatibility - PG-compat alias for `inet_server_addr` function.

Examples

-- Read the server IP
SELECT INET_SERVER_ADDR();
-- Identify which compute node is handling the session
SELECT INET_SERVER_ADDR() AS server_ip, PG_BACKEND_PID() AS pid;
-- Compare client and server addresses in an audit row
SELECT INET_CLIENT_ADDR() AS client, INET_SERVER_ADDR() AS server;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →