使用 db2diag 工具来分析 db2diag 日志文件

使用 db2diag 工具来分析 db2diag 日志文件


供数据库和系统管理员使用的主日志文件为管理通知日志。

db2diag 日志文件旨在供 IBM 软件支持机构用于进行故障诊断。

管理通知日志消息也以标准化消息格式记录到 db2diag 日志文件。

db2diag 工具用于对 db2diag 日志文件中的大量信息进行过滤和格式化。过滤 db2diag 日志文件记录可缩短诊断问题时查找所需记录的时间。


示例 1:按数据库名称过滤 db2diag 日志文件

如果实例中有若干数据库,并且您只希望显示与数据库“SAMPLE”有关的信息,那么可以按如下所示过滤 db2diag 日志文件:

db2diag -g db=SAMPLE

因此,将仅显示包含“DB: SAMPLE”的 db2diag 日志文件记录,如:

2006-02-15-19.31.36.114000-300 E21432H406         级别:错误
PID:940                  TID:660         PROC:db2syscs.exe
实例:DB2                      节点:000          数据库:SAMPLE
APPHDL:0-1056                 APPID:*LOCAL.DB2.060216003103
函数:DB2 UDB,基本系统实用程序,sqleDatabaseQuiesce,探测点:2
消息:ADM7507W  数据库停顿请求成功完成。


示例 2:按进程标识过滤 db2diag 日志文件

以下命令可用来显示进程标识 (PID) 为 2200,并且在分区 0、1、2 或分区 3 上运行的进程生成的所有严重错误消息:

db2diag -g level=Severe,pid=2200 -n 0,1,2,3

注意,此命令可能以不同方式写入,包括 db2diag -l severe -pid 2200 -n 0,1,2,3。还要注意的是,-g 选项指定区分大小写的搜索,所以此处“Severe”会起作用,但如果使用了“severe”则会失败。满足如下要求时,这些命令将成功检索 db2diag 日志文件记录:

2006-02-13-14.34.36.027000-300 I18366H421         级别:严重
PID     : 2200                 TID  : 660         PROC : db2syscs.exe
实例:DB2                      节点:000          数据库:SAMPLE
APPHDL:0-1433               APPID:*LOCAL.DB2.060213193043
函数:DB2 UDB,数据管理,sqldPoolCreate,探测点:273
返回码:ZRC=0x8002003C=-2147352516=SQLB_BAD_CONTAINER_PATH
                    “错误的容器路径”


示例 3:格式化 db2diag 工具输出

以下命令过滤 2006 年 1 月 1 日之后发生,并且包含分区 0、1 或2 上记录的所有非严重错误和严重错误的所有记录。它会输出匹配的记录,因此时间戳记、分区号和级别将出现在第一行上,而 pid、tid 和实例名将出现在第二行上,之后是错误消息:

db2diag -time 2006-01-01 -node "0,1,2" -level "Severe, Error" |
db2diag -fmt "Time: %{ts}
分区:%node Message Level:%{level} \nPid:%{pid}  Tid:%{tid}
实例:%{instance}\nMessage: @{msg}\n"

生成的输出示例如下所示:

时间:2006-02-15-19.31.36.099000 分区:000 消息级别:错误
Pid:940 Tid:40 实例:DB2
消息:ADM7506W 已经请求了数据库停顿。

有关更多信息,请发出下列命令:

  • db2diag -help 提供了所有可用选项的简短描述

  • db2diag -h brief 提供对所有不带示例的选项的描述

  • db2diag -h notes 提供用法说明和限制

  • db2diag -h examples 提供一小组示例以帮助您入门

  • db2diag -h tutorial 提供所有可用选项的示例

  • db2diag -h all 提供最完整的选项列表


示例 4:过滤来自不同工具的消息

