1 查看参数
在 openGauss 中,可配置参数被称为 GUC(Grand Unified Configuration),数据库安装后,在数据目录(data)下自动生成三个配置文件(postgresql.conf、pg_hba.conf和pg_ident.conf)。
1.1 参数说明
openGauss提供了六类GUC参数:
openGauss=# select distinct(context) from pg_settings;
context
------------
internal
user
postmaster
backend
sighup
superuser
(6 rows)
参数类型说明:
- INTERNAL:固定参数,在创建数据库的时候确定,用户无法修改,只能通过show语法或者pg_settings视图进行查看。
- POSTMASTER: 数据库服务端参数,在数据库启动时确定,可以通过配置文件指定。可以通过gs_guc set 和 ALTER SYSTEM SET 来修改。
- SIGHUP:数据库全局参数,可在数据库启动时设置或者在数据库启动后,发送指令重新加载。可以通过gs_guc set、gs_guc reload、ALTER SYSTEM SET 来修改。重启后生效。
- BACKEND:会话连接参数。在创建会话连接时指定,连接建立后无法修改。连接断掉后参数失效。内部使用参数,不推荐用户设置。但可以通过gs_guc set、gs_guc reload、ALTER SYSTEM SET 来修改。设置该参数后,下一次建立会话连接时生效。
- SUSET: 数据库管理员参数。可在数据库启动时、数据库启动后或者数据库管理员通过SQL进行设置。可以通过gs_guc set、gs_guc reload修改。
- USERSET:普通用户参数。可被任何用户在任何时刻设置。可以通过gs_guc set、gs_guc reload、ALTER DATABASE、ALTER USER 来修改。
简单的说,就是大部分参数都可以通过gs_guc set 和 gs_guc reload 来修改。
openGauss=# select name,setting,context,source from pg_settings where name like '%wal%';
name | setting | context | source
---------------------------------+-------------+------------+--------------------
enable_wal_shipping_compression | off | sighup | default
max_wal_senders | 16 | postmaster | configuration file
wal_block_size | 8192 | internal | default
wal_buffers | 2048 | postmaster | default
wal_file_init_num | 10 | postmaster | default
wal_flush_delay | 1 | sighup | default
wal_flush_timeout | 2 | sighup | default
wal_keep_segments | 16 | sighup | configuration file
wal_level | hot_standby | postmaster | configuration file
wal_log_hints | on | postmaster | default
wal_receiver_buffer_size | 65536 | postmaster | default
wal_receiver_connect_retries | 1 | sighup | default
wal_receiver_connect_timeout | 2 | sighup | default
wal_receiver_status_interval | 5 | sighup | default
wal_receiver_timeout | 6000 | sighup | default
wal_segment_size | 2048 | internal | default
wal_sender_timeout | 6000 | sighup | default
wal_sync_method | fdatasync | sighup | default
wal_writer_delay | 200 | sighup | default
walsender_max_send_size | 8192 | postmaster | configuration file
walwriter_cpu_bind | -1 | postmaster | default
walwriter_sleep_threshold | 500 | sighup | default
(22 rows)
完成的GUC 参数,直接参考官方手册:
1.2 查看所有参数
SHOW ALL;
SELECT * FROM pg_settings;
注意这里show all 内容较多,我们/a不显示表行列符号,方便查看:
openGauss=# /a
Output format is unaligned.
openGauss=# show all;
name|setting|description
acce_min_datasize_per_thread|500000kB|Used to estimate whether pushdown the plan to the compute pool.
acceleration_with_compute_pool|off|If true, agg/scan may run in compute pool.
advance_xlog_file_num|0|Sets the number of xlog files to be initialized in advance.
alarm_component|/opt/huawei/snas/bin/snas_cm_cmd|Sets the component for alarm function.
alarm_report_interval|10|Sets the interval time between two alarm report.
allocate_mem_cost|0|Sets the planner's estimate of the cost of allocate memory.
allow_concurrent_tuple_update|on|Allows concurrent tuple update.
allow_create_sysobject|on|Allows create or replace system object.
allow_system_table_mods|off|Allows modifications of the structure of system tables.
……
openGauss=# /d pg_settings
View "pg_catalog.pg_settings"
Column | Type | Modifiers
------------+---------+-----------
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 |
openGauss=# select name,setting,context,source from pg_settings;
1.3 查看某个参数值
openGauss=# SHOW server_version;
-[ RECORD 1 ]--+------
server_version | 9.2.4
openGauss=# /x
Expanded display is on.
openGauss=# SELECT * FROM pg_settings WHERE NAME='server_version';
-[ RECORD 1 ]-------------------------
name | server_version
setting | 9.2.4
unit |
category | Preset Options
short_desc | Shows the server version.
extra_desc |
context | internal
vartype | string
source | default
min_val |
max_val |
enumvals |
boot_val | 9.2.4
reset_val | 9.2.4
sourcefile |
sourceline |
2 修改参数
在上节讲参数类型时,我们可以看到对不同的参数类型,一共有4种修改方法。 在修改参数之前,我们要做的就是确认参数的类型,然后使用对应的方法。
2.1 GUC参数4种设置方式
2.1.1 方法1:gs_guc set | POSTMASTER、SIGHUP、BACKEND、USERSET
修改参数命令如下:
gs_guc set -D datadir -c "paraname=value"
-c 表示参数是一个字符串变量:-c parameter="'value'"或-c "parameter = 'value'"。
在所有数据库节点上同时设置某个参数。
gs_guc set -N all -I all -c "paraname=value"
在数据库节点上设置cm_agent某个参数。
gs_guc set -Z cmagent -c "paraname=value"
gs_guc set -Z cmagent -N all -I all -c "paraname=value"
在数据库节点上设置cm_server某个参数。
gs_guc set -Z cmserver -c "paraname=value"
gs_guc set -Z cmserver -N all -I all -c "paraname=value"
重启数据库使参数生效。
gs_om -t stop && gs_om -t start
关于gs_guc 的使用,参考帮助:
[dave@www.cndba.cn ~]$ gs_guc --help
2.1.2 方法2:gs_guc reload | SIGHUP、BACKEND、SUSET、USERSET
语法:
gs_guc reload -D datadir -c "paraname=value"
在所有数据库节点上同时设置某个参数。
gs_guc reload -N all -I all -c "paraname=value"
2.1.3 方法3:ALTER DATABASE/ ALTER USER | USERSET
修改指定数据库、用户、会话级别的参数。
设置数据库级别的参数
openGauss=# ALTER DATABASE dbname SET paraname TO value;
在下次会话中生效。
设置用户级别的参数
openGauss=# ALTER USER username SET paraname TO value;
在下次会话中生效。
设置会话级别的参数
openGauss=# SET paraname TO value;
修改本次会话中的取值。退出会话后,设置将失效。
SET设置的会话级参数优先级最高,其次是ALTER设置的,其中ALTER DATABASE设置的参数值优先级高于ALTER USER设置,这三种设置方式设置的优先级都高于gs_guc设置方式。
2.1.4 方法4:ALTER SYSTEM SET | BACKEND
设置POSTMASERT级别的参数
openGauss=# ALTER SYSTEM SET paraname TO value;
重启后生效。
设置SIGHUP级别的参数
openGauss=# ALTER SYSTEM SET paraname TO value;
立刻生效(实际等待线程重新加载参数略有延迟)。
设置BACKEND级别的参数
openGauss=# ALTER SYSTEM SET paraname TO value;
在下次会话中生效。
2.2 操作示例
2.2.1 gs_guc set 示例
查看参数类型:
openGauss=# show archive_mode;
archive_mode
--------------
off
(1 row)
openGauss=# select name,setting,context,source from pg_settings where name='archive_mode';
name | setting | context | source
--------------+---------+---------+---------
archive_mode | off | sighup | default
(1 row)
openGauss=#
SIGHUP表示数据库全局参数。
启用归档:
[dave@www.cndba.cn ~]$ gs_guc set -N all -I all -c "archive_mode=on";
The gs_guc run with the following arguments: [gs_guc -N all -I all -c archive_mode=on set ].
NOTICE: When wal_level set to minimal, parameters archive_mode can not be used.
Begin to perform the total nodes: 3.
Popen count is 3, Popen success count is 3, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 3, Command success count is 3, Command failure count is 0.
Total instances: 3. Failed instances: 0.
ALL: Success to perform gs_guc!
重启数据库使参数生效:
[dave@www.cndba.cn ~]$ gs_om -t stop && gs_om -t start
openGauss=# select name,setting,context,source from pg_settings where name='archive_mode';
name | setting | context | source
--------------+---------+---------+--------------------
archive_mode | on | sighup | configuration file
(1 row)
2.2.2 gs_guc reload 示例
openGauss=# select name,setting,context,source from pg_settings where name='authentication_timeout';
name | setting | context | source
------------------------+---------+---------+---------
authentication_timeout | 60 | sighup | default
(1 row)
[dave@www.cndba.cn ~]$ gs_guc reload -N all -I all -c "authentication_timeout = 59s"
The gs_guc run with the following arguments: [gs_guc -N all -I all -c authentication_timeout = 59s reload ].
Begin to perform the total nodes: 3.
Popen count is 3, Popen success count is 3, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 3, Command success count is 3, Command failure count is 0.
Total instances: 3. Failed instances: 0.
ALL: Success to perform gs_guc!
openGauss=# select name,setting,context,source from pg_settings where name='authentication_timeout';
name | setting | context | source
------------------------+---------+---------+--------------------
authentication_timeout | 59 | sighup | configuration file
(1 row)
2.2.3 ALTER DATABASE 示例
openGauss=# SHOW explain_perf_mode;
explain_perf_mode
-------------------
pretty
(1 row)
openGauss=# ALTER DATABASE postgres SET explain_perf_mode TO normal;
ALTER DATABASE
openGauss=# SHOW explain_perf_mode;
explain_perf_mode
-------------------
pretty
(1 row)
注意这里要下次会话才会生效。
用户级别,也是下次生效:
openGauss=# ALTER USER dave SET explain_perf_mode TO pretty;
ALTER ROLE
openGauss=# SHOW explain_perf_mode;
explain_perf_mode
-------------------
pretty
(1 row)
当前会话生效:
openGauss=# SET explain_perf_mode TO normal;
SET
openGauss=# SHOW explain_perf_mode;
explain_perf_mode
-------------------
normal
(1 row)
版权声明:本文为博主原创文章,未经博主允许不得转载。