暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

华为openGauss 重设参数

华为高斯 2020-06-01
2903

背景信息

openGauss提供了多种修改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参数设置

openGauss提供了六类GUC参数,具体分类和设置方式请参考表1

表 1 GUC参数分类

参数类型

说明

设置方式

INTERNAL

固定参数,在创建数据库的时候确定,用户无法修改,只能通过show语法或者pg_settings视图进行查看。

POSTMASTER

数据库服务端参数,在数据库启动时确定,可以通过配置文件指定。

支持表2中的方式一。

SIGHUP

数据库全局参数,可在数据库启动时设置或者在数据库启动后,发送指令重新加载。

支持表2中的方式一、方式二。

BACKEND

会话连接参数。在创建会话连接时指定,连接建立后无法修改。连接断掉后参数失效。内部使用参数,不推荐用户设置。

支持表2中的方式一、方式二。

说明:

设置该参数后,下一次建立会话连接时生效。

SUSET

数据库管理员参数。可在数据库启动时、数据库启动后或者数据库管理员通过SQL进行设置。

支持表2中的方式一、方式二或由数据库管理员通过方式三设置。

USERSET

普通用户参数。可被任何用户在任何时刻设置。

支持表2中的方式一、方式二或方式三设置。

openGauss提供了三种方式来修改GUC参数,具体操作请参考表2

表 2 GUC参数设置方式

序号

设置方法

方式一

  1. 使用如下命令修改参数。
    gs_guc set -D datadir -c "paraname=value"
    说明:

    如果参数是一个字符串变量,则使用-c parameter="'value'"或者使用-c "parameter = 'value'"。

    使用以下命令在数据库节点上同时设置某个参数。

    gs_guc set -N all -I all -c "paraname=value"
  2. 重启数据库使参数生效。
    说明:

    重启openGauss操作会导致用户执行操作中断,请在操作之前规划好合适的执行窗口。

    gs_om -t stop && gs_om -t start

方式二

gs_guc reload -D datadir -c "paraname=value"
说明:

使用以下命令在数据库节点上同时设置某个参数。

gs_guc reload -N all -I all -c "paraname=value"

方式三

修改指定数据库,用户,会话级别的参数。

  • 设置数据库级别的参数
    postgres=# ALTER DATABASE dbname SET paraname TO value;

    在下次会话中生效。

  • 设置用户级别的参数
    postgres=# ALTER USER username SET paraname TO value;

    在下次会话中生效。

  • 设置会话级别的参数
    postgres=# SET paraname TO value;

    修改本次会话中的取值。退出会话后,设置将失效。

操作步骤

使用方式一设置数据库参数,以在数据库主节点设置archive_mode参数为例。

  1. 以操作系统用户omm登录数据库主节点。
  2. 查看archive_mode参数。

    cat /gaussdb/data/dbnode/postgresql.conf | grep archive_mode

    archive_mode = on

    on表示日志要进行归档操作。

  3. 设置archive_mode参数为off,关闭日志的归档操作。

    gs_guc set -D /gaussdb/data/dbnode -c "archive_mode=off"

    说明:
    可以使用以下命令在数据库节点上设置archive_mode参数为off。
    gs_guc set -N all -I all -c "archive_mode=off"

  4. 重启数据库使参数生效。

    gs_om -t stop && gs_om -t start

  5. 使用如下命令连接数据库。

    gsql -d postgres -p 8000

    postgres为需要连接的数据库名称,8000为数据库主节点的端口号。

    连接成功后,系统显示类似如下信息:

    ``` gsql ((openGauss 1.0.0 build 290d125f) compiled at 2020-05-08 02:59:43 commit 2143 last mr 131 Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help.

    postgres=# ```

  6. 检查参数设置的正确性。

    ``` postgres=# SHOW archive_mode; archive_mode


    off (1 row) ```

