April 25, 2021 in Tutorial3 minutes
In this tutorial we learn how to check the PostgreSQL version installed on a system. There are multiple methods to check PostgreSQL version and we will learn each of the method.
Starting from version 10, PostgreSQL uses the following pattern for its versioning number MAJOR.MINOR
. For example 10.1
, 11.2
, 12.3
, and 13.0
.
Before version 10, the major version used two numbers separated by dot. For example:
9.5.10
: the major version is 9.5
and minor 10
.9.6.4
: the major version is 9.6
and minor version 4
.Understanding this difference is important to know if you need to do upgrade or have to match application requirements with specific major version of PostgreSQL or minor version of PostgreSQL.
The first method to check the PostgreSQL version is to use the command line. On the system running PostgreSQL we can use the command below:
postgres --version
Another method to check the version of PostgreSQL from the command line is using the command below:
postgres -V
The second method that we can use to check the PostgreSQL version is from the SQL shell. First, we need to change the user to the postgres
user. Then we connect to the local PostgreSQL database using the psql
command.
psql
After connected to PostgreSQL shell we can use one the following query:
SELECT version();
Another query that we can run on PostgreSQL shell to get the running version is using the following query:
SHOW server_version;
To locate the correct path to the psql utility if it is not found, you can follow these steps:
locate bin/psql
psql --version
For example, if the full path to the psql executable is /usr/bin/psql
, you would run:
/usr/bin/psql --version
The terminal will display the version of PostgreSQL associated with the psql utility. By following these steps, you will be able to locate the correct path to the psql utility on your system if it is not found initially.
In this tutorial we learn how to check the version of PostgreSQL on the running system using two different methods, the first one is using shell command line and the second method is using SQL shell.