How to Check the PostgreSQL Database Version in Linux

How to Check the PostgreSQL Database Version in Linux

In this post, we are going to show that how to check PostgreSQL version in Linux including Ubuntu. If you want to check PostgreSQL version then this post is ideal for you.

The PostgreSQL database is a powerful, free and open-source object-relational database management system. It is also known as Postgres.

Linux is an operating system, like Windows OS, iOS, and Mac OS. It is one of the most popular operating system on the planet, Android is also powered by Linux OS(operating system).

Linux OS(operating system) is also distributed under an open source license. Open source following these points :

  • Freely to run the program, for any purpose.
  • Free to study how the program works.
  • It is free to re-distribute copies so you can help your friends.
  • Free to distribute copies of your modified versions to others.

How to Check the PostgreSQL Version

Simply follow below steps or methods to check PostgreSQL database versions in Linux including Ubuntu:

Method 1 : Check PostgreSQL Version Using Command Line

To check the PostgreSQL version number using command line, run the postgres command with --version or -V option:

postgres --version

OR

postgres -V

The commands above will display a output similar like below:

Output
postgres (PostgreSQL) 12.7

How to Solve the “postgres: command not found” Error

If you will get an error saying “postgres: command not found” during checking the PostgreSQL version using command-line that means the postgres binary is not in system’s PATH or the PostgreSQL packages is not installed from the standard repositories.

For solve the “Command ‘postgres’ not found” error, run the  locate or find command to locate or find the PostgreSQL path to the binary folder:

sudo find /usr -wholename '*/bin/postgres'

sudo updatedb
locate bin/postgres

The commands above display a output similar like below:

Output
/usr/lib/postgresql/12/bin/postgres

Now you can use the path above( path to the binary) to display the version of the PostgreSQL database server. Type the full path with the -V option as show below:

/usr/lib/postgresql/12/bin/postgres -V
Output
postgres (PostgreSQL) 12.7

The PostgreSQL Development and management Group uses a standard MAJOR.MINOR semantic versioning scheme. In this post, the first section (12) indicates the MAJOR version number and the second part (7) indicates the MINOR version number.


Method 2 : Check Postgres Version using SQL Shell

You can also retrieved Postgres Version using the PostgreSQL server prompt. Simply log in to the server SQL prompt and use an SQL statement to print the version.

To sign on to the PostgreSQL server, run the command below:

sudo -u postgres psql

Now, type the below SQL statement to display the current version along with the build information:

SELECT version();

The command above will display the PostgreSQL current version along with the build information.

If you want to display the only PostgreSQL server version number, type the below SQL query:

SHOW server_version;
Output:
server_version          
----------------------------------
 12.7
(1 row)

Method 3 : Check Postgres Version Using PostgreSQL Utility

To display Postgres Version number using PostgreSQL utility, run the command below:

psql --version
Output:
postgres (PostgreSQL) 12.7

That’s all

If you find any error and issue in above steps , please use comment box below to report.

If our tutorials helped you, please consider buying us a coffee. We appreciate your support!

Thank you for your support.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top