我运行的是哪个版本的 PostgreSQL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13733719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Which version of PostgreSQL am I running?
提问by Highly Irregular
I'm in a corporate environment (running Debian Linux) and didn't install it myself. I access the databases using Navicat or phpPgAdmin (if that helps). I also don't have shell access to the server running the database.
我在公司环境中(运行 Debian Linux)并且没有自己安装它。我使用 Navicat 或 phpPgAdmin 访问数据库(如果有帮助)。我也没有对运行数据库的服务器的 shell 访问权限。
回答by Highly Irregular
Run this query from PostgreSQL:
从 PostgreSQL 运行此查询:
SELECT version();
回答by Highly Irregular
I believe this is what you are looking for,
我相信这就是你要找的
Server version:
服务器版本:
pg_config --version
Client version:
客户端版本:
psql --version
回答by Acumenus
Using CLI:
使用命令行:
Server version:
服务器版本:
$ 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
If having more than one installation of PostgreSQL, or if getting the "postgres: command not found
" error:
如果安装了多个 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
If locate
doesn't help, try find
:
如果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
Although postmaster
can also be used instead of postgres
, using postgres
is preferable because postmaster
is a deprecated alias of postgres
.
虽然postmaster
也可以用来代替postgres
,但postgres
最好使用,因为它postmaster
是 的不推荐使用的别名postgres
。
Client version:
客户端版本:
As relevant, login as postgres
.
根据相关情况,以身份登录postgres
。
$ psql -V # Or --version
psql (PostgreSQL) 9.6.1
If having more than one installation of PostgreSQL:
如果安装了多个 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
Using SQL:
使用 SQL:
Server version:
服务器版本:
=> 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;
.
如果更好奇,请尝试=> 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.
值得一提的是,可以在其中执行 shell 命令psql
以显示psql
路径中可执行文件的客户端版本。请注意,运行psql
可能与路径中的运行不同。
=> \! psql -V
psql (PostgreSQL) 9.2.9
回答by simhumileco
If you're using CLIand you're a postgres
user, then you can do this:
如果您使用CLI并且您是postgres
user,那么您可以执行以下操作:
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)
回答by Michel Milezzi
The accepted answer is great, but if you need to interact programmatically with PostgreSQL version maybe it's better to do:
接受的答案很好,但如果您需要以编程方式与 PostgreSQL 版本交互,最好这样做:
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.:
它将以整数形式返回服务器版本。这是在PostgreSQL 源代码中测试服务器版本的方式,例如:
/*
* 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...
*/
回答by vipin cp
Execute command
执行命令
psql -V
Where
在哪里
Vmust be in capital.
V必须是大写的。
回答by Diego Santa Cruz Mendezú
in shell psql.exe , execute
在 shell psql.exe 中,执行
\! psql -V
回答by jmunsch
回答by Alex Trn
A simple way is to check the version by typing psql --version
in terminal
一种简单的方法是通过psql --version
在终端中键入来检查版本
回答by Donato
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 命令将报告 PostgreSQL 程序的安装目录 (--bindir)、C 包含文件 (--includedir) 和目标代码库 (--libdir) 的位置以及 PostgreSQL 的版本 (--version) :
$ pg_config --version
PostgreSQL 9.3.6