PostgreSQL
Database Management
Software Version
Tech Troubleshooting
Server Administration

Which version of PostgreSQL am I running?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

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:

  1. Open your terminal or command prompt.
  2. Connect to the PostgreSQL database by typing psql. You might need to provide a username, password, or other connection details depending on your setup.
  3. Once inside the PostgreSQL command line interface, execute the following SQL command:
sql
   SELECT version();

This query returns the PostgreSQL version along with some system information. The output typically looks like this:

 
PostgreSQL 12.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.3.0, 64-bit

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:
bash
  postgres -V
  • Windows: Open Command Prompt and type:
cmd
  postgres -V

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:

sql
SELECT version();

Additionally, if you need a more numeric-friendly version for version comparisons in scripts, you can use:

sql
SHOW server_version;

Or for even more specific usage:

sql
SHOW server_version_num;

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

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


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design