The fastest way to check your PostgreSQL version
Open a terminal or command prompt and run psql --version. This command returns the version number of the PostgreSQL client installed on your machine, usually in seconds. If you have PostgreSQL installed and the command is recognized, you will see output like "psql (PostgreSQL) 15.2".
If the command does not work, PostgreSQL may not be installed, or the psql program may not be in your system's search path. On Windows, you may need to navigate to the PostgreSQL installation folder first, or add it to your PATH environment variable.
This method works on Linux, macOS, and Windows, and requires no database connection or login credentials.
Key Takeaways
- Run psql --version from your terminal to see the PostgreSQL client version instantly.
- If you are already connected to a database, SELECT version(); shows the server version and build details.
- The client version and server version can differ if you have multiple PostgreSQL installations or are connecting to a remote database.
- On Windows, you may need to add PostgreSQL to your PATH or run the command from the installation directory.
Checking the version when you are already connected to a database
If you are already logged into a PostgreSQL database through psql, you can check the server version without disconnecting. Run SELECT version(); at the psql prompt. This returns the full version string of the database server you are connected to, including the operating system it runs on and the build configuration.
This method is useful when you need to know the exact version of a remote database or when you want to verify that your client and server versions match. The output is more detailed than psql --version and includes information like "PostgreSQL 15.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.2.0, 64-bit".
Understanding the difference between client and server versions
The psql --version command shows the version of the PostgreSQL client — the program you use to connect to databases. The SELECT version(); command shows the version of the PostgreSQL server — the program that actually stores and manages your data. These can be different numbers if you have installed multiple versions of PostgreSQL or are connecting to a database on another machine.
In most cases, the client and server versions should be close to each other. A client that is much older than the server may not support newer features, and a client that is much newer than the server may have compatibility issues. If you see a significant version mismatch, check whether you are connecting to the correct database or whether you need to update one of the installations.
Checking the version on Windows
On Windows, the psql --version command may not work immediately if PostgreSQL was not added to your system PATH during installation. If you see "psql is not recognized as an internal or external command", navigate to the PostgreSQL installation folder first. This is usually C:\Program Files\PostgreSQL\15 (the number varies by version), and then to the bin subfolder.
From that folder, run psql --version. Alternatively, you can add the PostgreSQL bin folder to your PATH so the command works from any terminal window. To do this, search for "Environment Variables" in the Windows Start menu, click "Edit the system environment variables", then click "Environment Variables" at the bottom. Under "System variables", find "Path", click "Edit", and add the full path to your PostgreSQL bin folder (for example, C:\Program Files\PostgreSQL\15\bin). Click OK and restart your terminal.
Checking the version on Linux and macOS
On Linux and macOS, psql --version usually works immediately after PostgreSQL is installed. If it does not, PostgreSQL may not be in your PATH. Run which psql to see whether the system can find it. If the command returns nothing, PostgreSQL is not in your PATH.
If PostgreSQL was installed via a package manager like Homebrew on macOS or apt on Ubuntu, it should be in your PATH automatically. If you installed it manually or from source, you may need to add the installation folder to your PATH. On macOS with Homebrew, run brew --prefix postgresql to find the installation location, then add the bin folder to your PATH in your shell configuration file (usually ~/.bash_profile, ~/.zshrc, or ~/.bashrc).
Other ways to find version information
If you have access to the PostgreSQL data directory on the server, you can check the PG_VERSION file. This file contains only the major version number and is located in the main data folder (often /var/lib/postgresql/15/main on Linux). Open it with a text editor or run cat /var/lib/postgresql/15/main/PG_VERSION to see the version.
You can also check the version through the PostgreSQL configuration file, postgresql.conf, which is in the same data directory. However, this file does not directly state the version — you would need to cross-reference the configuration options with PostgreSQL documentation to infer it. The psql --version and SELECT version(); methods are faster and more reliable.
Frequently Asked Questions
What if psql --version shows a different version than SELECT version()?
You have a client and server version mismatch. The first command shows the version of the psql program on your machine; the second shows the version of the database server you are connected to. This happens when you have multiple PostgreSQL installations or are connecting to a remote database running a different version. Both versions should work together, but check your connection settings to make sure you are connecting to the intended server.
Can I check the version without installing PostgreSQL client tools?
If you have access to the server itself, you can check the PG_VERSION file in the data directory. If you are connecting remotely and do not have psql installed, you can use another database client like pgAdmin, DBeaver, or a programming language driver (Python, Node.js, etc.) to connect and run SELECT version();. However, the psql client is the simplest method and is included with any PostgreSQL installation.
Why does the version number have three parts (like 15.2.1)?
PostgreSQL uses semantic versioning. The first number is the major version (15), the second is the minor version (2), and the third is the patch version (1). Major versions introduce new features and may have breaking changes. Minor and patch versions contain bug fixes and security updates. You should update patch versions regularly for security, but major version upgrades require more planning because they may affect your applications.
Is there a way to check the version in a script or program?
Yes. In a shell script, capture the output of psql --version and parse it. In Python, use the psycopg2 library and run SELECT version(); through a database connection. In Node.js, use the pg library the same way. In SQL scripts, SELECT version(); works in any PostgreSQL client. The method depends on your environment and what you are trying to do with the version information.