重设参数
GaussDB支持在管理控制台修改部分参数,建议在管理控制台上修改指定参数,如果需要修改的参数在管理控制台无法修改,请提前评估风险后再联系客服进行修改。
背景信息
GaussDB提供了多种修改GUC参数的方法,用户可以方便地针对数据库、用户、会话进行设置。
- 参数名称不区分大小写。
- 参数取值有整型、浮点型、字符串、布尔型和枚举型五类。
    - 布尔值可以是(on,off)、(true,false)、(yes,no)或者(1,0),且不区分大小写。
- 枚举类型的取值是在系统表pg_settings的enumvals字段取值定义的。
 
- 对于有单位的参数,在设置时请指定单位,否则将使用默认的单位。
    - 参数的默认单位在系统表pg_settings的unit字段定义的。
- 内存单位有:KB(千字节)、MB(兆字节)和GB(吉字节)。
- 时间单位:ms(毫秒)、s(秒)、min(分钟)、h(小时)和d(天)。
 
具体参数说明请参见GUC参数说明。
GUC参数设置
GaussDB提供了六类GUC参数,具体分类和设置方式请参考表1:
| 参数类型 | 说明 | 设置方式 | 
|---|---|---|
| INTERNAL | 固定参数,在创建数据库的时候确定,用户无法修改,只能通过show语法或者pg_settings视图进行查看。 | 无 | 
| POSTMASTER | 数据库服务端参数,在数据库启动时确定,可以通过配置文件指定。 | 支持表2中的方式一。 | 
| SIGHUP | 数据库全局参数,可在数据库启动时设置或者在数据库启动后,发送指令重新加载。 | 支持表2中的方式一、方式二。 | 
| BACKEND | 会话连接参数。在创建会话连接时指定,连接建立后无法修改。连接断掉后参数失效。内部使用参数,不推荐用户设置。 | 支持表2中的方式一、方式二。 
         说明: 
         设置该参数后,下一次建立会话连接时生效。 | 
| SUSET | 数据库管理员参数。可在数据库启动时、数据库启动后或者数据库管理员通过SQL进行设置。 | 支持表2中的方式一、方式二或由数据库管理员通过方式三设置。 | 
| USERSET | 普通用户参数。可被任何用户在任何时刻设置。 | 支持表2中的方式一、方式二或方式三设置。 | 
| 序号 | 设置方法 | 
|---|---|
| 方式一 | 
 | 
| 方式二 | 
 | 
| 方式三 | 
 | 
 
 
    - 使用方式一和方式二设置参数时,若所设参数不属于当前环境,数据库会提示参数不在支持范围内的相关信息。
- 使用方式三设置参数时,若参数值为int整型,则会将整数前导零过滤掉,例如SET paraname TO 008192与SET paraname TO 8192效果相同。
操作步骤
使用方式一设置数据库参数,以在数据库主节点设置hot_standby参数为例。
- 以操作系统用户omm登录数据库主节点。
- 查看hot_standby参数。
    
    1cat /gaussdb/data/dbnode/postgresql.conf | grep "hot_standby" hot_standby = on on表示日志要进行归档操作。 
- 设置hot_standby参数为off,关闭日志的归档操作。
    
    gs_guc set -Z datanode -D /gaussdb/data/dbnode -c "hot_standby=off"   可以使用以下命令在数据库节点上设置hot_standby参数为off。 gs_guc set -Z datanode -N all -I all -c "hot_standby=off"
- 重启数据库使参数生效。
    
    gs_om -t stop && gs_om -t start 
