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.
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
The version number is displayed in the terminal window. To use the -V
option, run:
postgres -V
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:
locate bin/postgres
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
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:
SELECT version();
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;
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
The -V
option works in this instance as well:
psql -V
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:
locate bin/psql
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
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.