实验二十四 GaussDB运维与故障处理-SQL慢问题

进行本实验前需要具备如下能力:

  1. 具备linux操作系统运维能力,熟练使用Linux运维命令,包括但不限top、iostat等;

  2. 熟练使用GaussDB数据库,具有理解和分析GaussDB数据库执行计划的能力;

  3. 熟悉GaussDB数据库的SQL优化方法。

实验环境准备

1.确定sysbench等压测工具安装成功。

sql 复制代码
[root@gs01 lib64]# sysbench --version
sysbench 1.0.17-71abd99
[root@gs01 lib64]# 

2.GaussDB中创建用户,之后sysbench压测使用。

sql 复制代码
gsql -d postgres -p 8000 -r

create user sysbench with sysadmin password 'Huawei@1234';

3.验证sysbench用户是否可以登录。

sql 复制代码
[Ruby@gs01 cm_agent]$ gsql -d postgres -p 8000 -U sysbench -W Huawei@1234 -h 192.168.3.60 -r
gsql ((GaussDB Kernel 505.2.1.SPC0800 build 85996fbb) compiled at 2025-07-03 01:15:58 commit 10558 last mr 24271 release)
SSL connection (cipher: ECDHE-RSA-AES128-GCM-SHA256, bits: 128)
Type "help" for help.

gaussdb=> 
gaussdb=> \l
                          List of databases
   Name    | Owner | Encoding  | Collate | Ctype | Access privileges 
-----------+-------+-----------+---------+-------+-------------------
 postgres  | Ruby  | SQL_ASCII | C       | C     | 
 template0 | Ruby  | SQL_ASCII | C       | C     | =c/Ruby          +
           |       |           |         |       | Ruby=CTc/Ruby
 template1 | Ruby  | SQL_ASCII | C       | C     | =c/Ruby          +
           |       |           |         |       | Ruby=CTc/Ruby
 templatea | Ruby  | SQL_ASCII | C       | C     | =c/Ruby          +
           |       |           |         |       | Ruby=CTc/Ruby
 templatem | Ruby  | SQL_ASCII | C       | C     | =c/Ruby          +
           |       |           |         |       | Ruby=CTc/Ruby
(5 rows)

4.创建测试库。

sql 复制代码
[Ruby@gs01 cm_agent]$ gsql -d postgres -p 8000 -U sysbench -W Huawei@1234  -c "create database db_test;"
CREATE DATABASE
[Ruby@gs01 cm_agent]$ 

5.初始化数据。

sql 复制代码
[root@gs01 share]# sysbench oltp_read_write --tables=1 --table-size=5000000 --threads=8 --time=600 --db-driver=pgsql --pgsql-db=db_test --pgsql-user=sysbench --pgsql-password=Huawei@1234 --pgsql-host=192.168.3.60 --pgsql-port=8000 --report-interval=5 prepare
sysbench 1.0.17-71abd99 (using bundled LuaJIT 2.1.0-beta2)

Initializing worker threads...

FATAL: Connection to database failed: none of the server's SASL authentication mechanisms are supported

FATAL: `sysbench.cmdline.call_command' function failed: ./oltp_common.lua:88: connection creation failed
FATAL: Connection to database failed: none of the server's SASL authentication mechanisms are supported

FATAL: `sysbench.cmdline.call_command' function failed: ./oltp_common.lua:88: connection creation failed
FATAL: Connection to database failed: none of the server's SASL authentication mechanisms are supported

FATAL: `sysbench.cmdline.call_command' function failed: ./oltp_common.lua:88: connection creation failed
FATAL: Connection to database failed: none of the server's SASL authentication mechanisms are supported

FATAL: `sysbench.cmdline.call_command' function failed: ./oltp_common.lua:88: connection creation failed
FATAL: Connection to database failed: none of the server's SASL authentication mechanisms are supported

FATAL: `sysbench.cmdline.call_command' function failed: ./oltp_common.lua:88: connection creation failed
FATAL: Connection to database failed: none of the server's SASL authentication mechanisms are supported

FATAL: `sysbench.cmdline.call_command' function failed: ./oltp_common.lua:88: connection creation failed
FATAL: Connection to database failed: none of the server's SASL authentication mechanisms are supported

FATAL: `sysbench.cmdline.call_command' function failed: ./oltp_common.lua:88: connection creation failed
FATAL: Connection to database failed: none of the server's SASL authentication mechanisms are supported

FATAL: `sysbench.cmdline.call_command' function failed: ./oltp_common.lua:88: connection creation failed

解决办法:

sql 复制代码
[Ruby@gs01 cm_agent]$ gs_guc reload -Z datanode -N all -I all -c "password_encryption_type=0"
The gs_guc run with the following arguments: [gs_guc -Z datanode -N all -I all -c password_encryption_type=0 reload ].
Begin to perform the total nodes: 1.
Popen count is 1, Popen success count is 1, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 1, Command success count is 1, Command failure count is 0.

Total instances: 1. Failed instances: 0.
ALL: Success to perform gs_guc!

[Ruby@gs01 cm_agent]$ gs_guc reload -Z datanode -N all -I all -h "host all all 0.0.0.0/0 md5"
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 md5 reload ].
Begin to perform the total nodes: 1.
Popen count is 1, Popen success count is 1, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 1, Command success count is 1, Command failure count is 0.

