用过Oracle的朋友都知道,在sqlplus里面可以通过show parameter +名字,然后就可以模糊查询到所有相关的参数(隐含参数并且没有修改的除外),如通过show parameter sga就可以把所有带有“sga”的参数都查询出来,如下:
SQL> show parameter sga
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
lock_sga boolean FALSE
pre_page_sga boolean FALSE
sga_max_size big integer 352M
sga_target big integer 0
SQL>
PostgresSQL里面也通过了show的命令,但是该命令只能show all,或者show + 具体参数名字,而不能模糊查询一些参数, 这样对于一些名字很长并且很难记住的参数就无法使用show 命令,比如这样一个autovacuum_multixact_freeze_max_age,一般平时很难记住完整的名字,使用show的时候就很难一下找到该参数,如:
postgres=# show autovacuum_multixact_freeze_max_age;
autovacuum_multixact_freeze_max_age
-------------------------------------
400000000
(1 row)
postgres=# show multixact;
ERROR: unrecognized configuration parameter "multixact"
postgres=#
postgres=#
如上,输入完整的参数名是可以show出来的,但是如果只是输入参数的一部分就无法使用。
为了达到show + 模糊查询的效果,可以在外部使用一个shell脚本,然后在psql里面使用,如下一个简单的shell脚本,名字叫show,调用该shell时需要传入参数名字
[postgres@postgres include]$ cat show
#!/bin/bash
psql -h127.0.0.1 -p5442 -d postgres -c 'show all;' | grep "$1"
[postgres@postgres include]$
psql中使用shell脚本
postgres=# \! show multixact
autovacuum_multixact_freeze_max_age | 400000000 | Multixact age at which to autovacuum a table to prevent multixact wraparound.
vacuum_multixact_freeze_min_age | 5000000 | Minimum age at which VACUUM should freeze a MultiXactId in a table row.
vacuum_multixact_freeze_table_age | 150000000 | Multixact age at which VACUUM should scan whole table to freeze tuples.
postgres=#
这样,就可以达到show +参数名字, 把包含该参数的所有的命令都显示出来