How to Check PostgreSQL Version on Ubuntu

Ubuntu is one of the well-known operating systems, including PostgreSQL in its official repositories. It makes it easy for Ubuntu users to install, remove and use the database system. Once installed, users can interact with PostgreSQL through a variety of interfaces, including the command line interface, and graphical user interfaces. Checking the Postgres version on Ubuntu is an important step in maintaining the stability, security, and compatibility of your system.

This article will demonstrate all possible methods to check the Postgres version in Ubuntu.

- Method 1: Using psql Command-Line Tool
- Method 2: Using pg_config Utility
- Method 3: Using the dpkg Command
- Method 4: Using the apt-cache Command

Let’s start with the first method.

Method 1: Using psql command-line Tool

Before checking the Postgres version, use the “sudo” command with the “u” option to log in to PostgreSQL as a superuser:

$ sudo -u postgres psql
img

After executing the above command, the user enters the Postgres shell as seen above.

To check the Postgres version in Ubuntu, use the “SELECT” statement with the “version()” function. It displays the current version of PostgreSQL:

SELECT version();
img

The output displays the “14.6” version of PostgreSQL that is currently installed in Ubuntu.

Method 2: Using pg_config Utility

If the config utility is installed, type the “pg_config” command with the “version” option to display the version of PostgreSQL:

$ pg_config --version
img

It displays the “14.6” version of PostgreSQL that is currently installed in Ubuntu.

Note: If the config utility is not installed in the system, install it by running the command “sudo apt install postgresql-server-dev-all”.

Method 3: Using the dpkg Command

Users can also check the Postgres version by executing the “dpkg” command with the “l” option by specifying the PostgreSQL. It displays the version of PostgreSQL:

$ dpkg -l postgresql
img

It displays the “14” version of PostgreSQL which is currently installed in Ubuntu.

Method 4: Using the apt-cache Command

To display the version of PostgreSQL, users can utilize the “apt-cache” with the “policy” utility:

$ apt-cache policy postgresql
img

The above output displays the “14” version of PostgreSQL that is installed in Ubuntu along with the repository it was installed from.

That is all from the guide.

Conclusion

To check the PostgreSQL version in Ubuntu, use the “psql” tool, “pg_config”, “dpkg”, or “apt-cache” commands. These commands provide information about the currently installed version of PostgreSQL in Ubuntu. This guide has illustrated all possible methods to check the PostgreSQL version in Ubuntu.