How to Check PostgreSQL Version (SQL, psql, Windows, Linux)

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
VS Code terminal: SELECT version() returns PostgreSQL 18.6 and SHOW server_version_num returns 180006
version(), server_version and server_version_num all report PostgreSQL 18.6

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
psql script comparing server_version_num to 180000 and printing VERSION_NAME and SERVER_VERSION_NAME
The psql client and the server both report 18.6, and the 180000 check passes

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
Command line output: psql --version, postgres -V and pg_config --version all print PostgreSQL 18.6
psql –version, postgres -V and pg_config –version print 18.6 on this machine

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
PowerShell Get-Service shows postgresql-x64-18 Running and the registry key shows Version 18.6-5
The Windows service name gives the major version; the registry key gives 18.6

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

  1. Connect to the server in the Object Explorer.
  2. Open Tools > Query Tool.
  3. 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?

PartExampleWhat it tells you
Major18Features and on-disk format; changes need pg_upgrade or dump/restore
Minor.6Bug and security fixes; install binaries and restart
Before 109.6.24Major 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:

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.