Skip to content

hostname

Get the server host name

pg_hostname · Get the server host name

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100233hostnamepg_hostname1.0.0UTILPostgreSQLC

PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18

Usage

Sources:

hostname provides one function, hostname() RETURNS text, that returns the operating-system host name visible to the PostgreSQL server process. It identifies the database server or container, not the client host and not necessarily a DNS-qualified or cluster-unique name.

Core Workflow

CREATE EXTENSION hostname;

SELECT hostname();

The C function calls the POSIX gethostname API and returns NULL if that call fails. The extension is relocatable and requires a POSIX platform with <unistd.h>.

Interpretation and Versioning

In containers, Kubernetes pods, failover clusters, and cloned hosts, the returned value can change across restarts or role transitions. Do not use it as a durable node identifier, security boundary, or routing source without comparing it to infrastructure metadata. The function is declared IMMUTABLE, so PostgreSQL may fold repeated calls within a planned expression even though an administrator can change the operating-system hostname.

The SQL extension version remains 1.0.0, while the upstream package/PGXN distribution is 1.0.4 at the pinned source revision. That is a packaging release difference rather than a new SQL extension version. Current upstream documentation supports PostgreSQL 9.0 or later and documents PostgreSQL 18 extension-path settings for custom install prefixes.

Table reader