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.
- 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
--version arguments. To do that, run:
The version number is displayed in the terminal window. To use the
-V option, run:
These two commands don't always work. For instance, sometimes running
postgres -V returns an error:
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:
The output prints the full postgres path.
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:
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
2. The output shows the current version, but use this command to verify it:
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:
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:
-V option works in this instance as well:
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
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:
The output provides the full path to the psql utility.
2. Use the resulting path and
-V to check the current psql version:
The resulting output shows the current psql client version on the system.
This tutorial provided several effective ways to determine the PostgreSQL version number and how to deal with the "Command 'postgres' not found" error.