1
0
mirror of https://github.com/postgres/postgres.git synced 2026-01-05 23:38:41 +03:00

psql: Show IP address in \conninfo

When hostaddr is given, the actual IP address that psql is connected to
can be totally unexpected for the given host.  The more verbose output
we now generate makes things clearer.  Since the "host" and "hostaddr"
parts of the conninfo could come from different sources (say, one of
them is in the service specification or a URI-style conninfo and the
other is not), this is not as silly as it may first appear.  This is
also definitely useful if the hostname resolves to multiple addresses.

Author: Fabien Coelho
Reviewed-by: Pavel Stehule, Arthur Zakirov
Discussion: https://postgr.es/m/alpine.DEB.2.21.1810261532380.27686@lancre
	https://postgr.es/m/alpine.DEB.2.21.1808201323020.13832@lancre
This commit is contained in:
Alvaro Herrera
2018-11-19 14:34:12 -03:00
parent 7ee5f88e65
commit 6e5f8d489a
6 changed files with 172 additions and 41 deletions

View File

@@ -1735,6 +1735,36 @@ char *PQhost(const PGconn *conn);
</listitem>
</varlistentry>
<varlistentry id="libpq-pqhostaddr">
<term>
<function>PQhostaddr</function>
<indexterm>
<primary>PQhostaddr</primary>
</indexterm>
</term>
<listitem>
<para>
Returns the server IP address of the active connection.
This can be the address that a host name resolved to,
or an IP address provided through the <literal>hostaddr</literal>
parameter.
<synopsis>
char *PQhostaddr(const PGconn *conn);
</synopsis>
</para>
<para>
<function>PQhostaddr</function> returns <symbol>NULL</symbol> if the
<parameter>conn</parameter> argument is <symbol>NULL</symbol>.
Otherwise, if there is an error producing the host information
(perhaps if the connection has not been fully established or
there was an error), it returns an empty string.
</para>
</listitem>
</varlistentry>
<varlistentry id="libpq-pqport">
<term>
<function>PQport</function>