重设参数
背景信息
GaussDB 200提供了多种修改GUC参数的方法,用户可以方便的针对数据库、用户、会话进行设置。
- 参数名称不区分大小写。
- 参数取值有整型、浮点型、字符串、布尔型和枚举型五类。
- 布尔值可以是(on,off)、(true,false)、(yes,no)或者(1,0),且不区分大小写。
- 枚举类型的取值是在系统表pg_settings的enumvals字段取值定义的。
- 对于有单位的参数,在设置时请指定单位,否则将使用默认的单位。
- 参数的默认单位在系统表pg_settings的unit字段定义的。
- 内存单位有:KB(千字节)、MB(兆字节)和GB(吉字节)。
- 时间单位:ms(毫秒)、s(秒)、min(分钟)、h(小时)和d(天)。
- CN和DN参数可以同时进行设置,其他类型的参数不能同时进行设置。
具体参数说明请参见GUC参数说明。
GUC参数设置
GaussDB 200提供了六类GUC参数,具体分类和设置方式请参考表1:
参数类型 |
说明 |
设置方式 |
---|---|---|
INTERNAL |
固定参数,在创建数据库的时候确定,用户无法修改,只能通过show语法或者pg_settings视图进行查看。 |
无 |
POSTMASTER |
数据库服务端参数,在数据库启动时确定,可以通过配置文件指定。 |
支持表2中的方式一。 |
SIGHUP |
数据库全局参数,可在数据库启动时设置或者在数据库启动后,发送指令重新加载。 |
支持表2中的方式一、方式二。 |
BACKEND |
会话连接参数。在创建会话连接时指定,连接建立后无法修改。连接断掉后参数失效。内部使用参数,不推荐用户设置。 |
支持表2中的方式一、方式二。 说明:
设置该参数后,下一次建立会话连接时生效。 |
SUSET |
数据库管理员参数。可在数据库启动时、数据库启动后或者数据库管理员通过SQL进行设置。 |
支持表2中的方式一、方式二或由数据库管理员通过方式三设置。 |
USERSET |
普通用户参数。可被任何用户在任何时刻设置。 |
支持表2中的方式一、方式二或方式三设置。 |
序号 |
设置方法 |
||||||
---|---|---|---|---|---|---|---|
方式一 |
|
||||||
方式二 |
|
||||||
方式三 |
修改指定数据库,用户,会话级别的参数。
|
操作步骤
使用方式一设置数据库参数,以在CN设置archive_mode参数为例。
- 以操作系统用户omm登录CN所在主机,执行source ${BIGDATA_HOME}/mppdb/.mppdbgs_profile命令启动环境变量。
- 查看archive_mode参数。
1
cat ${BIGDATA_DATA_HOME}/mppdb/data1/coordinator/postgresql.conf | grep archive_mode
archive_mode = on
on表示日志要进行归档操作。
- 设置archive_mode参数为off,关闭日志的归档操作。
gs_guc set -Z coordinator -D ${BIGDATA_DATA_HOME}/mppdb/data1/coordinator -c "archive_mode=off"
说明:
可以使用以下命令在所有CN和DN上设置archive_mode参数为off。
gs_guc set -Z coordinator -Z datanode -N all -I all -c "archive_mode=off"
- 重启数据库使参数生效。
gs_om -t stop && gs_om -t start
- 使用如下命令连接数据库。
gsql -d postgres -p 25308
postgres为需要连接的数据库名称,25308为CN的端口号。
连接成功后,系统显示类似如下信息:
gsql ((GaussDB Kernel V300R002C00 build 50dc16a6) compiled at 2019-01-29 05:49:21 commit 1071 last mr 1373) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. postgres=#
- 检查参数设置的正确性。
1 2 3 4 5
SHOW archive_mode; archive_mode -------------- off (1 row)
使用方式二设置参数,以在CN设置authentication_timeout参数为例。
- 以操作系统用户omm登录CN所在主机,执行source ${BIGDATA_HOME}/mppdb/.mppdbgs_profile命令启动环境变量。
- 查看authentication_timeout参数。
1
cat ${BIGDATA_DATA_HOME}/mppdb/data1/coordinator/postgresql.conf | grep authentication_timeout
authentication_timeout = 1min
- 设置authentication_timeout参数为59s。
gs_guc reload -Z coordinator -N all -I all -c "authentication_timeout = 59s" Total instances: 2. Failed instances: 0. Success to perform gs_guc!
说明:
可以使用以下命令在所有CN和DN上设置authentication_timeout参数为59s。
gs_guc reload -Z coordinator -Z datanode -N all -I all -c "authentication_timeout = 59s"
- 使用如下命令连接数据库。
gsql -d postgres -p 25308
postgres为需要连接的数据库名称,25308为CN的端口号。
连接成功后,系统显示类似如下信息:
gsql ((GaussDB Kernel V300R002C00 build 50dc16a6) compiled at 2019-01-29 05:49:21 commit 1071 last mr 1373) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. postgres=#
- 检查参数设置的正确性。
1 2 3 4 5
SHOW authentication_timeout; authentication_timeout ------------------------ 59s (1 row)
使用方式三设置参数,以设置explain_perf_mode参数为例。
- 以操作系统用户omm登录CN所在主机,执行source ${BIGDATA_HOME}/mppdb/.mppdbgs_profile命令启动环境变量。
- 使用如下命令连接数据库。
gsql -d postgres -p 25308
postgres为需要连接的数据库名称,25308为CN的端口号。
连接成功后,系统显示类似如下信息:
gsql ((GaussDB Kernel V300R002C00 build 50dc16a6) compiled at 2019-01-29 05:49:21 commit 1071 last mr 1373) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. postgres=#
- 查看explain_perf_mode参数。
1 2 3 4 5
SHOW explain_perf_mode; explain_perf_mode ------------------- normal (1 row)
- 设置explain_perf_mode参数。
使用以下任意方式进行设置:
- 设置数据库级别的参数
1
ALTER DATABASE postgres SET explain_perf_mode TO pretty;
当结果显示为如下信息,则表示设置成功。
ALTER DATABASE
在下次会话中生效。
- 设置用户级别的参数
1
ALTER USER omm SET explain_perf_mode TO pretty;
当结果显示为如下信息,则表示设置成功。
ALTER ROLE
在下次会话中生效。
- 设置会话级别的参数
1
SET explain_perf_mode TO pretty;
当结果显示为如下信息,则表示设置成功。
SET
- 检查参数设置的正确性。
1 2 3 4 5
SHOW explain_perf_mode; explain_perf_mode -------------- pretty (1 row)
示例
- 示例1:使用方式一修改集群所有CN的最大连接数。
- 以操作系统用户omm登录CN所在主机,执行source ${BIGDATA_HOME}/mppdb/.mppdbgs_profile命令启动环境变量。
- 使用如下命令连接数据库。
gsql -d postgres -p 25308
postgres为需要连接的数据库名称,25308为CN的端口号。
连接成功后,系统显示类似如下信息:
gsql ((GaussDB Kernel V300R002C00 build 50dc16a6) compiled at 2019-01-29 05:49:21 commit 1071 last mr 1373) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. postgres=#
- 查看最大连接数。
1 2 3 4 5
SHOW max_connections; max_connections ----------------- 200 (1 row)
- 使用如下命令退出数据库。
1
\q
- 修改集群所有CN的最大连接数。
gs_guc set -Z coordinator -N all -I all -c "max_connections = 800"
- 重启集群。
gs_om -t stop && gs_om -t start
- 使用如下命令连接数据库。
gsql -d postgres -p 25308
postgres为需要连接的数据库名称,25308为CN的端口号。
连接成功后,系统显示类似如下信息:
gsql ((GaussDB Kernel V300R002C00 build 50dc16a6) compiled at 2019-01-29 05:49:21 commit 1071 last mr 1373) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. postgres=#
- 查看最大连接数。
1 2 3 4 5
SHOW max_connections; max_connections ----------------- 800 (1 row)
- 示例2:使用方式二设置所有CN的客户端认证最长时间参数“authentication_timeout”
- 以操作系统用户omm登录CN所在主机,执行source ${BIGDATA_HOME}/mppdb/.mppdbgs_profile命令启动环境变量。
- 使用如下命令连接数据库。
gsql -d postgres -p 25308
postgres为需要连接的数据库名称,25308为CN的端口号。
连接成功后,系统显示类似如下信息:
gsql ((GaussDB Kernel V300R002C00 build 50dc16a6) compiled at 2019-01-29 05:49:21 commit 1071 last mr 1373) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. postgres=#
- 查看客户端认证的最长时间。
1 2 3 4 5
SHOW authentication_timeout; authentication_timeout ------------------------ 1min (1 row)
- 使用如下命令退出数据库。
1
\q
- 修改集群所有CN的客户端认证最长时间。
gs_guc reload -Z coordinator -N all -I all -c "authentication_timeout = 59s"
- 使用如下命令连接数据库。
gsql -d postgres -p 25308
postgres为需要连接的数据库名称,25308为CN的端口号。
连接成功后,系统显示类似如下信息:
gsql ((GaussDB Kernel V300R002C00 build 50dc16a6) compiled at 2019-01-29 05:49:21 commit 1071 last mr 1373) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. postgres=#
- 查看客户端认证的最长时间。
1 2 3 4 5
SHOW authentication_timeout; authentication_timeout ------------------------ 59s (1 row)
- 示例3:修改集群所有CN和DN的最大连接数。
- 以操作系统用户omm登录CN所在主机,执行source ${BIGDATA_HOME}/mppdb/.mppdbgs_profile命令启动环境变量。
- 使用如下命令连接数据库。
gsql -d postgres -p 25308
postgres为需要连接的数据库名称,25308为CN的端口号。
连接成功后,系统显示类似如下信息:
gsql ((GaussDB Kernel V300R002C00 build 50dc16a6) compiled at 2019-01-29 05:49:21 commit 1071 last mr 1373) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. postgres=#
- 查看最大连接数。
1 2 3 4 5
SHOW max_connections; max_connections ----------------- 200 (1 row)
- 使用如下命令退出数据库。
1
\q
- 修改集群所有CN和DN的最大连接数。
gs_guc set -Z coordinator -Z datanode -N all -I all -c "max_connections = 500"
- 重启集群。
gs_om -t stop gs_om -t start
- 使用如下命令连接数据库。
gsql -d postgres -p 25308
postgres为需要连接的数据库名称,25308为CN的端口号。
连接成功后,系统显示类似如下信息:
gsql ((GaussDB Kernel V300R002C00 build 50dc16a6) compiled at 2019-01-29 05:49:21 commit 1071 last mr 1373) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. postgres=#
- 查看最大连接数。
1 2 3 4 5
SHOW max_connections; max_connections ----------------- 500 (1 row)
- 示例4:设置所有CN和DN的客户端认证最长时间参数“authentication_timeout”
- 以操作系统用户omm登录CN所在主机,执行source ${BIGDATA_HOME}/mppdb/.mppdbgs_profile命令启动环境变量。
- 使用如下命令连接数据库。
gsql -d postgres -p 25308
postgres为需要连接的数据库名称,25308为CN的端口号。
连接成功后,系统显示类似如下信息:
gsql ((GaussDB Kernel V300R002C00 build 50dc16a6) compiled at 2019-01-29 05:49:21 commit 1071 last mr 1373) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. postgres=#
- 查看客户端认证的最长时间。
1 2 3 4 5
SHOW authentication_timeout; authentication_timeout ------------------------ 1min (1 row)
- 使用如下命令退出数据库。
1
\q
- 修改集群所有CN和DN的客户端认证最长时间。
gs_guc reload -Z coordinator -Z datanode -N all -I all -c "authentication_timeout = 30s"
- 使用如下命令连接数据库。
gsql -d postgres -p 25308
postgres为需要连接的数据库名称,25308为CN的端口号。
连接成功后,系统显示类似如下信息:
gsql ((GaussDB Kernel V300R002C00 build 50dc16a6) compiled at 2019-01-29 05:49:21 commit 1071 last mr 1373) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. postgres=#
- 查看客户端认证的最长时间。
1 2 3 4 5
SHOW authentication_timeout; authentication_timeout ------------------------ 30s (1 row)
查看更多:华为GaussDB 200 配置运行参数「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」关注作者【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。评论
- 查看客户端认证的最长时间。
- 查看最大连接数。
- 查看客户端认证的最长时间。
- 查看最大连接数。
- 设置用户级别的参数
- 查看explain_perf_mode参数。
- 设置authentication_timeout参数为59s。
- 设置archive_mode参数为off,关闭日志的归档操作。