下列示例显示如何仅查看来自数据库管理器中的特定工具(或所有工具)的消息。受支持的工具包括:

  • ALL,这会返回来自所有工具的记录

  • MAIN,这会返回来自 DB2® 常规诊断日志的记录,例如 db2diag 日志文件和管理通知日志

  • OPTSTATS,这会返回与优化器统计信息有关的记录

要读取来自 MAIN 工具的消息,请使用以下命令:

db2diag -facility MAIN

要显示来自 OPTSTATS 工具的消息并滤出级别为 Severe 的记录,请使用以下命令:

db2diag -fac OPTSTATS -level Severe

要显示来自所有可用工具的消息并滤出实例为 harmistr 级别为 Error 的记录,请使用以下命令:

db2diag -fac all -g instance=harmistr,level=Error

要显示 OPTSTATS 工具中级别为 Error 并且以特定格式输出时间戳记和 PID 字段的所有消息,请使用以下命令:

db2diag -fac optstats -level Error -fmt " Time :%{ts} Pid :%{pid}"


示例 5:根据时间戳记来合并文件和对记录进行排序

此示例说明了如何根据时间戳记来合并两个或更多 db2diag 日志文件以及对记录进行排序。

要合并的两个 db2diag 日志文件为如下所示:

  • db2diag.0.log;它包含具有以下时间戳记的 Level:Error 的记录:

    • 2009-02-26-05.28.49.822637

    • 2009-02-26-05.28.49.835733

    • 2009-02-26-05.28.50.258887

    • 2009-02-26-05.28.50.259685

  • db2diag.1.log;它包含具有以下时间戳记的 Level:Error 的记录:

    • 2009-02-26-05.28.11.480542

    • 2009-02-26-05.28.49.764762

    • 2009-02-26-05.29.11.872184

    • 2009-02-26-05.29.11.872968

要根据时间戳记来合并两个诊断日志文件以及对记录进行排序,请执行以下命令:

db2diag -merge db2diag.0.log db2diag.1.log -fmt %{ts} -level error

执行合并以及对记录进行排序的结果为如下所示:

  • 2009-02-26-05.28.11.480542

  • 2009-02-26-05.28.49.764762

  • 2009-02-26-05.28.49.822637

  • 2009-02-26-05.28.49.835733

  • 2009-02-26-05.28.50.258887

  • 2009-02-26-05.28.50.259685

  • 2009-02-26-05.29.11.872184

  • 2009-02-26-05.29.11.872968

时间戳记是按时间顺序进行合并和排序的。


示例 6:按时间戳记合并单台主机中的分割诊断目录路径文件以及对记录进行排序

此示例说明了如何合并当前主机上的三个数据库分区中的文件。为了获得分割诊断目录路径,按以下方式设置了 diagpath 数据库管理器配置参数:

db2 update dbm cfg using diagpath '"$n"'

以下是要合并的三个 db2diag 日志文件的列表:

  • ~/sqllib/db2dump/NODE0000/db2diag.log

  • ~/sqllib/db2dump/NODE0001/db2diag.log

  • ~/sqllib/db2dump/NODE0002/db2diag.log

要根据时间戳记来合并这三个诊断日志文件以及对记录进行排序,请执行以下命令:

db2diag -merge


示例 7:合并多台主机和多个数据库分区中的分割诊断目录路径文件

在此示例中,通过使用以下命令设置 diagpath 数据库管理器配置参数,以按照物理主机和数据库分区来分割缺省诊断数据目录路径:

db2 update dbm cfg using diagpath '"$h$n"'

此示例说明了如何获得所有诊断日志中所有记录的输出,以及如何合并 bower 和 horton 这两个主机中每个主机上的三个数据库分区中的诊断日志文件。以下是六个 db2diag 日志文件的列表:

  • ~/sqllib/db2dump/HOST_bower/NODE0000/db2diag.log

  • ~/sqllib/db2dump/HOST_bower/NODE0001/db2diag.log

  • ~/sqllib/db2dump/HOST_bower/NODE0002/db2diag.log

  • ~/sqllib/db2dump/HOST_horton/NODE0003/db2diag.log

  • ~/sqllib/db2dump/HOST_horton/NODE0004/db2diag.log

  • ~/sqllib/db2dump/HOST_horton/NODE0005/db2diag.log