- 使用如下命令连接数据库。
    
    gsql -d postgres -p 8000postgres为需要连接的数据库名称,8000为数据库主节点的端口号。 连接成功后,系统显示类似如下信息: gsql((GaussDB Kernel VxxxRxxxCxx build f521c606) compiled at 2021-09-16 14:55:22 commit 2935 last mr 6385 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. openGauss=# 
- 检查参数设置的正确性。
    
    1 2 3 4 5 openGauss=# SHOW hot_standby; hot_standby -------------- off (1 row) 
使用方式二设置参数,以在数据库主节点设置authentication_timeout参数为例。
- 以操作系统用户omm登录数据库主节点。
- 查看authentication_timeout参数。
    
    1cat /gaussdb/data/dbnode/postgresql.conf | grep authentication_timeout authentication_timeout = 1min 
- 设置authentication_timeout参数为59s。
    
    gs_guc reload -Z datanode -N all -I all -c "authentication_timeout = 59s" Total instances: 2. Failed instances: 0. Success to perform gs_guc!  可以使用以下命令在数据库节点上设置authentication_timeout参数为59s。 gs_guc reload -Z datanode -N all -I all -c "authentication_timeout = 59s"
- 使用如下命令连接数据库。
    
    gsql -d postgres -p 8000postgres为需要连接的数据库名称,8000为数据库主节点的端口号。 连接成功后,系统显示类似如下信息: gsql((GaussDB Kernel VxxxRxxxCxx build f521c606) compiled at 2021-09-16 14:55:22 commit 2935 last mr 6385 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. openGauss=# 
- 检查参数设置的正确性。
    
    1 2 3 4 5 openGauss=# SHOW authentication_timeout; authentication_timeout ------------------------ 59s (1 row) 
使用方式三设置参数,以设置explain_perf_mode参数为例。
- 以操作系统用户omm登录数据库主节点。
- 使用如下命令连接数据库。
    
    gsql -d postgres -p 8000postgres为需要连接的数据库名称,8000为数据库主节点的端口号。 连接成功后,系统显示类似如下信息: gsql((GaussDB Kernel VxxxRxxxCxx build f521c606) compiled at 2021-09-16 14:55:22 commit 2935 last mr 6385 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. openGauss=# 
- 查看explain_perf_mode参数。
    
    1 2 3 4 5 openGauss=# SHOW explain_perf_mode; explain_perf_mode ------------------- normal (1 row) 
- 设置explain_perf_mode参数。
    
    使用以下任意方式进行设置: - 设置数据库级别的参数
      1openGauss=# ALTER DATABASE postgres SET explain_perf_mode TO pretty; 当结果显示为如下信息,则表示设置成功。 ALTER DATABASE 在下次会话中生效。 
- 设置用户级别的参数
      1openGauss=# ALTER USER omm SET explain_perf_mode TO pretty; 当结果显示为如下信息,则表示设置成功。 ALTER ROLE 在下次会话中生效。 
- 设置会话级别的参数
      1openGauss=# SET explain_perf_mode TO pretty; 当结果显示为如下信息,则表示设置成功。 SET 
 
- 设置数据库级别的参数
      
- 检查参数设置的正确性。
    
    1 2 3 4 5 openGauss=# SHOW explain_perf_mode; explain_perf_mode -------------- pretty (1 row) 
示例
- 示例1:使用方式一修改GaussDB数据库主节点的最大连接数。
    - 以操作系统用户omm登录数据库主节点。
- 使用如下命令连接数据库。
      gsql -d postgres -p 8000postgres为需要连接的数据库名称,8000为数据库主节点的端口号。 连接成功后,系统显示类似如下信息: gsql((GaussDB Kernel VxxxRxxxCxx build f521c606) compiled at 2021-09-16 14:55:22 commit 2935 last mr 6385 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. openGauss=#
- 查看最大连接数。
      1 2 3 4 5 openGauss=# SHOW max_connections; max_connections ----------------- 200 (1 row) 
- 使用如下命令退出数据库。
      1openGauss=# \q 
- 修改GaussDB数据库主节点的最大连接数。
      gs_guc set -Z datanode -N all -I all -c "max_connections = 800"
- 重启数据库。
      gs_om -t stop && gs_om -t start 
- 使用如下命令连接数据库。
      gsql -d postgres -p 8000postgres为需要连接的数据库名称,8000为数据库主节点的端口号。 连接成功后,系统显示类似如下信息: gsql((GaussDB Kernel VxxxRxxxCxx build f521c606) compiled at 2021-09-16 14:55:22 commit 2935 last mr 6385 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. openGauss=# 
- 查看最大连接数。
      1 2 3 4 5 openGauss=# SHOW max_connections; max_connections ----------------- 800 (1 row) 
 
- 示例2:使用方式二设置数据库主节点的客户端认证最长时间参数“authentication_timeout”
    - 以操作系统用户omm登录数据库主节点。
- 使用如下命令连接数据库。
      gsql -d postgres -p 8000postgres为需要连接的数据库名称,8000为数据库主节点的端口号。 连接成功后,系统显示类似如下信息: gsql((GaussDB Kernel VxxxRxxxCxx build f521c606) compiled at 2021-09-16 14:55:22 commit 2935 last mr 6385 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. openGauss=# 
- 查看客户端认证的最长时间。
      1 2 3 4 5 openGauss=# SHOW authentication_timeout; authentication_timeout ------------------------ 1min (1 row) 
- 使用如下命令退出数据库。
      1openGauss=# \q 
- 修改数据库主节点的客户端认证最长时间。
      gs_guc reload -Z datanode -N all -I all -c "authentication_timeout = 59s"
- 使用如下命令连接数据库。
      gsql -d postgres -p 8000postgres为需要连接的数据库名称,8000为数据库主节点的端口号。 连接成功后,系统显示类似如下信息: gsql((GaussDB Kernel VxxxRxxxCxx build f521c606) compiled at 2021-09-16 14:55:22 commit 2935 last mr 6385 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. openGauss=# 
- 查看客户端认证的最长时间。
      1 2 3 4 5 openGauss=# SHOW authentication_timeout; authentication_timeout ------------------------ 59s (1 row) 
 
- 示例3:修改GaussDB数据库节点的最大连接数。
    - 以操作系统用户omm登录数据库主节点。
- 使用如下命令连接数据库。
      gsql -d postgres -p 8000postgres为需要连接的数据库名称,8000为数据库主节点的端口号。 连接成功后,系统显示类似如下信息: gsql((GaussDB Kernel VxxxRxxxCxx build f521c606) compiled at 2021-09-16 14:55:22 commit 2935 last mr 6385 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. openGauss=# 
- 查看最大连接数。
      1 2 3 4 5 openGauss=# SHOW max_connections; max_connections ----------------- 200 (1 row) 
- 使用如下命令退出数据库。
      1openGauss=# \q 
- 修改GaussDB数据库节点的最大连接数。
      gs_guc set -Z datanode -N all -I all -c "max_connections = 500"
- 重启数据库。
      gs_om -t stop gs_om -t start 
- 使用如下命令连接数据库。
      gsql -d postgres -p 8000postgres为需要连接的数据库名称,8000为数据库主节点的端口号。 连接成功后,系统显示类似如下信息: gsql((GaussDB Kernel VxxxRxxxCxx build f521c606) compiled at 2021-09-16 14:55:22 commit 2935 last mr 6385 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. openGauss=#
- 查看最大连接数。
      1 2 3 4 5 openGauss=# SHOW max_connections; max_connections ----------------- 500 (1 row) 
 
- 示例4:设置数据库节点的客户端认证最长时间参数“authentication_timeout”
    - 以操作系统用户omm登录数据库主节点。
- 使用如下命令连接数据库。
      gsql -d postgres -p 8000postgres为需要连接的数据库名称,8000为数据库主节点的端口号。 连接成功后,系统显示类似如下信息: gsql((GaussDB Kernel VxxxRxxxCxx build f521c606) compiled at 2021-09-16 14:55:22 commit 2935 last mr 6385 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. openGauss=#
- 查看客户端认证的最长时间。
      1 2 3 4 5 openGauss=# SHOW authentication_timeout; authentication_timeout ------------------------ 1min (1 row) 
- 使用如下命令退出数据库。
      1openGauss=# \q 
- 修改GaussDB数据库节点的客户端认证最长时间。
      gs_guc reload -Z datanode -N all -I all -c "authentication_timeout = 30s"
- 使用如下命令连接数据库。
      gsql -d postgres -p 8000postgres为需要连接的数据库名称,8000为数据库主节点的端口号。 连接成功后,系统显示类似如下信息: gsql((GaussDB Kernel VxxxRxxxCxx build f521c606) compiled at 2021-09-16 14:55:22 commit 2935 last mr 6385 release) Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help. openGauss=#
- 查看客户端认证的最长时间。
      1 2 3 4 5 openGauss=# SHOW authentication_timeout; authentication_timeout ------------------------ 30s (1 row) 
 
 
  