This article introduces several ways to view the PostgreSQL server version.
Method 1: SELECT version()
If you are already connected to the PostgreSQL server, you can execute the following query statement to obtain server version information:
SELECT version();
Here is an example that returns the result:
version ------------------------------------------------------------ PostgreSQL 14.1, compiled by Visual C++ build 1914, 64-bit (1 row)
Method 2: SHOW server_version
If you only need to get a simple server version number, you can use the configuration option server_version:
SHOW server_version;
Here is an output example:
server_version ---------------- 14.1 (1 row)
In addition, the configuration option server_version_num can return an integer server version number:
SHOW server_version_num; server_version_num -------------------- 140001 (1 row)
Method 3: Command line tool
PostgreSQL provides many command line tools that can return the corresponding version information. For example:
postgres --version postgres (PostgreSQL) 14.1
The -V option is also available.
Other commonly used command line tools include pg_config, pg_ctl, initdb, etc. However, it should be noted that psql --version returns the version of the psql tool, not the server version.
This is the end of this article about PostgreSQL’s several methods to view server versions. For more related PostgreSQL version content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!