Home Explore Blog CI



postgresql

17th chunk of `doc/src/sgml/libpq.sgml`
e7aa0aed187de7c5f02cec1f60f1a3a6ec27d068224f624b0000000100000fa1
 linkend="libpq-multiple-hosts"/> for details.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry id="libpq-connect-hostaddr" xreflabel="hostaddr">
      <term><literal>hostaddr</literal></term>
      <listitem>
       <para>
        Numeric IP address of host to connect to.  This should be in the
        standard IPv4 address format, e.g., <literal>172.28.40.9</literal>.  If
        your machine supports IPv6, you can also use those addresses.
        TCP/IP communication is
        always used when a nonempty string is specified for this parameter.
        If this parameter is not specified, the value of <literal>host</literal>
        will be looked up to find the corresponding IP address &mdash; or, if
        <literal>host</literal> specifies an IP address, that value will be
        used directly.
       </para>

       <para>
        Using <literal>hostaddr</literal> allows the
        application to avoid a host name look-up, which might be important
        in applications with time constraints. However, a host name is
        required for GSSAPI or SSPI authentication
        methods, as well as for <literal>verify-full</literal> SSL
        certificate verification.  The following rules are used:
        <itemizedlist>
         <listitem>
          <para>
           If <literal>host</literal> is specified
           without <literal>hostaddr</literal>, a host name lookup occurs.
           (When using <function>PQconnectPoll</function>, the lookup occurs
           when <function>PQconnectPoll</function> first considers this host
           name, and it may cause <function>PQconnectPoll</function> to block
           for a significant amount of time.)
          </para>
         </listitem>
         <listitem>
          <para>
           If <literal>hostaddr</literal> is specified without <literal>host</literal>,
           the value for <literal>hostaddr</literal> gives the server network address.
           The connection attempt will fail if the authentication
           method requires a host name.
          </para>
         </listitem>
         <listitem>
          <para>
           If both <literal>host</literal> and <literal>hostaddr</literal> are specified,
           the value for <literal>hostaddr</literal> gives the server network address.
           The value for <literal>host</literal> is ignored unless the
           authentication method requires it, in which case it will be
           used as the host name.
          </para>
         </listitem>
        </itemizedlist>
        Note that authentication is likely to fail if <literal>host</literal>
        is not the name of the server at network address <literal>hostaddr</literal>.
        Also, when both <literal>host</literal> and <literal>hostaddr</literal>
        are specified, <literal>host</literal>
        is used to identify the connection in a password file (see
        <xref linkend="libpq-pgpass"/>).
       </para>

       <para>
        A comma-separated list of <literal>hostaddr</literal> values is also
        accepted, in which case each host in the list is tried in order.
        An empty item in the list causes the corresponding host name to be
        used, or the default host name if that is empty as well. See
        <xref linkend="libpq-multiple-hosts"/> for details.
       </para>
       <para>
        Without either a host name or host address,
        <application>libpq</application> will connect using a local
        Unix-domain socket; or on Windows, it will attempt to connect to
        <literal>localhost</literal>.
       </para>
       </listitem>
      </varlistentry>

      <varlistentry id="libpq-connect-port" xreflabel="port">
       <term><literal>port</literal></term>
       <listitem>
       <para>
        Port number to connect to at the server host, or socket file
        name extension for Unix-domain
        connections.<indexterm><primary>port</primary></indexterm>
        If multiple hosts

Title: Host Address Parameter and Connection Behavior
Summary
This section elaborates on the 'hostaddr' parameter, used to specify the numeric IP address for connecting to the server. It details how using 'hostaddr' avoids host name lookups, which is useful in time-sensitive applications, but notes that a host name is necessary for certain authentication methods like GSSAPI and SSPI, as well as for SSL certificate verification. The rules for using 'host' and 'hostaddr' together or separately are explained. The section also discusses the use of comma-separated lists of 'hostaddr' values for trying multiple hosts and the behavior when neither 'host' nor 'hostaddr' is provided, which defaults to a local Unix-domain socket connection or localhost on Windows. Finally, it briefly introduces the 'port' parameter.