Oracle中查看参数是可以支持通配符的
一般在oracle中是输入 sqlplus “/ as sysdba”
SQL> show parameter back
可以显示出参数名中包含有back的参数,如background_dum_dest这个参数,不用输入太长的参数名,也不用很准确知道。
PostgreSQL在psql中的show是不支持通配符的
如要查询 data_directory 参数,是需要输入show data_directory;才能查询,或者是查询pg_settings。
postgres=# \d pg_settings;
postgres=# select name,setting from pg_settings where category like ‘File%’;
postgres=# \d pg_settings;
View "pg_catalog.pg_settings"
Column | Type | Collation | Nullable | Default
-----------------+---------+-----------+----------+---------
name | text | | |
setting | text | | |
unit | text | | |
category | text | | |
short_desc | text | | |
extra_desc | text | | |
context | text | | |
vartype | text | | |
source | text | | |
min_val | text | | |
max_val | text | | |
enumvals | text[] | | |
boot_val | text | | |
reset_val | text | | |
sourcefile | text | | |
sourceline | integer | | |
pending_restart | boolean | | |
postgres=# select name,setting from pg_settings where category like 'File%';
name | setting
-------------------+-----------------------------------------
config_file | /etc/postgresql/15/main/postgresql.conf
data_directory | /var/lib/postgresql/15/main
extension_destdir |
external_pid_file | /var/run/postgresql/15-main.pid
hba_file | /etc/postgresql/15/main/pg_hba.conf
ident_file | /etc/postgresql/15/main/pg_ident.conf
(6 rows)
编写一个show.sh的脚本
编写一个show.sh,然后授权为可执行,如chmod u+x show.sh
postgres@master:~/scripts$ cat show.sh
psql -c 'show all;'|grep $1
然后可以执行:
postgres@master:~/scripts$ ./show.sh data_
data_checksums | off | Shows whether data checksums are turned on for this cluster.
data_directory | /var/lib/postgresql/15/main | Sets the server's data directory.
data_directory_mode | 0700 | Shows the mode of the data directory.
data_sync_retry | off | Whether to continue running after a failure to sync data files.
为了不输入./,而是在任意目录下可以执行show.sh xxxx,其中xxxx表示参数的名称,可以是名称的一部分,有时记不住或者写不了太长的参数名,如要查log_destination参数,可以输入show.sh log_d,需要把存放show.sh的~/scripts目录加入$PATH中。
postgres@master:~$ cat .profile
PATH=/usr/lib/postgresql/15/bin:~/scripts:$PATH
export PATH
PGDATA=/etc/postgresql/15/main
export PGDATA
#我自己定义的DATA变量,用于记录postgreSQL数据库的数据文件存放位置
export DATA=`cat $PGDATA/postgresql.conf|grep data_direc|awk '{print $3 }'|sed "s/'//g"`
export LOG='/var/log/pg_log'
TZ='Asia/Shanghai'; export TZ
建立和配置好了show.sh后,并定义好搜索路径,就可以在linux环境下用show.sh 参数名来查询参数了,可勉强实现通配符的功能,参数名无需写完整,处理思路是查询全部参数,然后用grep过滤出包含指定的字符串。
show.sh使用例子
如要查询log目录,但是记不住参数名,可以先查log,然后再过滤dir。因为习惯使用了oracle的show parameter的部分字符串检索的功能,所以弄了这个变通的方法来实现。
postgres@master:~$ show.sh log|grep dir
log_directory | /var/log/pg_log | Sets the destination directory for log files.