developer tip

어떤 버전의 PostgreSQL을 실행하고 있습니까?

optionbox 2020. 9. 28. 09:00
반응형

어떤 버전의 PostgreSQL을 실행하고 있습니까?


회사 환경 (Debian Linux 실행)에 있으며 직접 설치하지 않았습니다. Navicat 또는 phpPgAdmin을 사용하여 데이터베이스에 액세스합니다 (도움이되는 경우). 또한 데이터베이스를 실행하는 서버에 대한 셸 액세스 권한이 없습니다.


PostgreSQL에서이 쿼리를 실행합니다.

SELECT version();

나는 이것이 당신이 찾고있는 것이라고 믿습니다.

서버 버전 :

pg_config --version

클라이언트 버전 :

psql --version

CLI 사용 :

서버 버전 :

$ postgres -V  # Or --version.  Use "locate bin/postgres" if not found.
postgres (PostgreSQL) 9.6.1
$ postgres -V | awk '{print $NF}'  # Last column is version.
9.6.1
$ postgres -V | egrep -o '[0-9]{1,}\.[0-9]{1,}'  # Major.Minor version
9.6

PostgreSQL이 두 개 이상 설치되어 있거나 " postgres: command not found"오류가 발생하는 경우 :

$ locate bin/postgres | xargs -i xargs -t '{}' -V  # xargs is intentionally twice.
/usr/pgsql-9.3/bin/postgres -V 
postgres (PostgreSQL) 9.3.5
/usr/pgsql-9.6/bin/postgres -V 
postgres (PostgreSQL) 9.6.1

locate도움 되지 않으면 다음을 시도하십시오 find.

$ sudo find / -wholename '*/bin/postgres' 2>&- | xargs -i xargs -t '{}' -V  # xargs is intentionally twice.
/usr/pgsql-9.6/bin/postgres -V 
postgres (PostgreSQL) 9.6.1

postmaster대신을 사용할 수도 있지만 더 이상 사용되지 않는 별칭 이므로 postgres사용하는 postgres것이 좋습니다 .postmasterpostgres

클라이언트 버전 :

관련이 있으면로 로그인하십시오postgres .

$ psql -V  # Or --version
psql (PostgreSQL) 9.6.1

둘 이상의 PostgreSQL 설치가있는 경우 :

$ locate bin/psql | xargs -i xargs -t '{}' -V  # xargs is intentionally twice.
/usr/bin/psql -V 
psql (PostgreSQL) 9.3.5
/usr/pgsql-9.2/bin/psql -V 
psql (PostgreSQL) 9.2.9
/usr/pgsql-9.3/bin/psql -V 
psql (PostgreSQL) 9.3.5

SQL 사용 :

서버 버전 :

=> SELECT version();
                                                   version                                                    
--------------------------------------------------------------------------------------------------------------
 PostgreSQL 9.2.9 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4), 64-bit

=> SHOW server_version;
 server_version 
----------------
 9.2.9

=> SHOW server_version_num;
 server_version_num 
--------------------
 90209

If more curious, try => SHOW all;.

Client version:

For what it's worth, a shell command can be executed within psql to show the client version of the psql executable in the path. Note that the running psql can potentially be different from the one in the path.

=> \! psql -V
psql (PostgreSQL) 9.2.9

If you're using CLI and you're a postgres user, then you can do this:

psql -c "SELECT version();"


Possible output:

                                                         version                                                         
-------------------------------------------------------------------------------------------------------------------------
 PostgreSQL 11.1 (Debian 11.1-3.pgdg80+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10+deb8u2) 4.9.2, 64-bit
(1 row)

Execute command

psql -V

Where

V must be in capital.


The accepted answer is great, but if you need to interact programmatically with PostgreSQL version maybe it's better to do:

SELECT current_setting('server_version_num'); -- Returns 90603 (9.6.3)
-- Or using SHOW command:
SHOW server_version_num; -- Returns 90603 too

It will return server version as an integer. This is how server version is tested in PostgreSQL source, e.g.:

/*
 * This is a C code from pg_dump source.
 * It will do something if PostgreSQL remote version (server) is lower than 9.1.0
 */
if (fout->remoteVersion < 90100)
    /*
     * Do something...
     */  

More info here and here.


in shell psql.exe , execute

\! psql -V

Using pgadmin4 it can be seen by double clicking Servers > server_name_here > Properties tab > Version:

Version 3.5:

pgadmin4 show postgres version. Servers > server_name > Properties > Version

Version 4.1, 4.5:

enter image description here


A simple way is to check the version by typing psql --version in terminal


In my case

$psql
postgres=# \g
postgres=# SELECT version();
                                                       version
---------------------------------------------------------------------------------------------------------------------
 PostgreSQL 8.4.21 on x86_64-pc-linux-gnu, compiled by GCC gcc-4.6.real (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3, 64-bit
(1 row)

Hope it will help someone


The pg_config command will report the directory where the PostgreSQL programs are installed (--bindir), the location of C include files (--includedir) and object code libraries (--libdir), and the version of PostgreSQL (--version):

$ pg_config --version
PostgreSQL 9.3.6

If you have shell access to the server (the question mentions op does not have, but in case you have,) on a debian/ubuntu system

sudo apt-cache policy postgresql

which will output the installed version,

postgresql:
  Installed: 9.6+184ubuntu1.1
  Candidate: 9.6+184ubuntu1.1
  Version table:
 *** 9.6+184ubuntu1.1 500
        500 http://in.archive.ubuntu.com/ubuntu artful-updates/main amd64 Packages
        500 http://in.archive.ubuntu.com/ubuntu artful-updates/main i386 Packages
        500 http://security.ubuntu.com/ubuntu artful-security/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu artful-security/main i386 Packages
        100 /var/lib/dpkg/status
     9.6+184ubuntu1 500
        500 http://in.archive.ubuntu.com/ubuntu artful/main amd64 Packages
        500 http://in.archive.ubuntu.com/ubuntu artful/main i386 Packages

where the Installed: <version> is the installed postgres package version.


Don’t know how reliable this is, but you can get two tokens of version fully automatically:

psql --version 2>&1 | tail -1 | awk '{print $3}' | sed 's/\./ /g' | awk '{print $1 "." $2}'

So you can build paths to binaries:

/usr/lib/postgresql/9.2/bin/postgres

Just replace 9.2 with this command.


If Select version() returns with Memo try using the command this way:

Select version::char(100) 

or

Select version::varchar(100)

참고URL : https://stackoverflow.com/questions/13733719/which-version-of-postgresql-am-i-running

반응형