top of page

How to find 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. To check the PostgreSQL version in Ubuntu, use below commands which provide information about the currently installed version of PostgreSQL in Ubuntu.

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

Let’s execute all the commands and find out the postgreSQL version info

1) Using psql command-line Tool

Before checking the Postgres version, Switch to the "postgres" user and you can access the PostgreSQL shell by running the 'psql' command OR use the “sudo” command with the “u” option to log in to PostgreSQL as a superuser:

root@Ubuntu06:~# sudo su - postgres
postgres@Ubuntu06:~$ psql
psql (15.3 (Ubuntu 15.3-1.pgdg22.04+1))
Type "help" for help.

postgres=#

OR

root@Ubuntu06:~# sudo -u postgres psql
could not change directory to "/root": Permission denied
psql (15.3 (Ubuntu 15.3-1.pgdg22.04+1))
Type "help" for help.

postgres=# 
sudo su - postgres; psql
sudo -u postgres psql

After executing the above command, the user enters the Postgres shell 'postgres=#' 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:

postgres=# SELECT version();
SELECT version();

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

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:

postgres@Ubuntu06:~$ pg_config --version
pg_config --version

It displays the “15.3” 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”.

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:

postgres@Ubuntu06:~$ dpkg -l postgresql
dpkg -l postgresql

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

4) Using the apt-cache Command

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

postgres@Ubuntu06:~$ apt-cache policy postgresql
apt-cache policy postgresql

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

That's all in this post. If you liked this blog and interested in knowing more about PostgreSQL, Please Like, Follow, Share & Subscribe to www.ImJhaChandan.com .

Comments


jc_logo.png

Hi, thanks for stopping by!

Welcome! to my “Muse & Learn” blog.

This website will help you to learn useful queries/SQL, Tips to troubleshoot problem and their remediation, perform DB related activities etc... and don't forget to muse with us :)....

It cover few useful information on below topics :

 

MySQL, SQL Server, DB2, Linux/UNIX/AIX, HTML ....

Let the posts
come to you.

Thanks for submitting!

  • Instagram
  • Facebook
  • Twitter
© 2023 By ImJhaChandan
bottom of page