How to Check Your PostgreSQL Version

December 4, 2023

Introduction

Major PostgreSQL versions are released yearly with a focus on improving key features and fixing known bugs. Minor releases are available approximately every three months and aim to resolve ongoing security concerns. Therefore, updating PostgreSQL regularly to the latest version is essential.

This tutorial shows you how to check your PostgreSQL version using different methods.

How to Check Your PostgreSQL Version

Prerequisites

  • Access to the terminal.
  • PostgreSQL database server installed.

Check PostgreSQL Version from the Command Line

The default way to check the PostgreSQL version is with the -V or --version arguments. To do that, run:

postgres --version
postgres --version terminal output

The version number is displayed in the terminal window. To use the -V option, run:

postgres -V
postgres -V terminal output

These two commands don't always work. For instance, sometimes running postgres -V returns an error:

Command Postgres not found

Solve "Command 'postgres' not found" When Using postgres -V

The message Command 'postgres' not found occurs due to various reasons, some of which are:

  • PostgreSQL binaries directory is not added to the system's PATH.
  • PostgreSQL installation was done from a third-party source.
  • The PostgreSQL server is missing.
  • The PostgreSQL server is installed without the corresponding client utilities.

Despite this error, there are alternative methods to check the PostgreSQL version via the command line. Use the -V on the postgress path as a workaround.

To do so:

1. Use the locate tool to find the PostgreSQL binary directory:

locate bin/postgres
locate bin/postgres terminal output

The output prints the full postgres path.

Note: The locate command is not present in every system by default. If the command is missing, install it with sudo apt install mlocate.

2. Type the full path and add the -V option to display the current PostgreSQL server version:

/usr/lib/postgresql/14/bin/postgres -V
/usr/lib/postgresql/14/bin/postgres -V terminal output

PostgreSQL uses a standard MAJOR.MINOR semantic versioning system. The first section (14) in the example above signifies the MAJOR release number. The second part (9) represents the MINOR release number for that major version.

Note: Always update PostgreSQL to the latest available minor version that corresponds to the major version you have installed.

Check Postgres Version from SQL Shell

Another way to retrieve the postgres version number is directly from the PostgreSQL shell. Follow these steps:

1. Access the PostgreSQL shell by typing:

sudo -u postgres psql
sudo -u postgres psql terminal output

2. The output shows the current version, but use this command to verify it:

SELECT version();
SELECT -version terminal output

The command prints the output in a new window. The resulting output provides the full version and system information for the PostgreSQL server.

Another way is to instruct PostgreSQL to show the value associated with the server_version parameter. Use this command:

SHOW server_version;
SHOW server_version; terminal output

The result displays the current value for server_version.

How to Check psql Client Version

Psql functions as a front-end terminal for PostgreSQL. It's used to issue queries and display the provided results.

Use the following command to determine the psql client version:

psql --version
psql --version terminal output

The -V option works in this instance as well:

psql -V
psql --V terminal output

Solve "Command 'postgres' not found" when Checking psql client Version

The Command not found error sometimes appears when checking the psql client version. If that is the case, you may have the PostgreSQL server installed but not the client utilities.

Install them with:

sudo apt install postgresql-client

sudo apt install postgresql-client terminal output

Once installed, run psql -V again. If the error persists, use this alternative method to check the version:

1. Enter the following command to locate the correct path to the psql utility:

locate bin/psql
locate bin/psql terminal output

The output provides the full path to the psql utility.

2. Use the resulting path and -V to check the current psql version:

/usr/lib/postgresql/14/bin/psql -V
/usr/lib/postgresql/14/bin/psql -V terminal output

The resulting output shows the current psql client version on the system.

Conclusion

This tutorial provided several effective ways to determine the PostgreSQL version number and how to deal with the "Command 'postgres' not found" error.

Next, learn more about using PostgreSQL, like exporting a table or listing all databases.

Was this article helpful?
YesNo
Vladimir Kaplarevic
Vladimir is a resident Tech Writer at phoenixNAP. He has more than 7 years of experience in implementing e-commerce and online payment solutions with various global IT services providers. His articles aim to instill a passion for innovative technologies in others by providing practical advice and using an engaging writing style.
Next you should read
How to Export a PostgreSQL Table to CSV
March 17, 2020

Learn how to export a PostgreSQL table to a .csv file. This feature is especially helpful when transferring...
Read more
How to Install PostgreSQL on Ubuntu 18.04
March 14, 2024

PostgreSQL is an open-source, relational database management system. There are two simple ways of installing...
Read more
PostgreSQL Vs MySQL: A Detailed Comparison
March 30, 2023

Explore the differences between the two most widely used database management systems. PostgreSQL and MySQL...
Read more
How to Connect to a PostgreSQL Database From Command Line in Linux
February 22, 2024

PostgreSQL is an open-source relational database management system. In this tutorial learn how to connect...
Read more