How can I tell/specify which version of the postgres client/libs psycopg2 is using?
<p>I have psycopg2 for a python program, but the computer the program is running on has two version of postgres installed: 9.2 in the 'main' system, and 9.5 in /opt. The postgres DB is hosted elsewhere, and is 9.5. The 9.2 psql client will still happily connect to the 9.5 DB, with a warning. How can I tell which version or postgres the psycopg2 library is using, and how can I force it to use a specific version? Running <code>SELECT version();</code> seems to return the server version, while I'm only interested in the client version.</p>

<p>Should be able to force it by putting the 9.5 client binaries at the start of the path for the user that is running your python program. To test:</p>

<pre><code>export PATH=/opt/&lt;path-to-your-9.5&gt;;$PATH
which psql #ensure the 9.5 one is returned
psql -h &lt;remote-host&gt; -p &lt;remote-port&gt; -U &lt;user&gt; -W -d &lt;dbname&gt; # test even further if you wish
</code></pre>

<p>If you wanting know the lib then you need to look at what libpq your python is using:</p>

<pre><code>[root@pgbuilder cgi-bin]# ldd /usr/lib64/python2.7/site-packages/psycopg2/_psycopg.so | grep libpq
libpq.so.5 =&gt; /usr/pgsql-9.5/lib/libpq.so.5 (0x00007fd5f40b7000)
</code></pre>

<p>Change your path to suit your "_psycopg.so" location.</p>

python postgresql psycopg2