要输出所有这六个 db2diag 日志文件中的记录,请运行以下命令:

db2diag -global

bower 和 horton 这两个主机中每个主机上有三个数据库分区,要合并这些数据库分区中的诊断数据目录路径中的所有六个 db2diag 日志文件,并且根据时间戳记设置输出的格式,请执行以下命令:

db2diag -global -merge -sdir /temp/keon -fmt %{ts}

其中 /temp/keon 是 bower 和 horton 这两个主机共享的共享目录,在处理期间用来存储每个主机的临时合并文件。


示例 8:仅过滤和合并最新的诊断日志条目

在此示例中,将过滤 db2diag 日志文件记录以仅显示特定数目的最新条目。要显示分区数据库环境中每个分区(共有 3 个分区)的 5 个最新格式化记录并按时间戳记进行合并和格式化,请输入:

db2diag -lastrecords 5 -global -merge -sdir /home/vbmithun -fmt %{ts}

2010-10-08-04.46.02.092192
2010-10-08-04.46.02.092821
2010-10-08-04.46.02.093497
2010-10-08-04.46.02.094431
2010-10-08-04.46.02.095317
2010-10-08-04.46.05.068648
2010-10-08-04.46.05.069212
2010-10-08-04.46.05.069900
2010-10-08-04.46.05.071008
2010-10-08-04.46.05.071831
2010-10-08-04.46.07.302051
2010-10-08-04.46.07.302727
2010-10-08-04.46.07.303544
2010-10-08-04.46.07.304647
2010-10-08-04.46.07.305391

还可以进一步过滤最新的诊断日志记录以仅返回特定级别的消息。例如,要仅返回最新的 10 个记录中具有严重消息级别的记录,请输入:

$ db2diag db2diag.log -lastrecords 10 -level Severe -fmt %{ts}

2010-08-11-04.11.33.733807
2010-08-11-04.11.33.735398


示例 9:归档无实例客户机上的 db2diag 日志文件

从 V9.7 FP4 开始,IBM® Data Server Driver Package 和 IBM Data Server for ODBC and CLI 提供了 db2diag -archive(或 -A)选项。此选项使您能够归档无实例客户机上的诊断日志文件。例如:

$ db2diag -A
db2diag: Moving "/home/usr1/clidriver/db2dump/db2diag.log"
         to     "/home/usr1/clidriver/db2dump/db2diag.log_2010-09-14-01.16.26"

归档到指定目录,如:

db2diag -A /db2diagbak


如果您指定除 -archive 或 -A 之外的选项,那么将返回错误消息。例如:

$ db2diag -x
db2diag: Unrecognized option: -x

$ db2diag -pid 1234
db2diag: Unrecognized option: -pid



附录1:db2diag简明介绍

db2diag.log文件是记录db2运行日志,可以通过此文件,查看记录的有关db2数据库详细的错误信息,如果

db2数据库在运行过程中经常报错的话,这个文件增长会很快,需要定期清理,备份移走或者删除。

默认位置:

C:\Documents and Settings\All Users\Application Data\IBM\DB2\DB2COPY1\DB2

可以使用

C:\>dir /w/d/s db2diag.log 来查找其位置


db2diag是查看db2diag.log文件的一个工具。


备份db2diag.log文件

C:\>db2diag -A f:\db2logbak  将日志文件备份到f:\db2logbak目录下


使用命令帮助 db2diag -h

语法:db2diag option filename


db2diag 中信息的格式:

2012-04-19-14.26.55.281000+480 I405668H601        LEVEL: Severe

PID     : 5984                 TID  : 2264        PROC : db2syscs.exe

