[2021-06-08]PostgresSQL 查看参数

本文介绍了在PostgreSQL中如何通过编写Shell脚本来实现类似于Oracle的show命令模糊查询参数功能。在PostgreSQL中,show命令不支持模糊查询,但通过一个简单的bash脚本,可以结合psql命令和grep工具,实现输入参数部分名称就能显示所有相关参数的值。这种方法对于记住长且复杂的参数名非常有帮助。
摘要由CSDN通过智能技术生成

用过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 +参数名字, 把包含该参数的所有的命令都显示出来

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值