Home Explore Blog CI



postgresql

42th chunk of `doc/src/sgml/libpq.sgml`
73695cd19051de6974b7bff1ff27f0c193f54a4d0e71edcf0000000100000fae
 id="libpq-PQserverVersion">
     <term><function>PQserverVersion</function><indexterm><primary>PQserverVersion</primary></indexterm></term>

     <listitem>
      <para>
       Returns an integer representing the server version.
<synopsis>
int PQserverVersion(const PGconn *conn);
</synopsis>
      </para>

      <para>
       Applications might use this function to determine the version of the
       database server they are connected to.  The result is formed by
       multiplying the server's major version number by 10000 and adding
       the minor version number.  For example, version 10.1 will be
       returned as 100001, and version 11.0 will be returned as 110000.
       Zero is returned if the connection is bad.
      </para>

      <para>
       Prior to major version 10, <productname>PostgreSQL</productname> used
       three-part version numbers in which the first two parts together
       represented the major version.  For those
       versions, <xref linkend="libpq-PQserverVersion"/> uses two digits for each
       part; for example version 9.1.5 will be returned as 90105, and
       version 9.2.0 will be returned as 90200.
      </para>

      <para>
       Therefore, for purposes of determining feature compatibility,
       applications should divide the result of <xref linkend="libpq-PQserverVersion"/>
       by 100 not 10000 to determine a logical major version number.
       In all release series, only the last two digits differ between
       minor releases (bug-fix releases).
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQerrorMessage">
     <term>
      <function>PQerrorMessage</function><indexterm><primary>PQerrorMessage</primary></indexterm>
      <indexterm><primary>error message</primary><secondary>in <structname>PGconn</structname></secondary></indexterm>
     </term>

     <listitem>
      <para>
       Returns the error message most recently generated by
       an operation on the connection.

<synopsis>
char *PQerrorMessage(const PGconn *conn);
</synopsis>
      </para>

      <para>
       Nearly all <application>libpq</application> functions will set a message for
       <xref linkend="libpq-PQerrorMessage"/> if they fail.  Note that by
       <application>libpq</application> convention, a nonempty
       <xref linkend="libpq-PQerrorMessage"/> result can consist of multiple lines,
       and will include a trailing newline. The caller should not free
       the result directly. It will be freed when the associated
       <structname>PGconn</structname> handle is passed to
       <xref linkend="libpq-PQfinish"/>.  The result string should not be
       expected to remain the same across operations on the
       <literal>PGconn</literal> structure.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQsocket">
     <term><function>PQsocket</function><indexterm><primary>PQsocket</primary></indexterm></term>
     <listitem>
      <para>
       Obtains the file descriptor number of the connection socket to
       the server.  A valid descriptor will be greater than or equal
       to 0; a result of -1 indicates that no server connection is
       currently open.  (This will not change during normal operation,
       but could change during connection setup or reset.)

<synopsis>
int PQsocket(const PGconn *conn);
</synopsis>

      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQbackendPID">
     <term><function>PQbackendPID</function><indexterm><primary>PQbackendPID</primary></indexterm></term>
     <listitem>
      <para>
       Returns the process <acronym>ID</acronym> (PID)<indexterm>
        <primary>PID</primary>
        <secondary>determining PID of server process</secondary>
        <tertiary>in libpq</tertiary>
       </indexterm>
       of the backend process handling this connection.

<synopsis>
int PQbackendPID(const PGconn *conn);
</synopsis>
      </para>

      <para>
       The backend <acronym>PID</acronym>

Title: PQserverVersion, PQerrorMessage, PQsocket, and PQbackendPID: Functions for Retrieving Server Information and Handling Errors
Summary
This section describes functions for retrieving server information and handling errors. PQserverVersion returns an integer representing the server version. PQerrorMessage returns the most recent error message generated by an operation on the connection. PQsocket obtains the file descriptor number of the connection socket to the server. PQbackendPID returns the process ID (PID) of the backend process handling the connection.