INSTANCE: DB2                  NODE : 000         DB   : DMSLOG

APPHDL  : 0-9                  APPID: 127.0.0.1.2680.120419062650

AUTHID  : 540

EDUID   : 2264                 EDUNAME: db2agent (DMSLOG) 0

FUNCTION: DB2 UDB, buffer pool services, sqlbFetchAndStoreContainerFSInfo, probe

:10

MESSAGE : ECF=0x9000001A=-1879048166=ECF_FILE_DOESNT_EXIST

          File doesn't exist

DATA #1 : File name, 44 bytes

D:\DB2\NODE0000\DMSLOG\T0000007\C0000000.LRG


通过上面的记录分析db2diag使用的option:

time(t) 就是日志记录的时间戳,如"2012-04-19-14.26.55.281000+480"

level(l) 信息级别,有Severe、Error、Warnning和Event,如"Severe"

pid 进程号,如"5984"

tid 线程号,如"2264" 

eduid EDU ID,如"2264"

node(n) 实例号 ,如"000"

error(e) 错误,上面没有

count(c) 记录条数,上面为一条记录

rc 显示ZRC或ECF记录,上面不是

括号中为简写。


使用db2diag时可以有两种查找方式:

1) 使用列标识参数,格式:db2diag -option value

option:有time(t)、level(l)、pid、tid、eduid、node(n)、error(e)、count(c)、rc、g、gi、gv、gvi、a、h等。

应用举例:

根据严重错误查找 db2diag -level severe 查询的是所有的严重错误

根据进程PID查找  db2diag -pid 5984  查询的是进程PID为5984的数据

查询PID=5984的严重错误 db2diag -pid 5984 -level severe

根据时间查找 db2diag -time 2011-10-08-11.40.31 查询的是2011-10-08 11:30:31秒以后的数据

根据时间段范围查找 db2diag -time 2012-01-16-11.37.00:2012-01-16-11.38.00 查找的是2012-01-16 11:37:00到2012-01-16 11:38:00之间的数据


2) 使用-g参数,使用filename进行查找

格式:db2diag -g "filename=value"

filename:time、level、pid、tid、eduid、node、error、rc、function、message、data之类的。就是在记录冒号前的名称。

参数

-g : 根据列模式查找,多条件中间使用","隔开,条件是"filename=value"形式

-gi: 根据列模式查找,并忽略大小写

-gv: 根据列模式查找,结果取反

-gvi: 根据列模式查找,并忽略大小写,结果取反


表达式形式:filename=value

= 精确查找

:= 模糊匹配

!= 精确查找上结果取反

^= 以列值开头模糊匹配查找

!^= 不以列值开头的模糊匹配查找

应用举例:

根据应用程序句柄查找 db2diag -gi "apphdl=0-10"

根据级别为错误查找 db2diag -gi "level=error"

根据ZRC信息查找   db2diag -gi "message:=zrc"

查找进程1060946的所有严重错误(Severe)  db2diag -g "PID=1060946,LEVEL=Severe"




DB2Diag中记录的日志Level有:Severe、Error、Warning和Event

记录的类型与实例参数DIAGLEVEL有关,默认为3

db2 get dbm cfg|find "DIAGLEVEL"

0 - 没有捕获到诊断数据

1 - 仅严重错误

2 - 所有错误

3 - 所有错误和警告

4 - 所有错误、警告以及参考消息


高级应用举例:


1 根据ZRC信息查找  db2diag -rc 0x83000001

----------------------------------------------------

LEVEL: Severe

MESSAGE : ZRC=0x83000001=-2097151999

Error encountered trying to read a page - information follows : 

DATA #2 : String, 29 bytes

Failed to read data from disk

DATA #3 : Page ID, PD_TYPE_SQLB_PAGE_ID, 4 bytes

4632

