PostgreSQL is also known as Postgres and it’s an open-source object-relational database management system. It is important to know the version of the PostgreSQL server which is installed on your system when your application is based on specific version. This tutorial will show you how to check the PostgreSQL server version which is running on your system.
Check PostgreSQL Version
PostgreSQL major releases with new features are usually delivered once a year. Each major release is supported for 5 years.
Using the Command Line
You can check the which PostgreSQL version is running on your system using command line by invoking postgres command with --version
or -V
option:
postgres --version
It will show you output like below:
postgres (PostgreSQL) 12.3
At the time of writing this article, the latest version of postgres is 12.3
.
If you will get an error saying “postgres: command not found”, that means you have not postgres
binary in system’s PATH or the PostgreSQL package is not installed from the distribution’s standard repositories.
To find the path to the binary either with the locate or find command:
sudo find /usr -wholename '*/bin/postgres'
sudo updatedb
locate bin/postgres
Output will looks like below:
/usr/lib/postgresql/12/bin/postgres
Now you can use the path to the binary, to get the version of the PostgreSQL server:
/usr/lib/postgresql/12/bin/postgres -V
To know the version of PostgreSQL client utility use psql
as following:
psql --version
It will print output as below:
postgres (PostgreSQL) 12.3
psql
is an interactive command-line utility that allows you to interact with the PostgreSQL server.
Using the SQL Shell
Alternate way to get the PostgreSQL server version is by logging in to the SQL server prompt and print out the version using an SQL statement.
Access the PostgreSQL shell using with psql
:
sudo -u postgres psql
Following statement displays the PostgreSQL server version along with the build information:
SELECT version();
PostgreSQL 12.3 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, 64-bit
(1 row)
To get the only PostgreSQL server version number type:
SHOW server_version;
server_version
----------------
12.3
(1 row)
Conclusion
We have shown you different ways to determine the PostgreSQL server version which is running on your system.
If you have any questions or suggestion, please leave a comment below.