How to Check Your PostgreSQL Version
Last Updated :
27 Sep, 2024
Knowing the specific version of PostgreSQL is vital for maintaining compatibility and utilizing new features. In this article, we will explain several methods to check our PostgreSQL version using the command line, the SQL shell, and the psql
client. Also, it addresses common errors such as the "Command 'postgres' not found".
Checking PostgreSQL Version from the Command Line
When working with Postgres, the exact version we are using is essential for compatibility, performance tuning and taking advantage of the latest features and security improvements.
Checking the PostgreSQL version from the command line is one of the quickest methods available. Let's go over two commands that can help us determine the server and client versions.
1. Using the PSQL Command (Client Version)
The PSQL command is the PostgreSQL interactive terminal that allows us to communicate with the database. The --version option displays the installed version of the psql client.
To check the version of the PostgreSQL client installed on your system, use the following command
psql --version
Output:
Using the psql CommandExplanation: This output indicates that the psql client version installed on my machine is 16.2, meaning i am using the client that interacts with a PostgreSQL 16.x server.
2. Using the postgres Command (Server Version)
The Postgres -V command directly checks the version of the PostgreSQL server. It’s useful for confirming the server version in case you are maintaining or configuring multiple versions of PostgreSQL.
To check the PostgreSQL server version, use the postgres command
postgres -V
Output:
Using the postgres Command
Explanation:
The output shows that my PostgreSQL server version is 16.2. It's important to note that the client and server versions should match or compatible to avoid communication errors.
Solve "Command 'postgres' not found" When Using postgres -V
Sometimes, when we try to run Postgres -V, we might encounter the "Command 'postgres' not found" error. This issue occurs either because PostgreSQL is not installed correctly or because the PATH environment variable is not configured. Here's how we can fix this:
Step 1. Verify Installation: Run the following command to verify if PostgreSQL is installed on your system.
This command lists the installed packages and should return a result if PostgreSQL is installed. If nothing is returned, we need to install PostgreSQL.
sudo apt list --installed | grep postgresql
Step 2. Add PostgreSQL to PATH: If PostgreSQL is installed but not found, add the PostgreSQL binary folder to your PATH:
export PATH=$PATH:/usr/lib/postgresql/14/bin
Step 3. Reinstall PostgreSQL: If the issue persists, reinstall PostgreSQL using the following command
sudo apt install postgresql
These steps will help resolve the error and ensure that the Postgres -V command works properly to check your server version.
Check Postgres Version from SQL Shell
The SQL Shell (PSQL) is another way to determine the PostgreSQL version. This method provides detailed information, including platform and compiler details. This query returns detailed information about the PostgreSQL server, including the version number, platform, and compiler used to build PostgreSQL.
Step 1: Log in to the PostgreSQL shell
Step 2: Run the following SQL command, This query returns the PostgreSQL version along with additional details like the OS platform and compiler version used to build the database.
SELECT version();
Output:
Check Postgres Version from SQL ShellExplanation:
The output shows that PostgreSQL version 16.2 is installed on a 64-bit system. Additionally, it provides details about the C++ compiler version used to build the database.
How to Check psql Client Version?
The psql client is a command-line interface that connects us to the PostgreSQL server. Checking the client version helps ensure that it's compatible with the server.
This command is similar to the one mentioned earlier and returns the version of the PostgreSQL psql client installed on your system. Run the following command to check the PSQLclient version,
psql --version
Solve "Command 'postgres' not found" when Checking psql Client Version
If we are checking the psql client version and encounter the "Command 'postgres' not found" error, the solution is similar to what we discussed earlier. Following these steps will help us to resolve the "command not found" issue when checking the PSQL client version.
Step 1: Check if psql is Installed: Run the following command to verify if the PSQL client is installed
sudo apt list --installed | grep psql
Step 2: If it's not listed: you can install it using
sudo apt install postgresql-client
Step 3: Add psql to PATH: If the client is installed but not accessible, add it to your system PATH using the following command
export PATH=$PATH:/usr/lib/postgresql/14/bin
Conclusion
In summary, quickly checking PostgreSQL versions via command line commands like psql --version
and postgres -V
is essential for effective database management. These methods enable users to confirm compatibility between client and server versions.
Similar Reads
How to Check PySpark Version
Knowing the version of PySpark you're working with is crucial for compatibility and troubleshooting purposes. In this article, we will walk through the steps to check the PySpark version in the environment. What is PySpark?PySpark is the Python API for Apache Spark, a powerful distributed computing
3 min read
How to Check NPM Version?
Node Package Manager (npm) is an essential tool for managing JavaScript projects. Whether you're working on a simple script or a large application, knowing your npm version is important for ensuring compatibility and troubleshooting issues. How to Check NPM Version?To check your npm version, you can
3 min read
How to Check Your WordPress Version?
Checking the WordPress version is important for maintaining the security and functionality of our website. Knowing the security version helps you determine if you need to update to the latest version which can include new features, bug fixes, and security patches. To check your WordPress version you
2 min read
How to Check Column Types in PostgreSQL?
In PostgreSQL, checking column types is an important aspect of understanding the structure and data stored in a database table. It helps database developers and administrators work effectively by providing a clear picture of the database schema. In this article, we will explore various methods to ch
4 min read
How to Check Your Ubuntu Version: A Guide
Ubuntu is a Linux distribution built on Debian that is mostly comprised of software that is open-source and free. Ubuntu is officially available in three editions: Desktop, Server, and Core for IoT devices and robots. Canonical, a British corporation, and a group of other developers work on the oper
4 min read
How To Check The Version of ReactJS Project?
Whether you're debugging an issue, updating a project, or just curious, about knowing the version of ReactJS used in your application, you can easily do it using these simple methods. In this article, weâll walk you through different ways to check the version of ReactJS used in a project using metho
2 min read
How to check scala version in terminal?
For Scala developers, it is very important to check the Scala version in the terminal. To make sure that your system is compatible with libraries, frameworks, etc., and to resolve any specific issues that might arise during programming, knowing the Scala version installed on a computer is vital. Wit
3 min read
How to check NumPy version installed?
In this article, we are going to learn how we can find out which version of NumPy your Python code uses. The version of any project keeps on changing with time as the project gets updated, new features keep being added, and old bugs are removed. Hence, a lot of work keeps on happening on projects es
2 min read
How to check Scala version in mac?
Scala is a powerful and versatile programming language that combines features of two popular programming paradigms: Object-oriented and Functional. These are the features of the Scala programming language: Multi-paradigmObject-OrientedFunctional ProgrammingJVM and BeyondStatically TypedTo check the
1 min read
How to Check Kernel Version in Linux
The kernel is the core component of the Linux operating system, responsible for managing hardware, running processes, and ensuring system stability. Whether you're updating software, installing new drivers, or troubleshooting issues, knowing your kernel version helps ensure everything works smoothly
7 min read