3 Easy Ways To Check The Installed PostgreSQL Version

Check Your PostgreSQL Version

PostgreSQL (often shortened as Postgres) is a powerful open-source relational database management system (RDBMS) that efficiently organizes and manages large volumes of data. 

Unlike several other popular DBMS on the market, it is free to use, reliable, and offers a long list of robust features.

You’ll find PostgreSQL in several stacks that power business applications. So, whether you’re a seasoned developer or just starting out with databases, knowing how to check your PostgreSQL version is a fundamental skill. 

Once you know the current PostgreSQL version on your server, you can plan on leveraging the latest features and improvements and maintain compatibility with the current business application requirements.

This quick tutorial will run you through 3 easy ways to check the PostgreSQL version on your machine. 

An Overview of PostgreSQL Versions

PostgreSQL gets product updates regularly. Major updates come every year to introduce new features and major performance improvements. Simultaneously, the PostgreSQL team releases minor updates every three months to fix known security loopholes.

Three Ways to Check PostgreSQL Versions

Let’s start with the prerequisites before diving into checking PostgreSQL versions. 

Prerequisites

Before we begin, make sure you have:

  • Access to the command line
  • A server with an active PostgreSQL installation
  • Permission to work with the terminal and PostgreSQL database

Method #1: Find PostgreSQL Version in the Terminal

The fastest and easiest method is checking the PostgreSQL version from the command line. You don’t need to click through menus – instead, you can directly interact with the system using a simple command. 

Launch the terminal and run the following command: 

# postgres --version

Alternatively, you can run the following shorthand version of this command: 

# postgres -V

If you installed PostgreSQL from the official source, both these commands will display the version information. 

However, if you used an “unofficial” source, you might encounter the command ‘postgres’ not found error. 

How to Fix the command ‘postgres’ not found Error

To fix the problem, you need to find where PostgreSQL is on your system. You can do this by using the following command:

# locate bin/postgres

postgres locate bin

As you can see, on our test system, PostgreSQL can be found at /usr/lib/postgresql/14/bin/postgres. You can combine this path with the -V flag to get the current PostgreSQL version. 

# /usr/lib/postgresql/14/bin/postgres -V

As you can see in the following screenshot, the current version is 14.9. Here, 14 is the major version, and 9 is the minor version. 

usr lib postgres

Method #2: Find PostgreSQL Version Using the SQL Shell

You can also get the version number right from the PostgreSQL prompt. 

Start by launching the PostgreSQL shell with the following command. Note that you might need to provide your admin password.

# sudo -u postgres psql

On the SQL prompt, use the following statement to see the PostgreSQL version:

postgre=# SELECT version();

The result of this statement shows the PostgreSQL version information. 

postgres select version

You can also ask PostgreSQL to reveal the value of the server_version environment variable:

postgre=# SHOW server_version;

The result will show you the current value (version information) of the server_version variable.

show server version

Method #3: Find the Psql Client Version

The psql client is a great option for accessing and working with a PostgreSQL database. You can use it to query the database. 

You can use the following psql command to find out the version information:

# psql --version

You might notice that the commands to check the psql client utility version are similar to those for the PostgreSQL server version. In this case, you can use the -V option as well:

# psql -V

The SQL version is displayed in the terminal.

psql version

The command not found error can happen here, too. 

In this case, use the following command to find where the psql tool is located:

# locate bin/psql

The full path to the psql utility will be displayed in the output.

locate bin psql

Take the full path and add -V to it. This will show you the current psql version.

# /usr/lib/postgresql/14/bin/psql -V

The result will display the Psql client version you have on your computer:

postgresql bin psql

Conclusion

Checking your PostgreSQL version is essential for keeping your database system up-to-date and secure. 

Whether you use PostgreSQL for a website or application, understanding the version helps you make informed decisions. You can easily check it using the methods we discussed in this guide.

If you’re looking for a robust server for your PostgreSQL projects, RedSwitches offers the best dedicated server pricing and delivers instant dedicated servers, usually on the same day the order gets approved. Whether you need a dedicated server, a traffic-friendly 10Gbps dedicated server, or a powerful bare metal server, we are your trusted hosting partner.

FAQs

Q. Is PostgreSQL an open-source database management system?

Yes, PostgreSQL is an open-source database management system.

Q. How can I check the versions of PostgreSQL using the command line?

To check the PostgreSQL version using the command line utility, use the following syntax:

# postgres --version

Q. How can I find the PostgreSQL version using the SQL shell?

To find the PostgreSQL version using the SQL shell, follow these steps:

  • Open the SQL shell.
  • Connect to your PostgreSQL database server.
  • Type this command: # SELECT version();
  • The output will display the version of your installations of PostgreSQL.

Q. Can I determine the PostgreSQL database version without connecting to it?

No, you need to connect to the database using a PostgreSQL client tool or the SQL shell to determine the PostgreSQL version.

Q. How can I determine the major version of my PostgreSQL installation?

You can determine the major version of your PostgreSQL installation by checking the first two digits of the version number. For example, if your version is 9.6.2, the major release version is 9.

Q. What is the latest version of PostgreSQL?

As of the last update on September 14, 2023, the latest version of PostgreSQL is PostgreSQL 16.

Q. What are the steps required to install PostgreSQL on Linux?

To install PostgreSQL on Linux, you can follow these steps:

  • Update your package list: sudo apt update.
  • Install PostgreSQL: sudo apt install postgresql.
  • Verify the installation by checking the version: postgres –version.

Q. Can I check the PostgreSQL version using pgAdmin 4?

Yes, you can check the PostgreSQL version using pgAdmin 4. After connecting to your server, the version will be displayed in the Server Properties section.

Q. How can I check the minor version of my PostgreSQL installation?

You can check the minor release version of your PostgreSQL installation by checking the third digit of the version number. For example, if your version is 9.6.2, the minor version release is 2.

Jignesh J

Jignesh is a senior server administrator at RedSwitches. He keeps everything up & running while tackling advanced server management and high-availability cluster issues. He’s a big fan of blockchain and web security. When not at his terminal, he loves to work out and is a fitness freak. If you have any support issues, contact him at [email protected]

Related articles

Latest articles