Home Explore Blog CI



postgresql

18th chunk of `doc/src/sgml/libpq.sgml`
f9895dbc9361f49945f6dfc86874a02a08fdb1be67b878150000000100000fa0
 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 were given in the <literal>host</literal> or
        <literal>hostaddr</literal> parameters, this parameter may specify a
        comma-separated list of ports of the same length as the host list, or
        it may specify a single port number to be used for all hosts.
        An empty string, or an empty item in a comma-separated list,
        specifies the default port number established
        when <productname>PostgreSQL</productname> was built.
       </para>
      </listitem>
     </varlistentry>

     <varlistentry id="libpq-connect-dbname" xreflabel="dbname">
      <term><literal>dbname</literal></term>
      <listitem>
      <para>
       The database name.  Defaults to be the same as the user name.
       In certain contexts, the value is checked for extended
       formats; see <xref linkend="libpq-connstring"/> for more details on
       those.
      </para>
      </listitem>
     </varlistentry>

     <varlistentry id="libpq-connect-user" xreflabel="user">
      <term><literal>user</literal></term>
      <listitem>
      <para>
       <productname>PostgreSQL</productname> user name to connect as.
       Defaults to be the same as the operating system name of the user
       running the application.
      </para>
      </listitem>
     </varlistentry>

     <varlistentry id="libpq-connect-password" xreflabel="password">
      <term><literal>password</literal></term>
      <listitem>
      <para>
       Password to be used if the server demands password authentication.
      </para>
      </listitem>
     </varlistentry>

     <varlistentry id="libpq-connect-passfile" xreflabel="passfile">
      <term><literal>passfile</literal></term>
      <listitem>
      <para>
       Specifies the name of the file used to store passwords
       (see <xref linkend="libpq-pgpass"/>).
       Defaults to <filename>~/.pgpass</filename>, or
       <filename>%APPDATA%\postgresql\pgpass.conf</filename> on Microsoft Windows.
       (No error is reported if this file does not exist.)
      </para>
      </listitem>
     </varlistentry>

     <varlistentry id="libpq-connect-require-auth" xreflabel="require_auth">
      <term><literal>require_auth</literal></term>
      <listitem>
      <para>
        Specifies the authentication method that the client requires from the
        server. If the server does not use the required method to authenticate
        the client, or if the authentication handshake is not fully completed by
        the server, the connection will fail. A comma-separated list of methods
        may also be provided, of which the server must use exactly one in order
        for the connection to succeed. By default, any authentication method is
        accepted, and the server is free to skip authentication altogether.
      </para>
      <para>
        Methods may be negated with the addition of a <literal>!</literal>
        prefix, in which case the server must <emphasis>not</emphasis> attempt
        the listed method; any other method

Title: Connection Parameters: Port, Database, User, Password, Passfile, and Authentication
Summary
This section details several connection parameters for libpq. It covers the 'port' parameter, explaining how to specify the port number for the server or the socket file extension for Unix-domain connections, including handling multiple hosts with comma-separated lists of ports. It also describes the 'dbname' parameter for the database name, defaulting to the user name, the 'user' parameter for the PostgreSQL user name, defaulting to the operating system user, the 'password' parameter, the 'passfile' parameter for the password file location, and the 'require_auth' parameter to enforce the client-side authentication method. Finally, it briefly touches on password authentication and the password file.