How to check PostgreSQL version

SimpleBackups founder

Laurent Lemaire

Co-founder, SimpleBackups

November 21st, 2023

Knowing the version of your PostgreSQL database is crucial for various reasons, such as compatibility with specific features or troubleshooting issues. In this article, we'll explore how to check the PostgreSQL database version on both Linux and macOS. We'll provide step-by-step instructions and code snippets to guide developers through this essential task.

Check PostgreSQL version

Checking PostgreSQL Version using the pg_config Command

To check the PostgreSQL database version, you can use the pg_config command or query the database server. Here's how to do it:

→ Open your terminal and run the following command:

pg_config --version

This command will display the PostgreSQL version installed on your system.



Check Postgres Version from SQL

You can also query the database server to obtain the version information. Follow these steps:

→ 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.

Certainly, here's a paragraph that you can add to the article to explain how to check the PostgreSQL version using psql:



Check PostgreSQL Version psql

In addition to using the pg_config command and SQL queries, you can also check the PostgreSQL version directly within the psql interactive shell. This method can be especially useful when you're already working with the database and want to quickly verify the version.

→ 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. This quick method is handy for developers who work extensively with PostgreSQL databases and need to check the version while already connected to the database.



Conclusion

Knowing how to check the PostgreSQL database version is a fundamental skill for any developer working with PostgreSQL. Whether you are on Linux or macOS, you can use either the pg_config command or SQL queries to obtain the version information. By following the steps and using the code snippets provided in this article, you can easily determine the PostgreSQL version on your system, ensuring compatibility and making informed decisions for your database-related tasks.



Back to blog

Stop worrying about your backups.
Focus on building amazing things!

Free 7-day trial. No credit card required.

Have a question? Need help getting started?
Get in touch via chat or at [email protected]

Customer support with experts
Security & privacy first
Service that you'll love using