Detecting the PostgreSQL DBMS version

The SELECT version(); SQL query may be executed over any SQL connection, including ODBC, JDBC, ADO.NET, OLE DB, etc. For example, --

SQL> SELECT version();

version
------------------------------
PostgreSQL 8.2.3 on sparc-sun-

 result set 1 returned 1 rows.


SQL>


Counter-intuitively, the PG_VERSION file in the database sub-directory of the PostgreSQL server installation bears no relation to your actual installed binaries. This is the file the PostgreSQL server uses to determine whether the directory it's looking at is:

  • an initdb-ed location
  • initdb-ed with the right version

Referenced by...