Which version of PostgreSQL am I running?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Determining which version of PostgreSQL you are running is crucial for a variety of reasons including compatibility, performance optimizations, security updates, and understanding available features. PostgreSQL, an advanced open-source relational database system, has frequent updates and knowing the specific version can greatly influence how you manage databases and develop applications. Here, we will explore different methods to check the PostgreSQL version along with contextual explanations.
Command Line Query
The most straightforward method to find out the PostgreSQL version is by using SQL queries from the command line interface. Once PostgreSQL is installed, you can access the database using the psql command-line utility. Here’s how you can check the version:
- Open your terminal or command prompt.
- Connect to the PostgreSQL database by typing
psql. You might need to provide a username, password, or other connection details depending on your setup. - Once inside the PostgreSQL command line interface, execute the following SQL command:
This query returns the PostgreSQL version along with some system information. The output typically looks like this:
This information indicates that the PostgreSQL version is 12.3, running on a Linux system with a specific GCC version.
Using Terminal or Command Prompt
For those who prefer working directly from the terminal or command prompt without going into the PostgreSQL command line interface:
- Linux/MacOS: Open your terminal and type:
- Windows: Open Command Prompt and type:
Both commands should return the PostgreSQL version similar to postgres (PostgreSQL) 12.3.
PostgreSQL Administrative Functions
PostgreSQL offers administrative functions that can be queried to get meta-information including the version. The function version() can be used within any SQL query tool or interface:
Additionally, if you need a more numeric-friendly version for version comparisons in scripts, you can use:
Or for even more specific usage:
This will return an integer like 120003, which corresponds to version 12.3 where 12 is the major version and 003 is the minor version.
Importance of Knowing PostgreSQL Version
Knowledge of the PostgreSQL version can impact several aspects:
- Migration: Ensures compatibility when migrating databases.
- Feature Utilization: Newer versions may have additional features or improvements.
- Security: Older versions may have vulnerabilities that are addressed in later releases.
Summary Table
| Method | Description |
SELECT version(); | SQL query returning version with system info in psql. |
postgres -V (command-line) | Direct command to get PostgreSQL version outside psql. |
SHOW server_version; | SQL query returning only the version. |
SHOW server_version_num; | SQL query returning numeric version code. |
Understanding your PostgreSQL version through one of these methods ensures that you manage your databases effectively and harness the full potential of PostgreSQL features optimized to your specific version. Whether you are a database administrator or a developer, keeping abreast of version details is pivotal for your database strategy.

