Have you ever had compatibility problems with specific features in a PostgreSQL database? The first thing in such cases is to check what version you are running on.
In this article, we will take you step-by-step through the process of checking the version of the PostgreSQL database - either on Linux or macOS.
pg_config
Command
The first option is to check the database version using the pg_config
command.
→ Open your terminal and run the following command:
pg_config --version
As a result, you will see the version of PostgreSQL installed on your system.
Server Query
The second way to check the database version is to query the server.
→ Open your terminal and access the PostgreSQL database using the psql
command-line tool:
psql
→ Once you're in the PostgreSQL interactive shell, run the following SQL query:
SELECT version();
This query will return detailed version information about your PostgreSQL installation.
Direct use of psql
interactive shell
If, for some reason, you don't want or can't use the previous two options, there is still a third way: checking directly within the psql
interactive shell.
This method is especially handy when you are already working with the database and want to verify its version quickly.
→ Open your terminal and access the PostgreSQL database using the psql
command-line tool:
psql -U your_username -d your_database_name
Replace your_username
with your PostgreSQL username and your_database_name
with the name of the database you want to connect to.
→ Once you are in the psql
interactive shell, run the following SQL query:
SELECT version();
Typing or copy-pasting this query into the psql
prompt and pressing Enter will display detailed information about your PostgreSQL installation, including the version number.