SELECT version(); is the quickest way to check PostgreSQL version details: run it from psql, pgAdmin or any SQL client and the server answers with its exact release.
SELECT version();
Here’s the catch most guides skip. psql –version reports the psql client on your machine, not the server you’re connected to, and the two can be different releases.
Tested on PostgreSQL 18.6 on Windows 11, 11/17/2026.
How Do I Check the PostgreSQL Version With SQL?
I want the build string, the short version and the number. Once you connect to the PostgreSQL database, one file does all three:
psql -h localhost -U postgres -d dfq_pgcheckver -f check-version.sql -t
SELECT version();
SHOW server_version;
SHOW server_version_num;
Output:
PostgreSQL 18.6 on x86_64-windows, compiled by msvc-19.44.35229, 64-bit
18.6
180006

Same answer, three formats (-t hides the headers and row counts). version() adds the platform and compiler, SHOW server_version gives just 18.6, and server_version_num gives 180006.
Use server_version_num to Compare PostgreSQL Versions in Scripts
Never compare version strings in code: as text, ‘9.6’ sorts after ‘18.6’. The integer is major times 10,000 plus the minor, so 180006 is 18.6 and anything 180000 or higher is PostgreSQL 18.
I want a script that stops on anything older than 18 and prints client and server side by side. psql’s \if works like the PostgreSQL IF ELSE logic you’d write in PL/pgSQL:
SELECT current_setting('server_version_num')::int >= 180000
AS pg18_or_newer \gset
\echo psql client: :VERSION_NAME
\echo server: :SERVER_VERSION_NAME
\if :pg18_or_newer
\echo OK: server is PostgreSQL 18 or newer
\else
\echo Upgrade needed: server is older than 18
\endif
Output:
psql client: 18.6
server: 18.6
OK: server is PostgreSQL 18 or newer

You should see two 18.6 lines and the OK message. :VERSION_NAME is psql itself; :SERVER_VERSION_NAME is the server, refreshed on every connection.
Check the PostgreSQL Version From the Command Line (psql –version)
I want the version without logging in at all. These three binaries live in the server’s bin folder:
.\check-version-command-line.cmd
@echo off
psql --version
postgres -V
pg_config --version
Output:
psql (PostgreSQL) 18.6
postgres (PostgreSQL) 18.6
PostgreSQL 18.6

All three print 18.6, but each describes only the binary you ran. A remote server can be anything.
The psql docs warn that backslash commands may fail against a newer server. If you manage several servers from one laptop, they recommend the newest psql you have, because a new client copes with older servers better than the reverse.
How to Check the Postgres Version on Windows
I want the version without opening psql. The installer from PostgreSQL installation on Windows leaves a service and a registry key:
powershell -NoProfile -File .\check-postgresql-windows.ps1
Get-Service -Name 'postgresql*' | Format-Table Status, Name -AutoSize
$pg = Get-ItemProperty 'HKLM:\SOFTWARE\PostgreSQL\Installations\*'
"Version: $($pg.Version)"
"Folder: $($pg.'Base Directory')"
Output:
Status Name
------ ----
Running postgresql-x64-18
Version: 18.6-5
Folder: C:\Program Files\PostgreSQL\18

The service postgresql-x64-18 is running, and the key says 18.6-5. The -5 suffix comes from the EDB installer; version() on the same server still says 18.6.
Check the PostgreSQL Version on Linux and macOS
My test box is Windows, so I didn’t run these. They’re the standard paths from the PGDG packages (see installing PostgreSQL on Linux):
psql --version
sudo -u postgres psql -c "SELECT version();"
/usr/lib/postgresql/18/bin/postgres -V # Debian, Ubuntu
/usr/pgsql-18/bin/postgres -V # RHEL, Rocky, Fedora
pg_lsclusters # Debian/Ubuntu: every cluster
On Linux the server binary usually isn’t on the PATH, so plain postgres -V fails. macOS works the same way.
Check the PostgreSQL Version in pgAdmin
- Connect to the server in the Object Explorer.
- Open Tools > Query Tool.
- Run
SELECT version();and read the result in the Data Output tab.
Skip Help > About. It shows the pgAdmin release, which has its own numbering.
Find the Version in the Data Directory and Check Extension Versions
Every data directory holds a PG_VERSION file with its major version. Reading it needs a superuser or pg_read_server_files; pg_available_extensions lists extension versions:
SELECT trim(E'\n' FROM pg_read_file('PG_VERSION')) AS pg_version_file;
SELECT name, default_version, installed_version
FROM pg_available_extensions
WHERE name IN ('plpgsql', 'pgcrypto');
Output:
pg_version_file
-----------------
18
(1 row)
name | default_version | installed_version
----------+-----------------+-------------------
pgcrypto | 1.4 |
plpgsql | 1.0 | 1.0
(2 rows)
The file says 18; pgcrypto 1.4 is available but not installed. Compare your major with the PostgreSQL latest version and its support dates.
What Do the PostgreSQL Version Numbers Mean?
| Part | Example | What it tells you |
|---|---|---|
| Major | 18 | Features and on-disk format; changes need pg_upgrade or dump/restore |
| Minor | .6 | Bug and security fixes; install binaries and restart |
| Before 10 | 9.6.24 | Major was 9.6, minor was .24 |
On 11/17/2026 the versioning page lists 18.7 as the current minor, so my 18.6 test box is already one fix release behind. A minor update is a stop, install and Postgres restart.
Common Mistakes When You Check the PostgreSQL Version
The first query I typed wrong treated the setting as a column:
SELECT server_version;
Error:
psql:select-server-version-error.sql:1: ERROR: column "server_version" does not exist
LINE 1: SELECT server_version;
^
server_version is a setting, not a column. Read it with SHOW server_version or current_setting('server_version').
Next step: if version() won’t run because you can’t log in, work through could not connect to the PostgreSQL server first.
Related reading for other engines and tasks:
- Checking the version on SQL Server
- The same check on a MariaDB server
- Listing every database on your PostgreSQL server
- PostgreSQL system requirements by version
Frequently Asked Questions
Does psql show the server version when it connects?
Only when they differ: the banner then reads like psql (18.6, server 17.2).
How do I check the PostgreSQL version on Amazon RDS or Azure?
There’s no server shell, so postgres -V won’t help. SELECT version() works over any connection.
Can I change server_version_num?
No. It’s one of the read-only preset options, fixed at build time.
How long is PostgreSQL 18 supported?
Five years from its first release. The versioning policy lists 11/14/2030 as the final PostgreSQL 18 release.

Kumar Saurabh is a freelance software engineer who builds web and mobile apps with Next.js, React, Flutter and Python. From 2021 to 2024, Saurabh worked as an IT analyst and developer at TSInfo Technologies, writing technical articles on SQL and PostgreSQL. Saurabh writes the PostgreSQL, MySQL, MariaDB and MongoDB tutorials on DatabaseFAQs.com and holds a Master of Computer Applications (MCA) from Chandigarh University.