Check PostgreSQL Version in Ubuntu Linux / Windows

There are a couple of ways we can check the PostgreSQL version. If you can connect to the server via psql, you can issue the following command that shows the server version:

SELECT version();

This function returns the PostgreSQL version, as well as the build system. It is also the preferred method to get the Postgres version on Windows.

You'll get an answer that looks something like the following:

PostgreSQL 13.1 (Ubuntu 13.1-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit
(1 row)

The pg_lsclusters command is available in Ubuntu and Debian Linux distros. This command on Ubuntu shows all installed PostgreSQL clusters and their information.


The pg_lsclusters output includes Postgres Version (Major release number), Port, Data directory, etc.

The following Linux command will also help you identify the PostgreSQL version by looking at the postmaster process.

pgrep -a post

It shows the command that started the PostgreSQL process. In my case, it is /usr/lib/postgresql/13/bin/postgres which I can use with the --version option to check PostgreSQL version.

/usr/lib/postgresql/13/bin/postgres --version
check postgresql version

The PostgreSQL version number consists of two digits: major and minor release.

End of life (EOL): PostgreSQL developers provide support and upgrades for 5 years after a new stable version is released.