DATA #4 : Object descriptor, PD_TYPE_SQLB_OBJECT_DESC, 68 bytes

    Obj: {pool:7;obj:172;type:64} Parent={7;172}

  lifeLSN:       0000036604E7

  tid:           0 0  0

  extentAnchor:        4632

  initEmpPages:           0

  poolPage0:           4640

  poolflags:            122

  objectState:           27

  lastSMP:                0

  pageSize:           16384

  extentSize:             8

  bufferPoolID:           1

  partialHash:   1085014023

  bufferPool:    0x71a3f570

DATA #5 : Bitmask, 4 bytes

0x00000002

-------------------------------

其中pool是表空间的ID,obj是对象的ID,使用下面语句查询表

db2 "select tbspace,tabschema,tabname,tableid,tbspaceid from syscat.tables where tbspaceid=7 and tableid=172"


2 显示实例启动时间

C:\>db2diag -gi PROC=db2syscs.exe,LEVEL=Event,MESSAGE:=ADM7513W

MESSAGE : ADM7513W  Database manager has started.




附录2:db2diag帮助信息

$ db2diag -h

 db2diag - The db2diag log(s) Analysis Tool

 db2diag is a tool for filtering and formatting the db2diag log file(s)

 Command syntax:
                   .------------.  .--------------.
                   V            |  V              |
      >>--db2diag--+------------+--+--------------+--><
                    |          |    |            |
                     --option--      --filename--

 Command parameters:

 filename          - one or more space-separated path names of diagnostic logs
 -help   , -h , ?  - help information. To get help on help, try "db2diag -h h"
 -filter , -g      - case-sensitive search for a list of field-pattern pairs
 -gi               - case-insensitive search for a list of field-pattern pairs
 -gv               - case-sensitive invert matching
 -gvi    , -giv    - case-insensitive invert matching
 -invert , -v      - invert the sense of matching for all filtering options
 -exist            - record field must exist in order to be processed
 -pid              - find all records for a list of process IDs
 -tid              - find all records for a list of thread IDs
 -eduid            - find all records for a list of EDU IDs
 -node   , -n      - find all records for a list of nodes
 -error  , -e      - find all records for a list of errors
 -level  , -l      - find all records for a list of severity levels
 -global ,         - find all records from all the database partitions
 -merge  ,         - merge all the records from all the database partitions
                     on the current host 
 -history, -H      - display the history of logged records for a time interval
 -time   , -t      - display all the records within a particular time interval
 -count  , -c      - display a count of matching records
 -verbose, -V      - display all record fields whether they contain data or not
 -strict           - display records using one "field: value" pair per line
 -cbe              - display records in the Common Base Event (CBE) format
 -fmt              - format tool's output using a format string
 -output , -o      - save output into a file
 -follow , -f      - continuously display appended records as the file grows
 -archive, -A      - archive a diagnostic log file
 -readfile         - read from a file ignoring terminal input (used in scripts)
 -rc               - display descriptions of DB2 error return codes, ZRC or ECF
 -ecfid            - display function info extracted from the numeric ECF ID
 -facility, -fac   - display messages from a particular facility
 -lastlines        - consider last <n> lines given for filtering
 -lastrecords      - consider last <n> records given for filtering

 Note: db2diag reads from rotating db2 diag logs if dbm config parameter 
 DIAGSIZE is set. Otherwise by default, it reads from default db2diag.log file
 

 "db2diag -h <option1[,option2[,option3...]]>" - displays additional help and
  usage examples for one or more options specified in the options list

 "db2diag -h brief"    - displays help for all options without examples

 "db2diag -h examples" - displays a few typical examples to get started

 "db2diag -h tutorial" - displays more advanced examples covering all features

 "db2diag -h notes"    - displays usage notes and restrictions that apply

 "db2diag -h all"      - displays help in the most complete form with detailed
                         information about all options and usage examples




转载于:https://my.oschina.net/goopand/blog/352920

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值