SimpleBackupsSimpleBackups

How to check PostgreSQL version

Last updated on

Originally posted on

Have you ever had compatibility problems with specific features in a PostgreSQL database? The first thing in such cases is to check what version you are running on.

This guide covers every way to do it: pg_config, a server query, the psql shell, Windows, Linux and pgAdmin. Start with whichever matches your setup.

Check PostgreSQL version

pg_config Command

The first option is to check the database version using the pg_config command.

→ Open your terminal and run the following command:

pg_config --version

As a result, you will see the version of PostgreSQL installed on your system.



Server Query

The second way to check the database version is to query the server.

→ Open your terminal and access the PostgreSQL database using the psql command-line tool:

psql

→ Once you're in the PostgreSQL interactive shell, run the following SQL query:

SELECT version();

This query will return detailed version information about your PostgreSQL installation.



Direct use of psql interactive shell

If, for some reason, you don't want or can't use the previous two options, there is still a third way: checking directly within the psql interactive shell.

This method is especially handy when you are already working with the database and want to verify its version quickly.

→ Open your terminal and access the PostgreSQL database using the psql command-line tool:

psql -U your_username -d your_database_name

Replace your_username with your PostgreSQL username and your_database_name with the name of the database you want to connect to.

→ Once you are in the psql interactive shell, run the following SQL query:

SELECT version();

Typing or copy-pasting this query into the psql prompt and pressing Enter will display detailed information about your PostgreSQL installation, including the version number.



Check the PostgreSQL version on Windows

The commands above assume a Unix shell. On Windows the binaries are not on your PATH by default, which is why psql --version often returns "not recognized".

Command Prompt (cmd):

"C:\Program Files\PostgreSQL\16\bin\psql" --version

Change 16 to your installed major version. If you are not sure which folders exist, run dir "C:\Program Files\PostgreSQL".

PowerShell:

& 'C:\Program Files\PostgreSQL\16\bin\psql.exe' --version

PowerShell needs the call operator & in front of a quoted path, otherwise it treats the string as text and prints it back at you.

To use psql from any directory, add the bin folder to your PATH once:

$env:Path += ';C:\Program Files\PostgreSQL\16\bin'

That lasts for the current session. To make it permanent, add the same folder through System Properties, then Environment Variables.


Check the PostgreSQL version on Linux

On Debian and Ubuntu the client and the server can be different versions, and the one that matters depends on what you are debugging:

psql --version        # the client you are typing into
postgres -V           # the server binary
sudo -u postgres psql -c 'SHOW server_version;'   # the running server

If postgres -V reports "command not found", the binary lives under a versioned path rather than on your PATH:

ls /usr/lib/postgresql/          # lists the installed major versions
/usr/lib/postgresql/16/bin/postgres -V

On RHEL, CentOS and Fedora the equivalent path is /usr/pgsql-16/bin/.

To confirm the package the distribution installed, rather than the binary:

dpkg -l | grep postgresql        # Debian, Ubuntu
rpm -qa | grep postgresql        # RHEL, CentOS, Fedora

Check the PostgreSQL version in pgAdmin

pgAdmin shows the server version without any command line. Connect to the server, select it in the browser tree on the left, and open the Properties tab. The version appears in the Version field.

For the exact string, open the Query Tool on any database and run:

SELECT version();

That reports the server version. pgAdmin's own version is separate and lives under Help, then About.


FAQ

What is the difference between psql --version and SELECT version()?

psql --version reports the version of the client you are typing into. SELECT version() reports the version of the server you are connected to. They are often different, because a newer client can connect to an older server. When you are debugging a compatibility problem, the server version is usually the one that matters.

Why does psql --version say "command not found" or "not recognized"?

The binary is installed but not on your PATH. On Windows it lives under "C:\\Program Files\\PostgreSQL\\{version}\\bin". On Debian and Ubuntu it is under /usr/lib/postgresql/{version}/bin, and on RHEL and Fedora under /usr/pgsql-{version}/bin. Call it by full path, or add that folder to your PATH.

How do I check the PostgreSQL version without connecting to a database?

Use pg_config --version or postgres -V. Both read the installed binary and need no server connection or credentials. SELECT version() and SHOW server_version both require a working connection.

How do I check the PostgreSQL version in pgAdmin?

Select the server in the browser tree and open the Properties tab, where the version appears in the Version field. For the full string, run SELECT version() in the Query Tool. That reports the server version; pgAdmin's own version is under Help, then About.

The version matters for more than compatibility: restoring a dump into an older major version usually fails, so check both ends before you migrate. The complete guide to PostgreSQL backup covers which direction is safe.