How to Check Which Version of Postgres is Running/Installed

Check which Postgres version is installed using the command line with postgres -V and psql -V, plus SQL queries like SELECT version() and SHOW server_version.

What version of postgres client or server am I running?

In this brief guide, we are going to explore how to check which version of Postgres is running either on your machine or in a postgres instance for both the client and the server versions.

The sample output below was captured on PostgreSQL 18.6 running on Rocky Linux 9. The commands work the same on every supported release (14 through 18 as of September 2026); only the version string changes. Note that PostgreSQL 14 reaches end of life on November 12, 2026, so if that is what you find, plan an upgrade. Since PostgreSQL 10, versions use a two-part major.minor format (for example 18.6): the first number is the major release and the second is the minor (bug-fix) release.

We will cover three methods:

  1. Using the command line
  2. Using SQL
  3. Use VERSION special variable

1. Using the command line

Postgres installations provide both client and server utilities that can be used to query the Postgres Installation.

To check the version, we use the respective binary but with the -V or --version flag.

Server version

To find the Postgres server version from the shell command line, use the postgres command with the -V or (--version) flag (for version):

$ postgres -V
postgres (PostgreSQL) 18.6

Oftentimes, the postgres command is not added to the $PATH and is not normally accessible. In such a case, you will get the error:

$ postgres -V
-bash: postgres: command not found

If you know the exact path to the postgres executable, type it like /path/to/postgres -V but if not use the locate command. If you get the locate command not found like this:

# locate bin/postgres
-bash: locate: command not found

You need to install it. I am using Rocky Linux 9. So to check which package provides that:

$ sudo dnf whatprovides locate
mlocate-0.26-30.el9.x86_64 : An utility for finding files by name
Repo        : baseos
Matched from:
Filename    : /usr/bin/locate

Install it:

$ sudo dnf install -y mlocate

On Rocky Linux 10 (and other EL10 systems), locate is provided by plocate instead, so install that package:

$ sudo dnf install -y plocate

Then Update locate database so it can find the files:

$ sudo updatedb

Next let us locate our bin/postgres.

$ locate bin/postgres
/usr/bin/postgresql-18-setup
/usr/pgsql-18/bin/postgres
/usr/pgsql-18/bin/postgresql-18-check-db-dir
/usr/pgsql-18/bin/postgresql-18-setup

In our case we are interested in the /usr/pgsql-18/bin/postgres command:

$ /usr/pgsql-18/bin/postgres -V
postgres (PostgreSQL) 18.6

If you would rather not install locate, the binary usually lives in a predictable place. PGDG packages on RHEL-family systems install to /usr/pgsql-<major>/bin/, while Debian and Ubuntu packages install to /usr/lib/postgresql/<major>/bin/:

ls /usr/pgsql-*/bin/postgres /usr/lib/postgresql/*/bin/postgres 2>/dev/null

On Debian and Ubuntu, pg_lsclusters (from the postgresql-common package) also lists every installed cluster with its version, port and status.

Client version

Postgres provides a client tool psql that can be used to connect to Postgres.

To view the client version, pass the -V flag to the psql client utility command:

$ psql -V
psql (PostgreSQL) 18.6

If the psql command is not found, search it with :

$ locate bin/psql
/usr/bin/psql
/usr/pgsql-18/bin/psql

Then you can supply the full path:

$ /usr/pgsql-18/bin/psql -V
psql (PostgreSQL) 18.6

2. Using SQL

We can also use the SQL prompt via an SQL statement to query the PostgreSQL database. Unlike postgres -V, this asks the running server itself, so it is the reliable answer when the client and server versions differ or the server is on another host.

Server version

To determine the server version, postgres provides the select version();

postgres=# select version();
                                                  version
-----------------------------------------------------------------------------------------------------------
 PostgreSQL 18.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-14), 64-bit
(1 row)

The above command will show the full version information for the database.

You can also query from the command line:

psql -c "SELECT version();"

You can also query the specific server version, in the major.minor format, by using the SHOW command:

postgres=# show server_version;
 server_version
----------------
 18.6
(1 row)

The SHOW command is used to display current run-time parameters, which are essentially just a table of name/setting pairs.

For scripts, server_version_num is easier to compare because it is a plain integer (140000 for 14.0, 180006 for 18.6):

postgres=# show server_version_num;
 server_version_num
--------------------
 180006
(1 row)

Client version

We can also issue a short SQL statement from a PostgreSQL prompt to query the client version of psql. However, it’s worth noting that this is purely for convenience, as we’re effectively just asking Postgres to issue a command on the shell prompt, but from within the PostgreSQL prompt itself.

This is performed by using the \! flag while connected to the client, followed by the statement we wish to issue:

postgres=# \! psql -V
psql (PostgreSQL) 18.6

Just as before when we were issuing this command directly from the shell prompt, psql -V may return your client version as above, or the path may not be found.

3. Use VERSION special variable

psql also sets a VERSION special variable at start-up. Note that it reports the version of the psql client, not the server. Because psql -c still needs a database connection, run it as a user that can connect; on a default install that is the postgres user.

Login as postgres

sudo -iu postgres

Then check the version

$ psql -c "\echo :VERSION"
PostgreSQL 18.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-14), 64-bit

To get the server version from the same kind of variable, use SERVER_VERSION_NAME (or SERVER_VERSION_NUM), which psql sets every time it connects:

$ psql -c "\echo :SERVER_VERSION_NAME"
18.6

Conclusion

We managed to cover how to check the client and server versions of postgres in this guide.

Last updated on Sep 26, 2026 13:54 +0300
comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy