How to Check Which PostgreSQL Version is Running from CLI

PostgreSQL is an open-source relational database management system that is commonly known as Postgres.

As a system administrator as well as a database administrator, it is most important to know the installed and running version of Postgres in your system. For example, if you are deploying an application that requires a specific version of Postgres, you may need to search for the same version of PostgreSQL Server.

In this article, I will explain how to check your PostgreSQL version on server and client using different methods.

Using command line

To find the running PostgreSQL version on your system, access your terminal and execute command postgres with -V or --version option:

$ postgres --version

or

$ postgres -V

Both command will give output as:

Output

postgres (PostgreSQL) 12.5 

In this example, the version of PostgreSQL is 12.5

If postgres binary file is not present in the system's path you will get an error saying "postgres: command not found". To mitigate such problems you need to find the PostgreSQL binary directory. Enter the following command to locate the PostgreSQL binary folder:

$ locate /bin/postgres

The full path of your postgresql binary folder is displayed in your terminal.

PostgreSQL binary folder path

Type the full path and add --version or -V option to get the current PostgreSQL server version.

$ /usr/lib/postgresql/12/bin/postgres --version
$ /usr/lib/postgresql/12/bin/postgres -V

Both command will give output as:

Output

postgres (PostgreSQL) 12.5 

In this example, Postgres version is 12.5.

Using SQL Shell

PostgreSQL version can be retrieved from PostgreSQL prompt. Log in into server SQL prompt and execute SQL command to print out the version.

$ sudo -u postres psql

Type following SQL command to check current PostgreSQL version:

postgres=# SELECT version();
Checking PostgreSQL version using SQL Shell

In this example, PostgreSQL version is 12.5

You can display only the PostgreSQL server version by using following SQL statement.

postgres=#  SHOW server_version;

This SQL statement will print following output:

PostgreSQL sever version using SQL statement

In this example, running PostgreSQL version is 12.5

PSQL Client version

psql is a terminal-based interactive command-line utility tool that acts as a front-end to PostgreSQL which allows you to interact with the PostgreSQL server. You can run the following command to display the version of the psql client utility:

$ psql --version

Also you can run psql command with -V option to print version of psql client utility.

$ psql -V

You will get following output in your terminal:

PostgreSQL psql client version

In this example, the version of psql client utility tool is 12.5

Conclusion

We hope this article helped you to find the version of PostgreSQL in a different way. Please feel free to comment on us. Thank you.

1 thought on “How to Check Which PostgreSQL Version is Running from CLI”... add one

Leave a Comment