DB2监控工具

DB2提供多种监控工具和方法予troubleshooting:
1.snapshot命令行监控,官方文档:
https://www.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.admin.mon.doc/doc/r0006001.html
snapshot 相当于相机,把数据库当前运动情况记录下来,监控对象包括实例,数据库,
应用程序活动,表空间,表,锁,缓冲池等信息。
要获取对象snapshot信息需要先打开监控开关(monitor switches),这些开关默认是关闭的,
有会话级别的打开和实例级别打开:
1.会话级别
查看:db2 get monitor switches
            [test@demo ~]$ db2 get monitor switches
            Monitor Recording Switches
Switch list for db partition number 0
Buffer Pool Activity Information  (BUFFERPOOL) = OFF
Lock Information                        (LOCK) = OFF
Sorting Information                     (SORT) = OFF
SQL Statement Information          (STATEMENT) = OFF
Table Activity Information             (TABLE) = OFF
Take Timestamp Information         (TIMESTAMP) = ON  01/12/2019 12:47:50.560139
Unit of Work Information                 (UOW) = OFF
打开监控开关:
db2 update monitor switches using BUFFERPOOL on LOCK on SORT on STATEMENT on TIMESTAMP on TABLE on UOW on

2.实例级别
查看:
  [test@demo ~]$ db2 get dbm monitor switches
      DBM System Monitor Information Collected
Switch list for db partition number 0
Buffer Pool Activity Information  (BUFFERPOOL) = OFF
Lock Information                        (LOCK) = ON  01/12/2019 12:50:27.578122
Sorting Information                     (SORT) = OFF
SQL Statement Information          (STATEMENT) = OFF
Table Activity Information             (TABLE) = OFF
Take Timestamp Information         (TIMESTAMP) = ON  01/12/2019 12:47:50.560139
Unit of Work Information                 (UOW) = OFF
或:
[test@demo ~]$ db2 get dbm cfg|grep -i DFT
 Default charge-back account           (DFT_ACCOUNT_STR) = 
   Buffer pool                         (DFT_MON_BUFPOOL) = OFF
   Lock                                   (DFT_MON_LOCK) = OFF
   Sort                                   (DFT_MON_SORT) = OFF
   Statement                              (DFT_MON_STMT) = OFF
   Table                                 (DFT_MON_TABLE) = OFF
   Timestamp                         (DFT_MON_TIMESTAMP) = ON
   Unit of work                            (DFT_MON_UOW) = OFF
打开监控开关:db2 update monitor switches using UOW ON STATEMENT ON
查看会话里面是否生效:db2 get monitor switches 
若会话里面没生效,则需要再update后执行db2 attach to db2 <--重新attach到实例,修改配置才能在会话中生效,或者重启实例

实际分析可能需要抓取多次快照信息,可以写一个简单脚本来实现:
#!/bin/bash
read -r -p "input the database to be monitored: "  dbname
db2 connect to $dbname
for((  i=0;i<=10;i++ ))
do
    db2 get snapshot for dbm >> dbm.out  2>&1
    db2 get snapshot for database on $dbname >> db.out  2>&1
    db2 get snapshot for applications on $dbname >> app.out  2>&1
    db2 get snapshot for tables on $dbname >> tb.out  2>&1
    db2 get snapshot for tablespaces on $dbname >> tbs.out  2>&1
    db2 get snapshot for bufferpools on $dbname >> buff.out  2>&1
    db2 get snapshot for locks on $dbname >> lock.out  2>&1
    db2 get snapshot for dynamic sql on $dbname >> dsql.out  2>&1
    sleep 15s
done
db2 terminate

2.使用内置的管理视图来监控,官方文档:
https://www.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.admin.mon.doc/doc/c0055388.html

3.db2pd,官方文档:
https://www.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.admin.trb.doc/doc/c0054595.html
相对频繁的快照可能会造成系统的性能的影响,db2pd工具是更为轻量级监控工具:
db2pd -help
db2pd -latches
db2pd -stack all
db2pd -edus interval=10

4.db2top实时监控,官方文档:
https://www.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0025222.html

5.事件监控器,官方文档:
https://www.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.admin.mon.doc/doc/r0005993.html
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000915.html
创建监控test用户执行SQL语句的事件监控器:
db2 drop event monitor sqlmon
db2 "create EVENT MONITOR  sqlmon for STATEMENTS where AUTH_ID = 'TEST' write to table STMT(table tb3 in ts2)"
db2 "set event monitor sqlmon state=1"
查看事件监控器结果:
db2 "set event monitor sqlmon state=0"
db2 "select START_TIME, substr(APPL_ID,1,30) as APPL_ID, substr(STMT_TEXT,1,50) as STMT_TEXT from tb3"

你可能感兴趣的:(DB2)