In this article I present several ways to check your PostgreSQL version.
Option 1: SELECT version()
If you’re already connected to PostgreSQL, run the following query to return the PostgreSQL server’s version information:
SELECT version();
Here’s the result when using PostgreSQL 12.1:
version ------------------------------------------------------------------------------------------------------------- PostgreSQL 12.1 on x86_64-apple-darwin16.7.0, compiled by Apple LLVM version 8.1.0 (clang-802.0.42), 64-bit (1 row)
This option is handy for when you’re connected to a PostgreSQL database using a GUI such as PgAdmin, DBeaver, Azure Data Studio, etc.
But you can run the same query when you’re connected to a PostgreSQL database using the psql command line interface (CLI).
Option 2: SHOW server_version
If you only want the version number, run SHOW server_version
:
SHOW server_version;
Here’s the result when using PostgreSQL 12.1:
server_version ---------------- 12.1
You can also use the server_version_num
command to return the version number as an integer:
SHOW server_version_num;
Here’s the result when using PostgreSQL 12.1
server_version_num -------------------- 120001
Option 3: Using the CLI
Here are a couple of handy Command Line Interface (CLI) options.
The pg_config Utility
The pg_config utility retrieves information about the installed version of PostgreSQL.
Running it with the --version
option returns the PostgreSQL server’s version number:
pg_config --version
Here’s the result when using version 12.1:
PostgreSQL 12.1
Another way to do it is to use postgres -V
.
postgres -V
Result:
postgres (PostgreSQL) 12.1
The psql Client
psql is a terminal-based front-end to PostgreSQL.
Running psql --version
returns the psql version number:
psql --version
Here’s the result when using version 12.1:
psql (PostgreSQL) 12.1
You can also use a shortened syntax psql -V
to return the same result.
psql -V
Result:
psql (PostgreSQL) 12.1