How to Check PostgreSQL Version

Summary: in this tutorial, you will learn various ways to check the PostgreSQL version on your system.

1) Checking PostgreSQL version using psql

First, open Command Prompt on Windows or Terminal on a Unix-like system.

Second, run the following command:

psql --version

This command will display the PostgreSQL version installed on your server.

2) Getting the version using SQL statements

First, connect to the PostgreSQL server using psql or GUI tools like pgAdmin.

For example, you can connect to the PostgreSQL server using psql:

psql -U postgres

Second, run the following statement to retrieve the version:

SELECT version();
Code language: SQL (Structured Query Language) (sql)

The query will return a text that includes the PostgreSQL version. For example:

                          version
------------------------------------------------------------
 PostgreSQL 16.1, compiled by Visual C++ build 1937, 64-bit
(1 row)Code language: CSS (css)

3) Querying version from the information schema

First, connect to the PostgreSQL database using psql or a PostgreSQL client.

Second, execute the following query to get the PostgreSQL version:

SELECT 
  setting 
FROM 
  pg_settings 
WHERE 
  name = 'server_version';Code language: SQL (Structured Query Language) (sql)

Output:

 setting
---------
 16.1
(1 row)Code language: CSS (css)

Summary

  • Use the psql --version command, select version() statement, and retrieve the setting from the pg_settings to get the PostgreSQL version.
Was this tutorial helpful ?