Several ways to check the server version of PostgreSQL

This article introduces several methods to check the PostgreSQL server version.

Method 1: SELECT version()

If you have connected to the PostgreSQL server, you can execute the following query statement to get the server version information:

SELECT version();

Here is an example of the returned 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 example output:

 server_version
----------------
 14.1
(1 row)

Alternatively, the configuration option server_version_num can return the server version number as an integer:

SHOW server_version_num;

 server_version_num
--------------------
 140001
(1 row)

Method 3: Command line tool

PostgreSQL provides many command-line tools, all of which can return corresponding version information. For example:

postgres --version

postgres (PostgreSQL) 14.1

You can also use the -V option.

Other commonly used command-line tools include pg_config, pg_ctl, initdb, etc. Note, however, that psql --version returns the version of the psql tool, not the server version.

Guess you like

Origin blog.csdn.net/horses/article/details/129105228