Total instances: 1. Failed instances: 0.
ALL: Success to perform gs_guc!

删除sysbench用户重新创建:

sql 复制代码
gsql -d postgres -p 8000 -r

drop database db_test;
drop user sysbench;

create database db_test;
create user sysbench with sysadmin password 'Huawei@1234';

6.重新执行数据初始化。

sql 复制代码
[root@gs01 share]# sysbench oltp_read_write --tables=1 --table-size=5000000 --threads=8 --time=600 --db-driver=pgsql --pgsql-db=db_test --pgsql-user=sysbench --pgsql-password=Huawei@1234 --pgsql-host=192.168.3.60 --pgsql-port=8000 --report-interval=5 prepare
sysbench 1.0.17-71abd99 (using bundled LuaJIT 2.1.0-beta2)

Initializing worker threads...

Creating table 'sbtest1'...
Inserting 5000000 records into 'sbtest1'
Creating a secondary index on 'sbtest1'...
[root@gs01 share]# 

7.登录GaussDB数据库,查询数据库参数synchronous_commit

sql 复制代码
gaussdb=# show synchronous_commit;
 synchronous_commit 
--------------------
 off
(1 row)

8.重新设置 synchronous_commit 参数。

sql 复制代码
[Ruby@gs01 cm_agent]$ gs_guc reload -Z datanode -N all -I all -c "synchronous_commit=local"
The gs_guc run with the following arguments: [gs_guc -Z datanode -N all -I all -c synchronous_commit=local reload ].
Begin to perform the total nodes: 1.
Popen count is 1, Popen success count is 1, Popen failure count is 0.
Begin to perform gs_guc for datanodes.
Command count is 1, Command success count is 1, Command failure count is 0.

Total instances: 1. Failed instances: 0.
ALL: Success to perform gs_guc!

9.手动进行环境检测。

sql 复制代码
sysbench oltp_read_write --tables=1 --table-size=500000000 --threads=8 --time=600 --db-driver=pgsql --pgsql-db=db_test --pgsql-user=sysbench --pgsql-password=Huawei@1234 --pgsql-host=192.168.3.60 --pgsql-port=8000 --report-interval=5 run

磁盘IO压力大造成的性能劣化实验模拟

1.使用如下脚本模拟常规IO压力下业务的性能情况。

sql 复制代码
sysbench oltp_read_write --tables=1 --table-size=5000000 --threads=8 --time=600 --db-driver=pgsql --pgsql-db=db_test --pgsql-user=sysbench --pgsql-password=Huawei@1234 --pgsql-host=192.168.3.60 --pgsql-port=8000 --report-interval=5 --percentile=99 run

2.执行如下脚本,构建数据盘IO压力高场景。

sql 复制代码
touch /data/cluster/master/datanode1/test_in
touch /data/cluster/master/datanode1/test_out
dd if=/dev/zero of="/data/cluster/master/datanode1/test_in" bs=3G count=10 iflag=fullblock
while true;
do
dd if="/data/cluster/master/datanode1/test_in" of="/data/cluster/master/datanode1/test_out" bs=3G count=10 iflag=fullblock
done;

3.再次执行sysbench压测。

sql 复制代码
sysbench oltp_read_write --tables=1 --table-size=5000000 --threads=8 --time=600 --db-driver=pgsql --pgsql-db=db_test --pgsql-user=sysbench --pgsql-password=Huawei@1234 --pgsql-host=192.168.3.60 --pgsql-port=8000 --report-interval=5 --percentile=99 run

通过实验得知,没有IO读写压力的情况下TPS为357,QPS为7154;有IO读写压力的情况下,TPS为140,QPS为 2806。

相关推荐
人工智能知识库15 小时前
华为HCCDP-GaussDB工作级开发者题库(带详细解析)
华为·gaussdb·hccdp-gaussdb·工作级开发者认证
robinson198817 小时前
测试崖山-DM8-GaussDB-OpenTeleDB数据库在长事务下表和索引是否膨胀
达梦·表膨胀·gaussdb·openteledb·崖山
Gauss松鼠会2 天前
【GaussDB】从 sqlplus 到 gsql:Shell 中执行 SQL 文件方案的迁移与改造
数据库·sql·database·gaussdb
Gauss松鼠会2 天前
【GaussDB】跨用户调用已授权的存储过程,可能会在存储过程内SQL的自定义函数表达式里报错没有权限
数据库·sql·database·gaussdb
云和数据.ChenGuang3 天前
openGauss赋能新能源汽车智能制造——比亚迪MES系统数据库国产化升级案例
数据库·汽车·opengauss·gaussdb·数据库权限管理
云和数据.ChenGuang3 天前
GaussDB 期末考试题与面试题
数据库·opengauss·gaussdb·数据库期末试题
Neolnfra5 天前
openGauss部署配置指南
数据库·opengauss·gaussdb
DarkAthena6 天前
【GaussDB】跨用户调用已授权的存储过程,可能会在存储过程内SQL的自定义函数表达式里报错没有权限
数据库·sql·gaussdb
DarkAthena8 天前
【GaussDB】从 sqlplus 到 gsql:Shell 中执行 SQL 文件方案的迁移与改造
数据库·sql·oracle·gaussdb
NineData14 天前
如何通过 NineData 将 Oracle 不停机迁移到 GaussDB
数据库·oracle·gaussdb·数据库管理工具·ninedata·数据库迁移·迁移工具