GaussDB有类似Oracle AWR报告的WSR(Workload Statistics Report)报告。以帮助DBA进行DB性能分析定位。
集群环境当前仅支持在DN主节点上生成分析报告,不支持CN节点。
[omm@Gauss1 ~]$ zsql sys/'Changeme_123'@127.0.0.1:40000 -q
connected.
SQL> wsr
The syntax of generating a WSR report is as follows:
Format: WSR snap_id1 snap_id2 "FILENAME"
snap_id1 and snap_id2 indicate the IDs of the start and end snapshots, respectively. FILENAME is optional.
You can create a snapshot using the SYS.WSR$CREATE_SNAPSHOT stored procedure and obtain snapshot IDs from the adm_hist_snapshot system view.
You can drop snapshots using the WSR$DROP_SNAPSHOT_RANGE stored procedure and obtain the latest 20 snapshot IDs by running the WSR list command.
Example1: WSR 10 20
Use snapshot 10 and snapshot 20 to generate a report, with a default report name.
Example2: WSR 10 20 "e:\wsr.html"
Use snapshot 10 and snapshot 20 to generate a report, with a specified report name.
Example3: WSR list
Obtain information about the latest 20 snapshots.
Example4: CALL WSR$CREATE_SNAPSHOT;
Create a snapshot.
Example5: CALL WSR$DROP_SNAPSHOT_RANGE(10, 20);
Drop snapshots from snapshot 10 to snapshot 20.
Note: For WSR, the values of the SQL_STAT and TIMED_STATS system parameters are true.
SQL>
查看可用快照点:
SQL> wsr list;
Listing the lastest Completed Snapshots
Snap Id Snap Started DB_startup_time
--------------- ------------------- ------------------
26 2019-12-17 04:30:21 2019-12-17 03:30:19
25 2019-12-17 04:00:21 2019-12-17 03:30:19
24 2019-12-17 03:30:21 2019-12-17 03:30:19
23 2019-12-17 01:57:30 2019-12-17 00:27:29
22 2019-12-17 01:27:30 2019-12-17 00:27:29
21 2019-12-17 00:57:30 2019-12-17 00:27:29
20 2019-12-17 00:27:30 2019-12-17 00:27:29
19 2019-12-16 23:51:43 2019-12-16 22:04:44
18 2019-12-16 23:21:43 2019-12-16 22:04:44
17 2019-12-16 22:51:43 2019-12-16 21:49:30
16 2019-12-16 22:21:43 2019-12-16 21:49:30
15 2019-12-16 21:51:43 2019-12-16 21:49:30
14 2019-12-16 03:47:00 2019-12-15 22:46:59
13 2019-12-16 03:17:00 2019-12-15 22:46:59
12 2019-12-16 02:47:00 2019-12-15 22:46:59
11 2019-12-16 02:17:00 2019-12-15 22:46:59
10 2019-12-16 01:47:00 2019-12-15 22:46:59
9 2019-12-16 01:17:00 2019-12-15 22:46:59
8 2019-12-16 00:47:00 2019-12-15 22:46:59
7 2019-12-16 00:17:00 2019-12-15 22:46:59
SQL>
手动收集快照点
SQL> CALL WSR$CREATE_SNAPSHOT;
PL/SQL procedure successfully completed.
SQL>
查看WSR配置信息
SQL> select snap_interval,retention,topnsql,session_status,session_interval,log_days from adm_hist_wr_control;
SNAP_INTERVAL RETENTION TOPNSQL SESSION_STATUS SESSION_INTERVAL LOG_DAYS
------------------------ ------------------------ ------------ -------------- ---------------- ------------
+00000 00:30:00.0 +00002 00:00:00.0 200 Y 30 30
1 rows fetched.
SQL>
SNAP_INTERVAL : 自动生成快照的间隔。取值范围【5,1440】 单位:分钟 默认值:30分 钟 参数为整数 call WSR $MODIFY_SETTING(I_ IN_INTERVAL_MINUT ES => 30);
RETENTION : 快照保留的天数。 取值范围【1,3000】 单位:天 默认值:2天 参数为整数 call WSR $MODIFY_SETTING(I_ IN_RETENTION_DAYS => 30);
TOPNSQL : 报告中Top SQL个 数。 取值范围【1,1000】 单位:个 默认值:200个 参数为整数 call WSR $MODIFY_SETTING(I_ IN_TOPSQL=> 100);
SESSION_STATUS : 是否开启准实时收 集任务。取值范围 Y:开启。N:不开启。默认值:Y call WSR $MODIFY_SETTING(S TR_IN_SESSION_STAT US=> 'Y');
SESSION_INTERVA : 准实时收集任务的间隔。 取值范围【1,1000】 单位:秒 默认值:30秒 参数为整数 call WSR $MODIFY_SETTING(I_ IN_SESSION_INTERVA L => 30);
LOG_DAYS : 日志的保留天数。 取值范围【1,1000】 单位:天 默认值:30天 参数为整数 call WSR $MODIFY_SETTING(I_ IN_LOG_DAYS => 30);
常用操作:
SQL> wsr list;
Listing the lastest Completed Snapshots
Snap Id Snap Started DB_startup_time
--------------- ------------------- ------------------
27 2019-12-17 04:37:31 2019-12-17 03:30:19
26 2019-12-17 04:30:21 2019-12-17 03:30:19
25 2019-12-17 04:00:21 2019-12-17 03:30:19
24 2019-12-17 03:30:21 2019-12-17 03:30:19
23 2019-12-17 01:57:30 2019-12-17 00:27:29
22 2019-12-17 01:27:30 2019-12-17 00:27:29
21 2019-12-17 00:57:30 2019-12-17 00:27:29
20 2019-12-17 00:27:30 2019-12-17 00:27:29
19 2019-12-16 23:51:43 2019-12-16 22:04:44
18 2019-12-16 23:21:43 2019-12-16 22:04:44
17 2019-12-16 22:51:43 2019-12-16 21:49:30
16 2019-12-16 22:21:43 2019-12-16 21:49:30
15 2019-12-16 21:51:43 2019-12-16 21:49:30
14 2019-12-16 03:47:00 2019-12-15 22:46:59
13 2019-12-16 03:17:00 2019-12-15 22:46:59
12 2019-12-16 02:47:00 2019-12-15 22:46:59
11 2019-12-16 02:17:00 2019-12-15 22:46:59
10 2019-12-16 01:47:00 2019-12-15 22:46:59
9 2019-12-16 01:17:00 2019-12-15 22:46:59
8 2019-12-16 00:47:00 2019-12-15 22:46:59
SQL> call wsr$drop_snapshot_range(8,10); --删除指定范围snapshot
PL/SQL procedure successfully completed.
SQL> wsr list;
Listing the lastest Completed Snapshots
Snap Id Snap Started DB_startup_time
--------------- ------------------- ------------------
27 2019-12-17 04:37:31 2019-12-17 03:30:19
26 2019-12-17 04:30:21 2019-12-17 03:30:19
25 2019-12-17 04:00:21 2019-12-17 03:30:19
24 2019-12-17 03:30:21 2019-12-17 03:30:19
23 2019-12-17 01:57:30 2019-12-17 00:27:29
22 2019-12-17 01:27:30 2019-12-17 00:27:29
21 2019-12-17 00:57:30 2019-12-17 00:27:29
20 2019-12-17 00:27:30 2019-12-17 00:27:29
19 2019-12-16 23:51:43 2019-12-16 22:04:44
18 2019-12-16 23:21:43 2019-12-16 22:04:44
17 2019-12-16 22:51:43 2019-12-16 21:49:30
16 2019-12-16 22:21:43 2019-12-16 21:49:30
15 2019-12-16 21:51:43 2019-12-16 21:49:30
14 2019-12-16 03:47:00 2019-12-15 22:46:59
13 2019-12-16 03:17:00 2019-12-15 22:46:59
12 2019-12-16 02:47:00 2019-12-15 22:46:59
11 2019-12-16 02:17:00 2019-12-15 22:46:59
7 2019-12-16 00:17:00 2019-12-15 22:46:59
6 2019-12-15 23:47:00 2019-12-15 22:46:59
5 2019-12-15 23:17:00 2019-12-15 22:46:59
SQL> wsr 10 20 --收集指定范围snapshot报告
GS-00601, [1:4]Sql syntax error: start_snap_id doesn't exist!
WSR Report Build failed.
SQL> wsr 11 20
GS-00516, Err occur when generate WSR report, msg: Database restarts in the middle of two snapshots.
WSR Report Build failed.
SQL> wsr 24 26 ----收集指定范围snapshot报告
WSR report file name : wsrrpt_24_26.html
WSR report Generation Success.
SQL> wsr 24 26 "/tmp/24-26.html" ----收集指定范围snapshot报告,并指定报告路径及名称
WSR report file name : tmp/24-26.html
WSR report Generation Success.
SQL>
WSR 相关视图
ADM_HIST_SNAPSHOT :历史快照信息
ADM_HIST_WR_CONTROL :WSR相关配置
ADM_HIST_SYSSTAT :DV_SYS_STATS快照信息
ADM_HIST_SYSTEM :DV_SYSTEM快照信息
ADM_HIST_SYSTEM_EVENT :DV_SYS_EVENTS快照信息
ADM_HIST_SQLAREA :DV_SQLS快照信息
ADM_HIST_PARAMETER :DV_PARAMETERS快照信息
ADM_HIST_WAITSTAT :DV_WAIT_STATS快照信息
ADM_HIST_LATCH :DV_LATCHS快照信息
ADM_HIST_LIBRARYCACHE :DV_LIBRARY_CACHE快照信息
ADM_HIST_SEGMENT :DV_SEGMENT_STATS快照信息
ADM_HIST_DBASEGMENTS :ADM_SEGMENTS快照信息
ADM_JOBS :快照相关job信息
扩展:gs_wsr
数据库集群部署成功后,GaussDB提供了gs_wsr工具将DN上的WSR报告统一生成并打包返回,极大提升了集群环境快速收集报告的效率。
[omm@Gauss1 ~]$ gs_wsr -t listsnapshot --查看快照点
SNAP_ID DBID INSTANCE_ID STARTUP_TIME SNAP_TIME FLUSH_ELAPSED SESSIONS CURSORS
------------ ------------ ------------ -------------------------------- -------------------------------- ------------------------ ------------ ------------
28 1199615300 0 2019-12-17 03:30:19.241 2019-12-17 05:00:21.217 -00000 00:00:00.2 71 2
27 1199615300 0 2019-12-17 03:30:19.241 2019-12-17 04:37:31.699 -00000 00:00:00.7 69 1
26 1199615300 0 2019-12-17 03:30:19.241 2019-12-17 04:30:21.562 -00000 00:00:00.6 70 2
25 1199615300 0 2019-12-17 03:30:19.241 2019-12-17 04:00:21.958 +00000 00:00:00.0 70 2
24 1199615300 0 2019-12-17 03:30:19.241 2019-12-17 03:30:21.420 -00000 00:00:00.4 49 1
23 1199615300 0 2019-12-17 00:27:29.283 2019-12-17 01:57:30.247 -00000 00:00:00.2 79 1
22 1199615300 0 2019-12-17 00:27:29.283 2019-12-17 01:27:30.584 -00000 00:00:00.6 70 2
21 1199615300 0 2019-12-17 00:27:29.283 2019-12-17 00:57:30.947 +00000 00:00:00.1 59 1
20 1199615300 0 2019-12-17 00:27:29.283 2019-12-17 00:27:30.306 -00000 00:00:00.3 50 2
9 rows fetched.
[omm@Gauss1 ~]$ gs_wsr -t report --begin-time="20191217 03:30:21" --end-time="20191217 04:30:21" --收集指定时间段报告
Successful completion of report collection, results are stored in home/omm/20191217-03-30-21_20191217-04-30-21.tar.gz.
[omm@Gauss1 tmp]$ tar -zxvf home/omm/20191217-03-30-21_20191217-04-30-21.tar.gz
24_25_DB4_7.html
24_25_DB3_5.html
24_25_DB2_3.html
24_25_DB1_1.html
[omm@Gauss1 ~]$
GaussDB 不仅支持上边的单命令一键收集,还支持部署定时任务,定时自动收集:
[omm@Gauss1 ~]$ gs_wsr -t createtask --time=60 --创建任务,每60min执行一次
========================================
Begin to create wsr cron task.
Create wsr cron task time interval is 60 minutes.
Successfully create wsr cron task.
========================================
[omm@Gauss1 ~]$ gs_wsr -t updatetask --time=120 --更新任务
[GAUSS-50004] : The parameter '--time' value is incorrect. Value scope is 15 or 30 or 60.
[omm@Gauss1 ~]$ gs_wsr -t updatetask --time=30
========================================
Begin to update wsr cron task.
Update wsr task time interval to 30 minutes.
Successfully update wsr cron task.
========================================
[omm@Gauss1 ~]$ gs_wsr -t taskstatus --查看任务状态
========================================
Check wsr cron task status.
The wsr cron task is running.
Task time interval: [ 30 minutes ].
Check wsr cron task status Finished.
========================================
[omm@Gauss1 ~]$ gs_wsr -t deletetask --删除任务
========================================
Begin to delete wsr cron task.
Successfully delete wsr cron task.
========================================
[omm@Gauss1 ~]$
gs_wsr常用命令:
创建WSR的定时任务
gs_wsr -t createtask --time=MINUTES
删除WSR的定时任务
gs_wsr -t deletetask
更新WSR定时任务时间
gs_wsr -t updatetask --time=MINUTES
查询定时任务状态
gs_wsr -t taskstatus
生成WSR报告
gs_wsr -t report --begin-time="BEGINTIME" --end-time="ENDTIME" [--outDir="dir"]
查看快照
gs_wsr -t listsnapshot [-I INSTANCENAME] [--date="DATE"]
显示帮助信息
gs_wsr -? | --help
显示版本号信息
gs_wsr -V | --version
一睹为快:
WSR报告样例
https://pan.baidu.com/s/1CHBPMELRMBhRCLHYh574Mw
关注国产,关注未来 我是Kevin YAN!
参考:
1. 《Gauss100官方文档》
2. https://support.huawei.com
关注我,可查阅更多文章呦!