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>