Home » Programming » Databases » How to Check What Version of PostgreSQL You are Running on Linux

How to Check What Version of PostgreSQL You are Running on Linux

This article will show you how to check the version (or versions) of PostgreSQL running on your Linux system.

As it is possible to install multiple versions of PostgreSQL on the same machine, there are a few ways to check the running version, which are detailed below.

Checking PostgreSQL Server Version

To check the running PostgreSQL server version, use the following pg_config command:

pg_config --version

Check PostgreSQL Client Version

To check which version of the PostgreSQL client you are running, run the following psql command:

psql --version

Finding the PostgreSQL Executables

If you run into an error where the executable cannot be found, and need to check the location of either PostgreSQL executable, you can run:

locate bin/postgres 

or for the client:

locate bin/psql 

The executable may have a different name if you are running multiple versions – see below.

If you’re looking to find the executable for the running PostgreSQL cluster, run:

pg_config ----bindir

Checking Multiple PostgreSQL Versions

If you have more than one version of PostgreSQL installed (for example, after upgrading), you can locate all of them by running

locate bin/postgresql | xargs -i xargs -t '{}' -V 

or for the client:

locate bin/psql | xargs -i xargs -t '{}' -V 

This will list all matching executables, which you can then check the version of individually by running the --version parameter for each of them:

For example, if you had two versions of PostgreSQL listed, you would run:

/usr/bin/psql --version

and:

/usr/pgsql-9.2/bin/psql --version

To check the version output for each.

Listing all PostgreSQL Clusters

You can also list all PostgreSQL clusters installed by running:

sudo pg_lsclusters

The output should look something like this:

Ver Cluster Port Status Owner    Data directory               Log file
9.1 main    5433 online postgres /var/lib/postgresql/9.1/main /var/log/postgresql/postgresql-9.1-main.log
11  main    5432 online postgres /var/lib/postgresql/11/main  /var/log/postgresql/postgresql-11-main.log

This output includes the version and location of all installed PostgreSQL clusters. They can then be managed using pg_ctlcluster.

SHARE:
Photo of author
Author
I'm Brad, and I'm nearing 20 years of experience with Linux. I've worked in just about every IT role there is before taking the leap into software development. Currently, I'm building desktop and web-based solutions with NodeJS and PHP hosted on Linux infrastructure. Visit my blog or find me on Twitter to see what I'm up to.

Leave a Comment