How to Check PostgreSQL Version Quickly and Easily
To check the PostgreSQL version, run the SQL command
SELECT version(); inside the database. Alternatively, use the command line tool with psql --version or postgres -V to see the installed version.Syntax
The main ways to check PostgreSQL version are:
SELECT version();- runs inside the database and returns detailed version info.psql --version- runs in the command line and shows the client version.postgres -V- runs in the command line and shows the server version.
sql
SELECT version();Example
This example shows how to check the PostgreSQL version by running the SQL command inside the database and using the command line.
sql
/* Inside psql shell or any SQL client connected to PostgreSQL */ SELECT version(); /* In your terminal or command prompt */ psql --version postgres -V
Output
PostgreSQL 14.5 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit
psql (PostgreSQL) 14.5
postgres (PostgreSQL) 14.5
Common Pitfalls
Common mistakes when checking PostgreSQL version include:
- Running
SELECT version();outside a connected database session will fail. - Using
psql --versionshows the client version, which might differ from the server version. - Running
postgres -Vrequires thepostgresbinary to be in your system PATH.
sql
/* Wrong: Running SQL without connection */ SELECT version(); -- Fails if not connected /* Right: Connect first then run */ psql -d your_database SELECT version();
Quick Reference
| Method | Command | Description |
|---|---|---|
| SQL Query | SELECT version(); | Shows detailed PostgreSQL server version inside database. |
| Command Line | psql --version | Shows PostgreSQL client (psql) version. |
| Command Line | postgres -V | Shows PostgreSQL server binary version. |
Key Takeaways
Use
SELECT version(); inside a connected database to get full server version details.Use
psql --version in the terminal to check the client version.Use
postgres -V to check the server binary version from the command line.Ensure you are connected to the database before running SQL commands.
Client and server versions may differ; check both if needed.