使用db2diag过滤DB2诊断日志

来源:互联网 发布:无人机测量数据 编辑:程序博客网 时间:2024/06/18 10:14

要分析一个37MB的诊断日志文件,由于该数据库的USEREXIT有问题,诊断日志中记录了大量数据库日志归档失败的错误信息,可读性很差。通过使用db2diag命令的 -gv 选项,可以过滤掉日志中的一些重复信息和无关信息,而使用 -g 选项又可以筛选其中的有用信息,详见下例。
这个诊断日志文件是从生产环境中取来的,70万行,直接查看眼睛都看花了~~~

db2inst1@suse-db:~/test> ls -lht db2diag-db1-new.log
-rw-rw-rw- 1 root root 37M 2009-11-30 09:44 db2diag-db1-new.log
db2inst1@suse-db:~/test> wc -l db2diag-db1-new.log
703600 db2diag-db1-new.log

[@more@]其中,绝大部分内容都是数据库日志归档失败的错误信息:

2009-11-24-20.59.48.743143+480 I76549337G369 LEVEL: Warning
PID : 9970 TID : 3086087872 PROC : db2logmgr (DDN)
INSTANCE: db2inst NODE : 000
FUNCTION: DB2 UDB, data protection, sqlpgRetryFailedArchive, probe:4780
MESSAGE : Still unable to archive log file 1624 due to rc 24 for LOGARCHMETH1
using method 4 and target .

2009-11-24-21.00.09.767137+480 E76549707G310 LEVEL: Error (OS)
PID : 9970 TID : 3086087872 PROC : db2logmgr (DDN)
INSTANCE: db2inst NODE : 000
FUNCTION: DB2 UDB, oper system services, sqloexec2, probe:2
CALLED : OS, -, unspecified_system_function OSERR: EINTR (4)

2009-11-24-21.00.09.767658+480 E76550018G482 LEVEL: Error
PID : 9970 TID : 3086087872 PROC : db2logmgr (DDN)
INSTANCE: db2inst NODE : 000
FUNCTION: DB2 UDB, data protection, sqlpgInvokeUserexit, probe:1140
MESSAGE : ADM1832E DB2 was unable to find the user exit program when archiving
log file "S0001624.LOG" from
"/mnt/data/db2inst/NODE0000/SQL00001/SQLOGDIR/" for database "DDN".
The error code was "24".

2009-11-24-21.00.09.768624+480 I76550501G384 LEVEL: Error
PID : 9970 TID : 3086087872 PROC : db2logmgr (DDN)
INSTANCE: db2inst NODE : 000
FUNCTION: DB2 UDB, data protection, sqlpgArchiveLogFile, probe:3160
MESSAGE : Failed to archive log file S0001624.LOG to USEREXIT from
/mnt/data/db2inst/NODE0000/SQL00001/SQLOGDIR/ with rc = 24.


2009-11-24-23.16.09.623814+480 I77155724G308 LEVEL: Error
PID : 9970 TID : 3086087872 PROC : db2logmgr (DDN)
INSTANCE: db2inst NODE : 000
FUNCTION: DB2 UDB, data protection, sqlpgArchivePendingLogs, probe:1500
MESSAGE : Log archive failed with rc 24 for LOGARCHMETH1.

下面使用虚拟机上的DB2 Express-C V9.7的db2diag将这些信息过滤掉:

db2inst1@suse-db:~/test> db2ls

Install Path Level Fix Pack Special Install Number Install Date Installer UID
---------------------------------------------------------------------------------------------------------------------
/opt/ibm/db2/V9.7 9.7.0.0 0 Mon Oct 5 00:36:24 2009 CST 0
db2inst1@suse-db:~/test> db2diag -gv proc='db2logmgr (DDN)' db2diag-db1-new.log > /tmp/db2diag-db1-new-temp01.log
db2inst1@suse-db:~/test> wc -l /tmp/db2diag-db1-new-temp01.log
121004 /tmp/db2diag-db1-new-temp01.log

注意,条件中等号右边的内容如果有空格,需要用单引号或双引号引起来,并且应严格区分大小写。如果想不区分大小写,应使用 -gvi 选项。

db2inst1@suse-db:~/test> db2diag -help | grep gv
-gv - case-sensitive invert matching
-gvi , -giv - case-insensitive invert matching

可以看到,过滤后的日志文件只剩下12万行。当然,这样可能会丢失db2logmgr进程相关的一些有用信息。如果力求精确,可以在 = 左边加上 ^ 或 : ,表示以等号右侧内容开头或包含等号右侧内容,然后用MESSAGE、FUNCTION等字段进行匹配即可。例如:

