合 PG查看版本的几种方法
Tags: PGpg_configpg_controldata查看版本
查看PG版本的几种方法
SQL查询
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | [pg13@lhrpg ~]$ psql psql (13.3) Type "help" for help. postgres=# show server_version; server_version ---------------- 13.3 (1 row) postgres=# select version(); version --------------------------------------------------------------------------------------------------------- PostgreSQL 13.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit (1 row) C:\Users\lhrxxt>psql -U postgres -h192.168.66.35 -p15433 Password for user postgres: psql (13.3) Type "help" for help. postgres=# exit C:\Users\lhrxxt>psql -U postgres -h192.168.66.35 -p54325 Password for user postgres: psql (13.3, server 12.2 (Debian 12.2-2.pgdg100+1)) Type "help" for help. postgres=# show server_version; server_version -------------------------------- 12.2 (Debian 12.2-2.pgdg100+1) (1 row) |
“psql (13.3, server 12.2 (Debian 12.2-2.pgdg100+1))”说明psql的版本为13.3,而数据库服务器的版本为PG 12.2。
“psql (13.3)”说明psql和数据库的版本都是13.3。
pg_config
可以使用pg_config | grep VERSION
或pg_config --version
来查看:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | [pg13@lhrpg ~]$ pg_config --version PostgreSQL 13.3 [pg13@lhrpg ~]$ pg_config | grep VERSION VERSION = PostgreSQL 13.3 [pg13@lhrpg ~]$ pg_config BINDIR = /pg13/pg13/bin DOCDIR = /pg13/pg13/share/doc/postgresql HTMLDIR = /pg13/pg13/share/doc/postgresql INCLUDEDIR = /pg13/pg13/include PKGINCLUDEDIR = /pg13/pg13/include/postgresql INCLUDEDIR-SERVER = /pg13/pg13/include/postgresql/server LIBDIR = /pg13/pg13/lib PKGLIBDIR = /pg13/pg13/lib/postgresql LOCALEDIR = /pg13/pg13/share/locale MANDIR = /pg13/pg13/share/man SHAREDIR = /pg13/pg13/share/postgresql SYSCONFDIR = /pg13/pg13/etc/postgresql PGXS = /pg13/pg13/lib/postgresql/pgxs/src/makefiles/pgxs.mk CONFIGURE = '--prefix=/pg13/pg13' CC = gcc -std=gnu99 CPPFLAGS = -D_GNU_SOURCE CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 CFLAGS_SL = -fPIC LDFLAGS = -Wl,--as-needed -Wl,-rpath,'/pg13/pg13/lib',--enable-new-dtags LDFLAGS_EX = LDFLAGS_SL = LIBS = -lpgcommon -lpgport -lpthread -lz -lreadline -lrt -ldl -lm VERSION = PostgreSQL 13.3 [pg13@lhrpg ~]$ pg_config --help pg_config provides information about the installed version of PostgreSQL. Usage: pg_config [OPTION]... Options: --bindir show location of user executables --docdir show location of documentation files --htmldir show location of HTML documentation files --includedir show location of C header files of the client interfaces --pkgincludedir show location of other C header files --includedir-server show location of C header files for the server --libdir show location of object code libraries --pkglibdir show location of dynamically loadable modules --localedir show location of locale support files --mandir show location of manual pages --sharedir show location of architecture-independent support files --sysconfdir show location of system-wide configuration files --pgxs show location of extension makefile --configure show options given to "configure" script when PostgreSQL was built --cc show CC value used when PostgreSQL was built --cppflags show CPPFLAGS value used when PostgreSQL was built --cflags show CFLAGS value used when PostgreSQL was built --cflags_sl show CFLAGS_SL value used when PostgreSQL was built --ldflags show LDFLAGS value used when PostgreSQL was built --ldflags_ex show LDFLAGS_EX value used when PostgreSQL was built --ldflags_sl show LDFLAGS_SL value used when PostgreSQL was built --libs show LIBS value used when PostgreSQL was built --version show the PostgreSQL version -?, --help show this help, then exit With no arguments, all known items are shown. Report bugs to <pgsql-bugs@lists.postgresql.org>. PostgreSQL home page: <https://www.postgresql.org/> |
pg_controldata
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | [pg13@lhrpg ~]$ pg_controldata --version pg_controldata (PostgreSQL) 13.3 [pg13@lhrpg ~]$ pg_controldata --help pg_controldata displays control information of a PostgreSQL database cluster. Usage: pg_controldata [OPTION] [DATADIR] Options: [-D, --pgdata=]DATADIR data directory -V, --version output version information, then exit -?, --help show this help, then exit If no data directory (DATADIR) is specified, the environment variable PGDATA is used. Report bugs to <pgsql-bugs@lists.postgresql.org>. PostgreSQL home page: <https://www.postgresql.org/> |
查看告警日志
看log_directory数据库配置参数指向的目录,看该目录中的运行日志是否打印有"LOG: starting PostgreSQL XX.Y"的版本信息(XX和Y均为阿拉伯数字)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | postgres=# show log_directory; log_directory --------------- pg_log (1 row) postgres=# exit [pg13@lhrpg ~]$ cd /pg13/ archive/ backup/ pg13/ pgdata/ scripts/ soft/ [pg13@lhrpg ~]$ cd /pg13/pgdata/pg_log [pg13@lhrpg pg_log]$ ll total 16 -rw------- 1 pg13 postgres 0 Sep 24 00:00 postgresql-Fri.log -rw------- 1 pg13 postgres 0 Sep 27 00:00 postgresql-Mon.log -rw------- 1 pg13 postgres 0 Sep 18 00:00 postgresql-Sat.log -rw------- 1 pg13 postgres 1423 Sep 26 19:40 postgresql-Sun.log -rw------- 1 pg13 postgres 10671 Sep 23 18:03 postgresql-Thu.log -rw------- 1 pg13 postgres 0 Sep 21 00:00 postgresql-Tue.log -rw------- 1 pg13 postgres 0 Sep 22 00:00 postgresql-Wed.log [pg13@lhrpg pg_log]$ more postgresql-Thu.log | grep "LOG: starting PostgreSQL" 2021-09-23 15:51:20.484 CST [1271656] LOG: starting PostgreSQL 13.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit |
postgres
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | [pg13@lhrpg ~]$ postgres -V postgres (PostgreSQL) 13.3 [pg13@lhrpg ~]$ which postgres /pg13/pg13/bin/postgres [pg13@lhrpg ~]$ postgres --help postgres is the PostgreSQL server. Usage: postgres [OPTION]... Options: -B NBUFFERS number of shared buffers -c NAME=VALUE set run-time parameter -C NAME print value of run-time parameter, then exit -d 1-5 debugging level -D DATADIR database directory -e use European date input format (DMY) -F turn fsync off -h HOSTNAME host name or IP address to listen on -i enable TCP/IP connections -k DIRECTORY Unix-domain socket location -N MAX-CONNECT maximum number of allowed connections -o OPTIONS pass "OPTIONS" to each server process (obsolete) -p PORT port number to listen on -s show statistics after each query -S WORK-MEM set amount of memory for sorts (in kB) -V, --version output version information, then exit --NAME=VALUE set run-time parameter --describe-config describe configuration parameters, then exit -?, --help show this help, then exit Developer options: -f s|i|n|m|h forbid use of some plan types -n do not reinitialize shared memory after abnormal exit -O allow system table structure changes -P disable system indexes -t pa|pl|ex show timings after each query -T send SIGSTOP to all backend processes if one dies -W NUM wait NUM seconds to allow attach from a debugger Options for single-user mode: --single selects single-user mode (must be first argument) DBNAME database name (defaults to user name) -d 0-5 override debugging level -E echo statement before execution -j do not use newline as interactive query delimiter -r FILENAME send stdout and stderr to given file Options for bootstrapping mode: --boot selects bootstrapping mode (must be first argument) DBNAME database name (mandatory argument in bootstrapping mode) -r FILENAME send stdout and stderr to given file -x NUM internal use Please read the documentation for the complete list of run-time configuration settings and how to set them on the command line or in the configuration file. Report bugs to <pgsql-bugs@lists.postgresql.org>. PostgreSQL home page: <https://www.postgresql.org/> |
pg_config命令详解
pg_config — 获取已安装的PostgreSQL的信息
大纲
pg_config
[option
...]
描述
pg_config工具打印当前安装版本的PostgreSQL的配置参数。它的设计目的之一是便于想与PostgreSQL交互的软件包能够找到所需的头文件和库。
选项
要使用pg_config,提供一个或多个下列选项:
--bindir
打印用户可执行文件的位置。例如使用这个选项来寻找
psql
程序。这通常也是pg_config
程序所在的位置。--docdir
打印文档文件的位置。
--htmldir
打印 HTML 文档文件的位置。
--includedir
打印客户端接口的 C 头文件的位置。
--pkgincludedir
打印其它 C 头文件的位置。
--includedir-server
打印用于服务器编程的 C 头文件的位置。
--libdir
打印对象代码库的位置。
--pkglibdir
打印动态可载入模块的位置,或者服务器可能搜索它们的位置(其它架构独立数据文件可能也被安装在这个目录)。
--localedir
打印区域支持文件的位置(如果在PostgreSQL被编译时没有配置区域支持,这将是一个空字符串)。
--mandir
打印手册页的位置。
--sharedir
打印架构独立支持文件的位置。
--sysconfdir
打印系统范围配置文件的位置。
--pgxs
打印扩展 makefile 的位置。
--configure
打印当PostgreSQL被配置编译时给予
configure
脚本的选项。这可以被用来重新得到相同的配置,或者找出是哪个选项编译了一个二进制包(不过注意二进制包通常包含厂商相关的自定补丁)。参见下面的例子。--cc
打印用来编译PostgreSQL的
CC
变量值。这显示被使用的 C 编译器。--cppflags
打印用来编译PostgreSQL的
CPPFLAGS
变量值。这显示在预处理时需要的 C 编译器开关(典型的是-I
开关)。--cflags
打印用来编译PostgreSQL的
CFLAGS
变量值。这显示被使用的 C 编译器开关。--cflags_sl
本人提供Oracle(OCP、OCM)、MySQL(OCP)、PostgreSQL(PGCA、PGCE、PGCM)等数据库的培训和考证业务,私聊QQ646634621或微信db_bao,谢谢!