首页 > 数据库 > 国内数据库 > GaussDB 集群参数管理(GUC)
GaussDB 的物理参数均保存在
gaussdb.conf 和
pg_hba.conf 配置文件中。根据内核控制范围,参数分为以下六种级别:
| 参数类型 | 作用域与控制级别 | 标准修改方式 | 生效时机 |
|---|---|---|---|
| INTERNAL | 静态固定参数,建库时确定。 | 无法修改,仅供
SHOW 查看。 |
固定 |
| POSTMASTER | 服务端核心参数(如内存、连接数)。 | gs_guc set | 必须重启集群 |
| SIGHUP | 数据库全局参数。 | gs_guc reload | 即时生效 (免重启) |
| BACKEND | 内部会话连接参数,不推荐用户设置。 | gs_guc reload | 下次新建立会话时生效 |
| SUSET | 数据库管理员(SYSADMIN)参数。 | gs_guc reload 或 管理员 SQL SET | 依修改方式确定 |
| USERSET | 普通用户参数。 | gs_guc reload 或 任意用户 SQL SET | 立即生效 |
gs_initdb 初始化数据库时就已经彻底定死。SHOW 语法或
pg_settings 视图进行人肉查看,常用于检查版本和核心块大小。blocksize:数据库标准的逻辑数据块大小(默认是 8192 字节)server_version:当前高斯数据库的内核核心大版本号。gaussdb=> SELECT current_setting('block_size')::int;
current_setting
-----------------
8192
(1 row)
gaussdb=> SELECT current_setting('server_version');
current_setting
-----------------
9.2.4
(1 row)
gaussdb=> show server_version;
server_version
----------------
9.2.4
(1 row)
gs_guc set 命令修改配置文件。gs_om -t restart)才会生效。在线执行
reload 会直接被内核拒绝。max_process_memory:单节点物理能够使用的最大总内存。shared_buffers:数据库用来缓存数据页面的共享内存缓冲区大小max_connections:允许客户端最大并发连入的连接数。port:数据库监听的 TCP 业务端口。gs_guc reload 命令,内核会向主进程发送 SIGHUP 信号量,秒级通知全网所有节点重新加载参数。synchronous_commit:主备流复制的事务提交安全级别(如 on、local)。synchronous_standby_names:强同步备机的选择策略(如 ANY 1(dn_6002))。log_destination:数据库日志的输出目的地(如 stderr、csvlog)。gs_guc reload,当旧连接断开、新连接进来时,新连接会读取到新值。log_connections:每次有新连接成功连入数据库时,是否在服务器日志里打印一条登录痕迹(通常在线开启用来抓取恶意扫描)。log_disconnections:当客户端断开连接时,是否在日志中记录其在线时长。maintenance_work_mem:执行 CREATE INDEX、VACUUM(清理碎片)等大型维护操作时,单条 SQL 可以使用的最大内存。work_mem:单条查询在进行高级 ORDER BY 或 Hash Join 时,允许在内存中消耗的容量。enable_nestloop:优化器强制关闭或开启“嵌套循环连接”路径。enable_nestloop/
enable_hashjoin:执行计划执行路径的选择开关。DateStyle:控制当前窗口查出来的日期时间显示格式。search_path:控制默认的模式检索优先顺序。explain_perf_mode:控制执行
EXPLAIN 查看执行计划时的输出样式。在实际运维中,我们不需要去记录每个参数的类型,查询字典视图
pg_settings的
context 字段即可。
-- 示例:查询 max_process_memory 的参数分类 SELECT name, setting, context, short_desc FROM pg_settings WHERE name = 'max_process_memory'; name | setting | context | short_desc --------------------+----------+------------+-------------------------------------------------------- max_process_memory | 10485760 | postmaster | Sets the maximum number of memory used by the process. (1 row)
gs_guc {set | reload | check} -Z NODE-TYPE [-N NODE-NAME] [-I INSTANCE-NAME | -D DATADIR] -c "parameter='value'"
参数说明:
-Z 节点类型:最常用的是
coordinator (CN) 和
datanode (DN)。-Z、多个
-N 或多个
-I。如需同时修改 CN 和 DN,必须拆分为两条命令分别下发!set:仅修改配置文件,通常用于需要重启的
POSTMASTER 参数。reload:修改配置文件并向内核发送信号量,用于
SIGHUP 参数的在线即时重载。gs_guc 全局修改gs_guc check 检查参数在变更参数前,查看当前参数值:
# 检查所有 DN 节点的共享内存与 ustore 引擎状态 [omm@gauss1 ~]$ gs_guc check -Z datanode -N all -I all -c "shared_buffers" The gs_guc run with the following arguments: [gs_guc -Z datanode -N all -I all -c shared_buffers check ]. Total GUC values: 3. Failed GUC values: 0. The value of parameter shared_buffers is same on all instances. shared_buffers='5GB' [omm@gauss1 ~]$ gs_guc check -Z datanode -N all -I all -c "enable_default_ustore_table" The gs_guc run with the following arguments: [gs_guc -Z datanode -N all -I all -c enable_default_ustore_table check ]. Total GUC values: 3. Failed GUC values: 0. The details for enable_default_ustore_table: [192.168.182.138] enable_default_ustore_table=NULL [/data/cluster/data/dn/dn_6001/gaussdb.conf] [192.168.182.139] enable_default_ustore_table=NULL [/data/cluster/data/dn/dn_6002/gaussdb.conf] [192.168.182.140] enable_default_ustore_table=NULL [/data/cluster/data/dn/dn_6003/gaussdb.conf]
针对最大内存、共享缓冲区等
POSTMASTER 参数,必须执行
set 并物理重启集群:
-- 1. 修改 max_connections 为 200 [omm@gauss1 ~]$ gs_guc set -Z datanode -N all -I all -c "max_connections=200" The gs_guc run with the following arguments: [gs_guc -Z datanode -N all -I all -c max_connections=200 set ]. 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! -- 2. 禁用 UStore [omm@gauss1 ~]$ gs_guc set -Z datanode -N all -I all -c "enable_default_ustore_table=off" The gs_guc run with the following arguments: [gs_guc -Z datanode -N all -I all -c enable_default_ustore_table=off set ]. NOTICE: Enable to create ustore table by default 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! # 3. 重启整个集群使上述配置生效 gs_om -t stop && gs_om -t start -- 4. 发现 max_connections 修改已生效 [omm@gauss1 ~]$ gs_guc check -Z datanode -N all -I all -c "max_connections" The gs_guc run with the following arguments: [gs_guc -Z datanode -N all -I all -c max_connections check ]. Total GUC values: 3. Failed GUC values: 0. The value of parameter max_connections is same on all instances. max_connections=200 -- 5. UStore 已关闭 [omm@gauss1 ~]$ gs_guc check -Z datanode -N all -I all -c "enable_default_ustore_table" The gs_guc run with the following arguments: [gs_guc -Z datanode -N all -I all -c enable_default_ustore_table check ]. Total GUC values: 3. Failed GUC values: 0. The value of parameter enable_default_ustore_table is same on all instances. enable_default_ustore_table=off
针对 SIGHUP 和 HBA 类参数, 使用
reload 即时生效:
# 在线重载 HBA 规则: 所有IP 信任登录 [omm@gauss1 ~]$ gs_guc reload -Z datanode -N all -I all -h "host all all 0.0.0.0/0 trust" The gs_guc run with the following arguments: [gs_guc -Z datanode -N all -I all -h host all all 0.0.0.0/0 trust 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!
gs_guc 修改的整个节点或全局的参数,还可以使用 SQL 脚本修改参数,根据sql脚本的不同,生效的范围也不相同。
使参数在某个数据库生效可以使用
alter database
-- 针对特定数据库变更兼容性行为 ALTER DATABASE postgres SET b_format_behavior_compat_options = 'enable_set_variables'; -- 针对特定运维用户修正时区 ALTER USER Ruby SET timezone TO 'UTC';
-- 临时调整当前窗口的时区 SET timezone TO 'UTC'; -- 临时指定当前事务的分布式计划节点路由数 SET max_datanode_for_plan = 1;
至此,GaussDB 参数配置讲到这里,下一期我们讲一下
GaussDB 的常用 SQL 语句。
这里是《实战派 K8S&DB》,更多干货敬请关注公众号。如果本文对你有所帮助,欢迎点赞、推荐和转发,也欢迎关注后续文章,一起考证、一起学习
GaussDB 分布式数据库。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31444449/viewspace-3182261/ ,如需转载,请注明出处,否则将追究法律责任。