我在公司环境中(运行Debian Linux)并没有自己安装它。我使用Navicat或phpPgAdmin访问数据库(如果有帮助的话)。我也没有shell访问运行数据库的服务器。
答案 0 :(得分:1361)
从PostgreSQL运行此查询:
SELECT version();
答案 1 :(得分:460)
我相信这就是你要找的东西,
服务器版本:
pg_config --version
客户端版本:
psql --version
答案 2 :(得分:201)
$ 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
,因为postmaster
是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
=> 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
如果更加好奇,请尝试=> SHOW all;
。
对于它的价值,可以在psql
内执行shell命令,以显示路径中psql
可执行文件的客户端版本。请注意,正在运行的psql
可能与路径中的不同。
=> \! psql -V
psql (PostgreSQL) 9.2.9
答案 3 :(得分:33)
执行命令
psql -V
其中
V 必须是大写。
答案 4 :(得分:22)
接受的答案很棒,但如果您需要以编程方式与PostgreSQL版本进行交互,那么最好这样做:
SELECT current_setting('server_version_num'); -- Returns 90603 (9.6.3)
-- Or using SHOW command:
SHOW server_version_num; -- Returns 90603 too
它将服务器版本作为整数返回。这是在PostgreSQL source中测试服务器版本的方式,例如:
/*
* 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...
*/
答案 5 :(得分:21)
如果您使用的是 CLI ,并且您是postgres
用户,则可以执行以下操作:
psql -c "SELECT version();"
可能的输出:
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)
答案 6 :(得分:20)
在shell psql.exe中,执行
\! psql -V
答案 7 :(得分:10)
使用tmp = {}
for i in l:
if not i['a'] in tmp:
tmp[i['a']] = {}
if not i['b'] in tmp[i['a']]:
tmp[i['a']][i['b']] = {}
if not i['c'] in tmp[i['a']][i['b']]:
tmp[i['a']][i['b']][i['c']] = {}
tmp[i['a']][i['b']][i['c']][i['d']] = some_value
可以通过双击服务器> server_name_here>属性选项卡>版本来查看:
版本3.5:
版本4.1、4.5:
答案 8 :(得分:8)
pg_config命令将报告安装PostgreSQL程序的目录(--bindir),C包含文件(--includedir)和目标代码库(--libdir)的位置,以及PostgreSQL的版本( - -version):
$ pg_config --version
PostgreSQL 9.3.6
答案 9 :(得分:8)
就我而言
$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)
希望它会帮助某人
答案 10 :(得分:8)
一种简单的方法是通过在终端中输入psql --version
来检查版本
答案 11 :(得分:3)
不知道这有多可靠,但您可以完全自动获得两个版本的令牌:
psql --version 2>&1 | tail -1 | awk '{print $3}' | sed 's/\./ /g' | awk '{print $1 "." $2}'
因此,您可以构建二进制文件的路径:
/usr/lib/postgresql/9.2/bin/postgres
只需用此命令替换9.2。
答案 12 :(得分:3)
如果你在debian / ubuntu系统上有shell访问服务器(提出op没有的问题,但万一你有),
sudo apt-cache policy postgresql
将输出已安装的版本
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
其中Installed: <version>
是已安装的postgres包版本。
答案 13 :(得分:2)
答案 14 :(得分:2)
检查PostgreSQL Database Version的有用查询
bash-4.1$ psql
postgres=# SELECT version();
postgres=# SHOW server_version;
检查 PostgreSQL 客户端版本。
bash-4.1$ psql --version
psql (PostgreSQL) 12.1
答案 15 :(得分:2)
答案 16 :(得分:0)
如果Select version()
与Memo一起返回,请尝试以这种方式使用命令:
Select version::char(100)
或
Select version::varchar(100)
答案 17 :(得分:0)
使用VERSION
特殊变量
$psql
postgres=# \echo :VERSION