How to Check the PostgreSQL Version

By 

Updated on

3 min read

Check PostgreSQL Version

PostgreSQL, often known simply as Postgres, is an open-source object-relational database management system.

Knowing which version is running on your system matters when you are installing an application that requires a specific PostgreSQL release, planning an upgrade, or troubleshooting compatibility issues.

This guide covers the most common ways to check the PostgreSQL version from the command line and from within a database session.

PostgreSQL Versioning

PostgreSQL releases follow a MAJOR.MINOR versioning scheme.

The MAJOR number increases with each annual release that introduces new features. Starting with PostgreSQL 10, each major version increments by one (10, 11, 12, … 16, 17). Before version 10, major versions used a two-part number such as 9.4 or 9.6.

The MINOR number covers bug fixes and security patches within a major release. For example, 17.1 and 17.2 are both part of the PostgreSQL 17 major release. Each major release receives security and bug-fix updates for five years.

The current major version is PostgreSQL 18.

Using the Command Line

To check the PostgreSQL server version, run the postgres binary with the --version or -V flag:

Terminal
postgres --version

The command prints the version and exits:

output
postgres (PostgreSQL) 17.2

You can also check the version of the psql client utility:

Terminal
psql --version
output
psql (PostgreSQL) 17.2

psql is the interactive terminal for PostgreSQL. Its version usually matches the server version, but they can differ if the client and server packages were installed separately.

Binary not found

If the postgres binary is not in your system’s PATH , you will get a “command not found” error. This usually happens when PostgreSQL was installed outside the distribution’s standard repositories.

Use the find command to locate the binary:

Terminal
sudo find /usr -wholename '*/bin/postgres'
output
/usr/lib/postgresql/17/bin/postgres

Once you have the path, pass it directly to get the version:

Terminal
/usr/lib/postgresql/17/bin/postgres -V

Using the SQL Shell

You can also check the version from within an active database session. Connect to the PostgreSQL shell with psql:

Terminal
sudo -u postgres psql

The following query returns the full version string including build details:

sql
SELECT version();
output
                                                              version                                                              
----------------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 17.2 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0, 64-bit
(1 row)

To get just the version number, use SHOW instead:

sql
SHOW server_version;
output
 server_version 
----------------
 17.2
(1 row)

SHOW server_version is useful in scripts or monitoring queries where you only need the bare version string.

Quick Reference

MethodCommand
Server binarypostgres --version
Client binarypsql --version
Full version string (SQL)SELECT version();
Version number only (SQL)SHOW server_version;
Find binary pathsudo find /usr -wholename '*/bin/postgres'

Conclusion

For a quick check from the shell, postgres --version is all you need. Inside a running session, SHOW server_version returns just the version number and works well in scripts or monitoring queries.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page