How To Check the PostgreSQL Version

April 25, 2021 in Tutorial3 minutes

Introduction {#h-introduction} In this tutorial we learn how to check the PostgreSQL version installed on a system. There are multiple methods to check PostgreSQL version and we will learn each of the method. ## PostgreSQL Versioning {#h-postgresql-versioning} Starting from version 10. PostgreSQL using the following pattern for it’s versioning number MAJOR.MINOR For example 10.1, 11.2, 12.3, and 13.0. Before version 10. The major version use two number separated by dot. For example: _ PostgreSQL version 9.5.10 the major version is 9.5 and minor 10. _ PostgreSQL version 9.6.4 the major version is 9.6 and minor version 4. Understanding this difference is important to know if you need to do upgrade or have to match application requirements with specific major version of PostgreSQL or minor version of PostgreSQL ## Check PostgreSQL Version From Command Line {#h-check-postgresql-version-from-command-line} The first method to check the PostgreSQL version is to use the command line. On the system running PostgreSQL we can use the command below: postgres --version Another method to check the version of PostgreSQL from the command line is using the command below: postgres -V ## Check PostgreSQL Version From SQL {#h-check-postgresql-version-from-sql} The second method that we can use to check the PostgreSQL version is from the SQL shell. First, we need to change the user to the postgres user. Then we connect to the local PostgreSQL database using the psql command. psql After connected to PostgreSQL shell we can use one the following query: SELECT version(); Another query that we can run on PostgreSQL shell to get the running version is using the following query SHOW server_version; ## How can I locate the correct path to psql utility if it’s not found? To locate the correct path to the psql utility if it is not found, you can follow these steps: Open your terminal or command prompt. Use the locate command to search for the psql binary folder. Enter the following command: locate bin/psql The locate command will display a list of paths where the psql utility is installed on your system. Look for the appropriate path based on your specific installation. Once you have located the binary folder, you need to find the path to the psql executable within that folder. Typically, the executable is named psql or psql.exe. Copy the full path to the psql executable. To verify that you have the correct path, open your terminal or command prompt and enter the following command: psql --version For example, if the full path to the psql executable is /usr/bin/psql, you would run: /usr/bin/psql --version The terminal will display the version of PostgreSQL associated with the psql utility. By following these steps, you will be able to locate the correct path to the psql utility on your system if it is not found initially. ## Video Tutorial {#h-video-tutorial}
## Summary {#h-summary} In this tutorial we learn how to check the version of PostgreSQL on the running system using two different methods, the first one is using shell command line and the second method is using SQL shell.