How to Check Which Version of PostgreSQL You’re Running on Linux

PostgreSQL is a popular relational database management system used extensively in Linux environments. Knowing the PostgreSQL version installed on your system is essential for compatibility, feature availability, and troubleshooting. This guide will walk you through the steps to determine the PostgreSQL version running on your Linux system.

Method 1: Using Command Line

1. Login to PostgreSQL:

Open your terminal and log in to PostgreSQL using the psql command-line tool. You might need to specify a username and database name if they are different from your current Linux user and default database.

psql -U your_username -d your_database

2. Query PostgreSQL Version:

Once logged in, execute the following SQL query to fetch the PostgreSQL server version:

SELECT version();

This query returns a result showing the PostgreSQL version installed on your system.


Assuming you are logged in as the PostgreSQL user and connected to a database named mydb, running the query would look like this:

$ psql -U postgres -d mydb
Password for user postgres:
psql (12.5)
Type "help" for help.

mydb=# SELECT version();
 PostgreSQL 12.5 (Ubuntu 12.5-0ubuntu0.20.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0, 64-bit
(1 row)


Method 2: Using pg_config Command

Another method to check the PostgreSQL version is by using the pg_config command, which provides configuration information for the PostgreSQL installation:

pg_config --version

This command outputs the version of PostgreSQL installed on your system.


Determining the version of PostgreSQL running on your Linux system is straightforward with the methods outlined in this guide. By following these steps, you can quickly retrieve the version information needed for maintenance, compatibility checks, and ensuring your PostgreSQL environment is up-to-date.

With this knowledge, you can confidently manage PostgreSQL installations, troubleshoot issues related to specific versions, and leverage the features available in your PostgreSQL deployment.