我在一个企业环境中(运行Debian Linux),没有自己安装它。我使用Navicat或phpPgAdmin访问数据库(如果有帮助的话)。我也没有运行数据库的服务器的shell访问权。
当前回答
对我来说
$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)
希望它能帮助到一些人
其他回答
从PostgreSQL运行这个查询:
SELECT version();
如果你已经在使用for工具(使用DBeaver)来连接PostgreSQL,它将是这样的:
使用VERSION特殊变量
$psql -c "\echo :VERSION"
使用pgadmin4,双击Servers > server_name_here > Properties选项卡> Version:
3.5版本:
4.1、4.5版本:
这是一个很老的问题,有很多很好的答案。我发现从版本12开始,简单地调用客户机就可以告诉我需要知道的内容,但是我在服务器的shell上运行它们。下面的示例带有输出。
当我在第12版的时候
$ sudo su postgres -c "psql"
psql (12.8 (Ubuntu 12.8-0ubuntu0.20.04.1))
我读这个是因为客户端和服务器都在版本12。
在我把Ubuntu从20.04升级到21.04之后:
$ sudo su postgres -c "psql"
psql (13.4 (Ubuntu 13.4-0ubuntu0.21.04.1), server 12.8 (Ubuntu 12.8-0ubuntu0.20.04.1))
它清楚地告诉我客户端在版本13上,但服务器仍然在版本12上,正如我确认的那样:
$ pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
12 main 5432 online postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log
顺便说一下,注意这个误导性的结果,在这个阶段:
$ pg_config --version
PostgreSQL 13.4 (Ubuntu 13.4-0ubuntu0.21.04.1)
我升级到14版后:
$ sudo su postgres -c "psql"
psql (14.0 (Ubuntu 14.0-1.pgdg21.04+1))
Type "help" for help.
postgres=#
再一次,我将其解释为客户端和服务器都在版本14上,再次确认:
$ pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
12 main 5432 down,binaries_missing postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log
14 main 5433 online postgres /var/lib/postgresql/14/main /var/log/postgresql/postgresql-14-main.log
顺便说一下,这个版本与运行SELECT version()获得的版本相同;查询