db2inst1@suse-db:~/test> db2diag -gv message^='Still unable to archive' db2diag-db1-new.log > /tmp/db2diag-db1-new-temp11.log
db2inst1@suse-db:~/test> wc -l /tmp/db2diag-db1-new-temp11.log
624375 /tmp/db2diag-db1-new-temp11.log
db2inst1@suse-db:~/test> db2diag -gv function:=sqloexec2 /tmp/db2diag-db1-new-temp11.log > /tmp/db2diag-db1-new-temp12.log
db2inst1@suse-db:~/test> wc -l /tmp/db2diag-db1-new-temp12.log
501945 /tmp/db2diag-db1-new-temp12.log
db2inst1@suse-db:~/test> db2diag -gv message:=ADM1832E /tmp/db2diag-db1-new-temp12.log > /tmp/db2diag-db1-new-temp13.log
db2inst1@suse-db:~/test> wc -l /tmp/db2diag-db1-new-temp13.log
318345 /tmp/db2diag-db1-new-temp13.log
db2inst1@suse-db:~/test> db2diag -gv message^='Failed to archive' /tmp/db2diag-db1-new-temp13.log > /tmp/db2diag-db1-new-temp14.log
db2inst1@suse-db:~/test> wc -l /tmp/db2diag-db1-new-temp14.log
175545 /tmp/db2diag-db1-new-temp14.log
db2inst1@suse-db:~/test> db2diag -gv message^='Log archive failed' /tmp/db2diag-db1-new-temp14.log > /tmp/db2diag-db1-new-temp15.log
db2inst1@suse-db:~/test> wc -l /tmp/db2diag-db1-new-temp15.log
121049 /tmp/db2diag-db1-new-temp15.log

本例中没有使用上述方法,只是用PROC字段进行了过滤。接下来,用同样的方法,继续以PID、PROC等字段进行一系列过滤:

db2inst1@suse-db:~/test> db2diag -gv pid=9844 /tmp/db2diag-db1-new-temp01.log > /tmp/db2diag-db1-new-temp02.log
db2inst1@suse-db:~/test> wc -l /tmp/db2diag-db1-new-temp02.log
67116 /tmp/db2diag-db1-new-temp02.log
db2inst1@suse-db:~/test> db2diag -gv pid=9845 /tmp/db2diag-db1-new-temp02.log > /tmp/db2diag-db1-new-temp03.log
db2inst1@suse-db:~/test> wc -l /tmp/db2diag-db1-new-temp03.log
13484 /tmp/db2diag-db1-new-temp03.log
db2inst1@suse-db:~/test> db2diag -gv proc=db2hmon /tmp/db2diag-db1-new-temp03.log > /tmp/db2diag-db1-new-temp04.log
db2inst1@suse-db:~/test> wc -l /tmp/db2diag-db1-new-temp04.log
12374 /tmp/db2diag-db1-new-temp04.log
db2inst1@suse-db:~/test> db2diag -gv pid=5686 /tmp/db2diag-db1-new-temp04.log > /tmp/db2diag-db1-new-temp05.log
db2inst1@suse-db:~/test> db2diag -gv pid=5687 /tmp/db2diag-db1-new-temp05.log > /tmp/db2diag-db1-new-temp06.log
db2inst1@suse-db:~/test> wc -l /tmp/db2diag-db1-new-temp06.log
11814 /tmp/db2diag-db1-new-temp06.log
db2inst1@suse-db:~/test> cp /tmp/db2diag-db1-new-temp06.log ./db2diag-db1-new_1.log

处理后的日志文件db2diag-db1-new_1.log只有1万多行,根据其内容分析问题就比较方便了。此时,如果只想查看其中的部分日志信息,可以使用 -g 选项进行筛选,它和 -gi 的用法与 -gv 和 -gvi 类似。

db2inst1@suse-db:~/test> db2diag -help | grep '-g' | grep -v gv
-filter , -g - case-sensitive search for a list of field-pattern pairs
-gi - case-insensitive search for a list of field-pattern pairs

例如,查看等级为严重的信息:

db2diag -g level=Severe db2diag-db1-new_1.log | more

又如,查看db2sys产生的等级为严重的日志信息:

db2diag -g level=Severe,proc=db2sysc db2diag-db1-new_1.log | more

如果想同时查看同一字段两种不同内容的信息,就需要使用一些字段特有的专用选项,如查看等级为严重和错误的日志信息:

db2diag -level 'Severe,Error' db2diag-db1-new_1.log | more

db2diag还有很多其它功能和用法,可通过 db2diag -help 查看。

0 0
原创粉丝点击