使用方式二设置参数,以在数据库主节点设置authentication_timeout参数为例。

  1. 以操作系统用户omm登录数据库主节点。
  2. 查看authentication_timeout参数。

    cat /gaussdb/data/dbnode/postgresql.conf | grep authentication_timeout

    authentication_timeout = 1min

  3. 设置authentication_timeout参数为59s。

    ``` gs_guc reload -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 -N all -I all -c "authentication_timeout = 59s"

  4. 使用如下命令连接数据库。

    gsql -d postgres -p 8000

    postgres为需要连接的数据库名称,8000为数据库主节点的端口号。

    连接成功后,系统显示类似如下信息:

    ``` gsql ((openGauss 1.0.0 build 290d125f) compiled at 2020-05-08 02:59:43 commit 2143 last mr 131 Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help.

    postgres=# ```

  5. 检查参数设置的正确性。

    ``` postgres=# SHOW authentication_timeout; authentication_timeout


    59s (1 row) ```

使用方式三设置参数,以设置explain_perf_mode参数为例。

  1. 以操作系统用户omm登录数据库主节点。
  2. 使用如下命令连接数据库。

    gsql -d postgres -p 8000

    postgres为需要连接的数据库名称,8000为数据库主节点的端口号。

    连接成功后,系统显示类似如下信息:

    ``` gsql ((openGauss 1.0.0 build 290d125f) compiled at 2020-05-08 02:59:43 commit 2143 last mr 131 Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help.

    postgres=# ```

  3. 查看explain_perf_mode参数。

    ``` postgres=# SHOW explain_perf_mode; explain_perf_mode


    normal (1 row) ```

  4. 设置explain_perf_mode参数。

    使用以下任意方式进行设置:

    • 设置数据库级别的参数

      postgres=# ALTER DATABASE postgres SET explain_perf_mode TO pretty;

      当结果显示为如下信息,则表示设置成功。

      ALTER DATABASE

      在下次会话中生效。

    • 设置用户级别的参数

      postgres=# ALTER USER omm SET explain_perf_mode TO pretty;

      当结果显示为如下信息,则表示设置成功。

      ALTER ROLE

      在下次会话中生效。

    • 设置会话级别的参数

      postgres=# SET explain_perf_mode TO pretty;

      当结果显示为如下信息,则表示设置成功。

      SET

  5. 检查参数设置的正确性。

    ``` postgres=# SHOW explain_perf_mode; explain_perf_mode


    pretty (1 row) ```

示例

  • 示例1:使用方式一修改openGauss数据库主节点的最大连接数。

    1. 以操作系统用户omm登录数据库主节点。
    2. 使用如下命令连接数据库。

      gsql -d postgres -p 8000

      postgres为需要连接的数据库名称,8000为数据库主节点的端口号。

      连接成功后,系统显示类似如下信息:

      ``` gsql ((openGauss 1.0.0 build 290d125f) compiled at 2020-05-08 02:59:43 commit 2143 last mr 131 Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help.

      postgres=# ```

    3. 查看最大连接数。

      ``` postgres=# SHOW max_connections; max_connections


      200 (1 row) ```

    4. 使用如下命令退出数据库。

      postgres=# \q

    5. 修改openGauss数据库主节点的最大连接数。

      gs_guc set -N all -I all -c "max_connections = 800"

    6. 重启openGauss。

      gs_om -t stop && gs_om -t start

    7. 使用如下命令连接数据库。

      gsql -d postgres -p 8000

      postgres为需要连接的数据库名称,8000为数据库主节点的端口号。

      连接成功后,系统显示类似如下信息:

      ``` gsql ((openGauss 1.0.0 build 290d125f) compiled at 2020-05-08 02:59:43 commit 2143 last mr 131 Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help.

      postgres=# ```

    8. 查看最大连接数。

      ``` postgres=# SHOW max_connections; max_connections


      800 (1 row) ```

  • 示例2:使用方式二设置数据库主节点的客户端认证最长时间参数“authentication_timeout”

    1. 以操作系统用户omm登录数据库主节点。
    2. 使用如下命令连接数据库。

      gsql -d postgres -p 8000

      postgres为需要连接的数据库名称,8000为数据库主节点的端口号。

      连接成功后,系统显示类似如下信息:

      ``` gsql ((openGauss 1.0.0 build 290d125f) compiled at 2020-05-08 02:59:43 commit 2143 last mr 131 Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help.

      postgres=# ```

    3. 查看客户端认证的最长时间。

      ``` postgres=# SHOW authentication_timeout; authentication_timeout


      1min (1 row) ```

    4. 使用如下命令退出数据库。

      postgres=# \q

    5. 修改openGauss数据库主节点的客户端认证最长时间。

      gs_guc reload -N all -I all -c "authentication_timeout = 59s"

    6. 使用如下命令连接数据库。

      gsql -d postgres -p 8000

      postgres为需要连接的数据库名称,8000为数据库主节点的端口号。

      连接成功后,系统显示类似如下信息:

      ``` gsql ((openGauss 1.0.0 build 290d125f) compiled at 2020-05-08 02:59:43 commit 2143 last mr 131 Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help.

      postgres=# ```

    7. 查看客户端认证的最长时间。

      ``` postgres=# SHOW authentication_timeout; authentication_timeout


      59s (1 row) ```

  • 示例3:修改openGauss数据库节点的最大连接数。

    1. 以操作系统用户omm登录数据库主节点。
    2. 使用如下命令连接数据库。

      gsql -d postgres -p 8000

      postgres为需要连接的数据库名称,8000为数据库主节点的端口号。

      连接成功后,系统显示类似如下信息:

      ``` gsql ((openGauss 1.0.0 build 290d125f) compiled at 2020-05-08 02:59:43 commit 2143 last mr 131 Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help.

      postgres=# ```

    3. 查看最大连接数。

      ``` postgres=# SHOW max_connections; max_connections


      200 (1 row) ```

    4. 使用如下命令退出数据库。

      postgres=# \q

    5. 修改openGauss数据库节点的最大连接数。

      gs_guc set -N all -I all -c "max_connections = 500"

    6. 重启openGauss。

      gs_om -t stop gs_om -t start

    7. 使用如下命令连接数据库。

      gsql -d postgres -p 8000

      postgres为需要连接的数据库名称,8000为数据库主节点的端口号。

      连接成功后,系统显示类似如下信息:

      ``` gsql ((openGauss 1.0.0 build 290d125f) compiled at 2020-05-08 02:59:43 commit 2143 last mr 131 Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help.

      postgres=# ```

    8. 查看最大连接数。

      ``` postgres=# SHOW max_connections; max_connections


      500 (1 row) ```

  • 示例4:设置数据库节点的客户端认证最长时间参数“authentication_timeout”

    1. 以操作系统用户omm登录数据库主节点。
    2. 使用如下命令连接数据库。

      gsql -d postgres -p 8000

      postgres为需要连接的数据库名称,8000为数据库主节点的端口号。

      连接成功后,系统显示类似如下信息:

      ``` gsql ((openGauss 1.0.0 build 290d125f) compiled at 2020-05-08 02:59:43 commit 2143 last mr 131 Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help.

      postgres=# ```

    3. 查看客户端认证的最长时间。

      ``` postgres=# SHOW authentication_timeout; authentication_timeout


      1min (1 row) ```

    4. 使用如下命令退出数据库。

      postgres=# \q

    5. 修改openGauss数据库节点的客户端认证最长时间。

      gs_guc reload -N all -I all -c "authentication_timeout = 30s"

    6. 使用如下命令连接数据库。

      gsql -d postgres -p 8000

      postgres为需要连接的数据库名称,8000为数据库主节点的端口号。

      连接成功后,系统显示类似如下信息:

      ``` gsql ((openGauss 1.0.0 build 290d125f) compiled at 2020-05-08 02:59:43 commit 2143 last mr 131 Non-SSL connection (SSL connection is recommended when requiring high-security) Type "help" for help.

      postgres=# ```

    7. 查看客户端认证的最长时间。

      ``` postgres=# SHOW authentication_timeout; authentication_timeout


      30s (1 row) ```

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

文集目录
暂无数据