http://publib.boulder.ibm.com/infocenter/db2luw/v8/ index.jsp?topic=/com.ibm.db2.udb.doc/admin/r0000888.htm http://publib.boulder.ibm.com/infocenter/db2luw/v8/ index.jsp?topic=/com.ibm.db2.udb.doc/core/r0011729.htm Note: catch option is used to enable the database to catch certain errors from that point in time forward. $ db2pd -help Usage: -h | -help [file=<filename>] Help -v | -version [file=<filename>] Version -osinfo [disk] [file=<filename>] Operating System Information -dbpartitionnum <num>[,<num>] Database Partition Number(s) -alldbpartitionnums All partition numbers -database | -db <database>[,<database>] Database(s) -alldatabases | -alldbs All Active Databases
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
The db2pd tool is a problem determination tool which contains quick and immediate information from the DB2 memory sets. It is similar to the Informix "onstat" tool, and runs very quickly as it is not acquiring any locks or latches and runs outside of the DB2 engine resources.
The tool collects this information without acquiring any latches or using any engine resources. It is therefore possible (and expected) to retrieve information that is changing while db2pd is collecting information; hence the data might not be completely accurate. If null pointers are encountered, a signal handler is used to prevent db2pd from aborting abnormally. This can result in messages such as "Changing data structure forced command termination" to appear in the output. Nonetheless, the tool can be helpful for problem determination. Two benefits to collecting information without latching include faster retrieval and no competition for engine resources.
What follow are some examples of problem scenarios in which db2pd can be used to expedite problem determination.
Scenario 1: Catching a lock timeout using the "-catch" db2pd option:
The purpose of db2pd -catch is to allow the user to catch any sqlcode (and reason code), zrc code, or ecf code and capture the information needed to solve the error code.
The primary reaction is to execute the db2cos (callout script) that can dynamically be altered to run any db2pd command, operating system command, or any other command needed to solve the problem. The template db2cos file is located in sqllib/cfg and must be moved to sqllib in order to be called.
Usage:
-catch clear | status | <errorCode> [<action>] [count=<count>]Sets catchFlag to catch error or warning.
Error Codes:
<sqlCode>[,<reasonCode>] / sqlcode=<sqlCode>[,<reasonCode>]ZRC (hex or integer)ECF (hex or integer)"deadlock" or "locktimeout"
Actions:
[db2cos] (default) Run sqllib/db2cos callout script[lockname=<lockname>] Lockname for catching specific lock(lockname=000200030000001F0000000052)[locktype=<locktype>] Locktype for catching specific lock(locktype=R or locktype=52)
Examples (see last example for a step-by-step locktimeout catch):
1. Catch sqlcode -911 reason code 68 and run db2cos 2. db2pd -catch -911,68 db2cos OR3. db2pd -catch -911,684. Error Catch #15. Sqlcode: -9116. ReasonCode: 687. ZRC: 08. ECF: 09. Component ID: 010. LockName: Not Set11. LockType: Not Set12. Current Count: 013. Max Count: 25514. Bitmap: 0x26115. Action: Error code catch flag enabled
Action: Execute sqllib/db2cos callout script16. Catch sqlcode -911 (and any reason code) and run db2cos 17. db2pd -catch -91118.19. db2pd -catch -91120. Input ECF string '-911' parsed as 0xFFFFFC71 (-911).21. Error Catch #222. Sqlcode: -91123. ReasonCode: 024. ZRC: 025. ECF: 026. Component ID: 027. LockName: Not Set28. LockType: Not Set29. Current Count: 030. Max Count: 25531. Bitmap: 0x6132. Action: Error code catch flag enabled
Action: Execute sqllib/db2cos callout script
33. Catch 0x80100044and run db2cos 34. db2pd -catch 0x8010004435. Input ZRC string '0x80100044'parsed as 0x80100044 (-2146435004).36. Error Catch #337. Sqlcode: 038. ReasonCode: 039. ZRC: -214643500440. ECF: 041. Component ID: 042. LockName: Not Set43. LockType: Not Set44. Current Count: 045. Max Count: 25546. Bitmap: 0xA147. Action: Error code catch flag enabled
Action: Execute sqllib/db2cos callout script48. Catch 0x80100044and run db2cos, but only fire the script one time. 49. db2pd -catch 0x80100044count=150. Input ZRC string '0x80100044'parsed as 0x80100044 (-2146435004).51. Error Catch #452. Sqlcode: 053. ReasonCode: 054. ZRC: -214643500455. ECF: 056. Component ID: 057. LockName: Not Set58. LockType: Not Set59. Current Count: 060. Max Count: 161. Bitmap: 0xA162. Action: Error code catch flag enabled
Error catch setting cleared for sqlCode -911 reasonCode 6865. Clear all settings 66. db2pd -catch clear all
All error catch flag settings cleared.
67. Step-by-step instructions to catch a lock timeout.
Copy the db2cos template into sqllib.
cp sqllib/cfg/db2cos sqllib/db2cos
Set the error catch setting. You can use -911,68, -911, or locktimeout. If fact, if you know the lock type or lock name in advance, you can use use the locktype or lockname suboptions to filter out unwanted lock catches.
ZRC: -2146435004ECF: 0Component ID: 0LockName: Not SetLockType: Not SetCurrent Count: 0Max Count: 1Bitmap: 0xA1Action: Error code catch flag enabledAction: Execute sqllib/db2cos callout script
Reproduce a lock timeout.
db2 update staff set id = 0DB21034E The command was processed as an SQL statement because it was not avalid Command Line Processor command. During SQL processing it returned:SQL0911N The current transaction has been rolled back because of a deadlockor timeout. Reason code "68". SQLSTATE=40001
Notice the db2diag.log tells us what happened.
2005-01-06-15.31.59.017134-300 I416442C274 LEVEL: EventPID : 9875676 TID : 1 PROC : db2pdINSTANCE: db2inst1 NODE : 000FUNCTION: DB2 UDB, RAS/PD component, pdErrorCatch, probe:30START : Error catch set for ZRC -2146435004
Now look in sqllib/db2dump/db2cos.rpt which is the default output file that contains the db2pd output generated when the error was caught.
Lock Timeout CaughtThu Jan 6 15:36:07 EST 2005Instance db2inst1Datbase: SAMPLEPartition Number: 0PID: 10379460TID: 1
Function: sqlplnfdComponent: lock managerProbe: 999Timestamp: 2005-01-06-15.36.07.084474AppID: *LOCAL.db2inst1.050106202920AppHdl:<snip>Database Partition 0 -- Database SAMPLE -- Active -- Up 0 days 00:06:53Locks:Address TranHdl Lockname Type Mode Sts Owner Dur HldCnt Att Rlse0x402C6B30 3 00020003000000040000000052 Row ..X W* 3 1 0 0 0x40
Just look for the "W*" as this is the lock that experienced the timeout. You can map this to a transaction, application, agent, and even SQL statement with all of the db2pd output provided. You can get strategic and narrow down the output or use other commands to collect the information you need. For example, you could change the db2pd options to use the "-locks wait" option that only prints locks with a wait status and their waiter. You could also put in -app, and -agent options if that's what you need.
There are several types of locks reported with db2pd -locks that can cause an application to wait. Common ones are table, pool, and row where other possibilities are Internal V (dynamic sql cache), Internal P (package cache), and CatCache (catalog cache). Prior to db2pd, there was no way to identify the Internal V, Internal P, or CatCache lock.
db2pd -locks output showing Catcache, Row, Internal V, and Internal P.
Locks:
Address TranHdl Lockname Type Mode Sts Owner 0x00000002202EA3E0 2 0000000200000B0520A4774043 CatCache ..X G 20x00000002202E30D8 2 00000002000004070000000052 Row .NS G 20x00000002202DCC28 2 00000002000000010001860056 Internal V ..S G 20x00000002202D88F0 2 53514C4532453047668358B641 Internal P ..S G 2
db2pd -catalogcache output showing the lock 0000000200000B0520A4774043 maps to a SYSTABLES entry for the SYSIBM table.
Catalog Cache:Configured Size 655360Current Size 353416Maximum Size 4294950912High Water Mark 393216
SYSTABLES:Address Schema Name Type TableID TbspaceID0x0000000220A47740 SYSIBM SYSFUNCTIONS V 0 0
LastRefID CatalogCacheLoadingLock CatalogCacheUsageLock Sts10615 000100000000000220A4774043 0000000200000B0520A4774043 V
db2pd -dynamic output showing that lock 00000002000000010001860056 maps to an sql statement creating a view. Since the dynamic cache has three tiers, one must identify the lock in the Variation section then map the Variation to an Environment and finally map the Environment to a Statement.
Dynamic Cache:Current Memory Used 1019927Total Heap Size 1271398Cache Overflow Flag 0Number of References 150Number of Statement Inserts 77Number of Statement Deletes 1Number of Variation Inserts 150Number of Statements 76
package_name, package_version, bindfile_path) as select l.libschema, l.libname, b.libversion, b.package_schema, b.package_name, b.package_version, b.bindfile_path from sysibm.syslibrarybindfiles as b, sysibm.syslibraries as l where b.lib_id = l.lib_id
db2pd -static output showing that lock 53514C4532453047668358B641 maps to a Package SQLE2E0G.
Static Cache:Current Memory Used 991807Total Heap Size 1271398Cache Overflow Flag 0Number of References 3Number of Package Inserts 2Number of Section Inserts 0
Packages:Address Schema PkgName Version UniqueID NumSec0x0000000220A01780 JMCMAHON SQLE2E0G AAAAARAU 0
UseCount NumRef Iso QOpt Blk Lockname0 1 CS 5 U 53514C4532453047668358B641
Scenario 3: Mapping an application to a dynamic SQL statement.
Starting with DB2 UDB, Version 8.2.2, db2pd -applications reports the Current and Last Anchor ID and Statement Unique ID for dynamic SQL statements. This allows direct mapping from an application to a dynamic sql statements.
The db2pd -memsets and -mempools options report statistics about DB2 Memory Sets and Memory Pools which can be very useful when trying to understand memory usage.
Memory Sets:Name Address Id Size Key DBP Type Ov OvSizeSAMPLE 0x0000000220000000 290831 46055424 0x0 0 1 Y 8978432App780 0xFFFFFFFF77F00000 1487884 131072 0x0 0 3 N 0
db2pd -memb appctl -db sample Printing all blocks in Appctl set id 566624315.Address PoolID PoolName BlockID Size I P N LOC File 0xA370C048 3 appctlh 1 64 1 0 0 150 30327041230xA370C0A8 3 appctlh 2 2992 1 0 0 1413 26585387100xA370CC78 3 appctlh 3 88 1 0 0 2547 14366388710xA370D1E8 3 appctlh 8 144 1 0 0 778 91986655 0xA370D298 3 appctlh 9 400 1 0 0 4284 2614547685
Example for all instance scope sets (DBMS, FCM, FMP):
db2pd -memb allPrinting all blocks in DBMS set.Address PoolID PoolName BlockID Size I P N LOC File0x30980048 74 fcm 4 16400 1 0 0 1224 29273123490x3091FFB8 74 fcm 2 393232 1 0 0 1009 29273123490x30914048 74 fcm 1 4112 1 0 0 818 12727980170x30915078 74 fcm 3 4112 1 0 0 1042 29273123490x309D6F88 11 monh 80 69699 1 0 0 772 38817331820x309C2F88 11 monh 79 69699 1 0 0 772 3881733182<snip>Printing all blocks in FCM set.Address PoolID PoolName BlockID Size I P N LOC File0x813C4048 79 fcmrqb 19 16400 1 0 0 2547 12727980170x813B8048 79 fcmrqb 18 47120 1 0 0 2375 12727980170x813AC048 79 fcmrqb 17 47120 1 0 0 2375 1272798017<snip>Printing all blocks in FMP set.Address PoolID PoolName BlockID Size I P N LOC File0x90009FA8 59 undefh 1 122916 1 0 0 357 4133190529
Example for all instance and database scope sets (DBMS, FCM, FMP, DB, AppCtl):
db2pd -memb all -db samplePrinting all blocks in DBMS set.Address PoolID PoolName BlockID Size I P N LOC File0x30980048 74 fcm 4 16400 1 0 0 1224 29273123490x3091FFB8 74 fcm 2 393232 1 0 0 1009 2927312349
0x30914048 74 fcm 1 4112 1 0 0 818 12727980170x30915078 74 fcm 3 4112 1 0 0 1042 29273123490x309D6F88 11 monh 80 69699 1 0 0 772 38817331820x309C2F88 11 monh 79 69699 1 0 0 772 38817331820x309BC048 11 monh 70 184 1 0 0 130 88219158<snip>Printing all blocks in FCM set.Address PoolID PoolName BlockID Size I P N LOC File0x813C4048 79 fcmrqb 19 16400 1 0 0 2547 12727980170x813B8048 79 fcmrqb 18 47120 1 0 0 2375 12727980170x813AC048 79 fcmrqb 17 47120 1 0 0 2375 1272798017<snip>Printing all blocks in FMP set.Address PoolID PoolName BlockID Size I P N LOC File0x90009FA8 59 undefh 1 122916 1 0 0 357 4133190529Printing all blocks in Appctl set id 566624315.Address PoolID PoolName BlockID Size I P N LOC File0xA370C048 3 appctlh 1 64 1 0 0 150 30327041230xA370C0A8 3 appctlh 2 2992 1 0 0 1413 2658538710<snip>Printing all blocks in Database SAMPLE set.Address PoolID PoolName BlockID Size I P N LOC File0x4093C048 5 utilh 1 64 1 0 0 150 30327041230x4093C0A8 5 utilh 2 232 1 0 0 194 17797663160x40940048 7 pckcacheh 2 408 1 0 0 1082 197035070x409401F8 7 pckcacheh 3 1060 1 0 0 2119 3048315900
Example for AppCtl sets (database required):
db2pd -db sample -memb appctlPrinting all blocks in Appctl set id 566624315.Address PoolID PoolName BlockID Size I P N LOC File0xA370C048 3 appctlh 1 64 1 0 0 150 30327041230xA370C0A8 3 appctlh 2 2992 1 0 0 1413 26585387100xA370CC78 3 appctlh 3 88 1 0 0 2547 14366388710xA370D1E8 3 appctlh 8 144 1 0 0 778 919866550xA370D298 3 appctlh 9 400 1 0 0 4284 2614547685<snip>Printing all blocks in Database SAMPLE set.Address PoolID PoolName BlockID Size I P N LOC File0x4093C048 5 utilh 1 64 1 0 0 150 30327041230x4093C0A8 5 utilh 2 232 1 0 0 194 17797663160x40940048 7 pckcacheh 2 408 1 0 0 1082 197035070x409401F8 7 pckcacheh 3 1060 1 0 0 2119 30483159000x40940738 7 pckcacheh 14 408 1 0 0 1082 19703507
Scenario 6: Producing a shared memory dump with db2pd -bindump .
Usage
-bindump [-db <database>] [-inst] DBMS, FCM, FMP sets dumped with -bindump. DBMS, DB, AppCtl sets dumped with -db <database>.
DBMS, FCM, FMP, DB, AppCtl sets dumped with -db <database> and -inst.
Example -bindump:
db2pd -bindSending -bindump output to /home/jmcmahon/db2pd.binDumping DBMS set starting at 0x30000000 with size 52690944Dumping FCM set starting at 0x80000000 with size 43270144Dumping FMP set starting at 0x90000000 with size 257654784
Example -bindump -db sample:
db2pd -bind -db sampleSending -bindump output to /home/jmcmahon/db2pd.binDumping DBMS set starting at 0x30000000 with size 52690944Dumping DB set for database SAMPLE starting at 0x40000000 with size 65716224Dumping AppCtl set starting at 0xa0000000 with size 192839680
Example -bindump -db sample -inst:
db2pd -bind -db sample -instSending -bindump output to /home/jmcmahon/db2pd.binDumping DBMS set starting at 0x30000000 with size 52690944Dumping DB set for database SAMPLE starting at 0x40000000 with size 65716224Dumping AppCtl set starting at 0xa0000000 with size 192839680Dumping FCM set starting at 0x80000000 with size 43270144Dumping FMP set starting at 0x90000000 with size 257654784
Scenario 7: Figuring out which application is using up your tablespace.
Using db2pd -tcbstats, the number of Inserts can be identified for a table. Here is temp table TEMP1.
(The UsablePgs vs. TotalPages is where they would notice the space filling)
Once this is known, you can identify the dynamic sql statement using a table called "TEMP1."
db2pd -db sample -dyn
Database Partition 0 -- Database SAMPLE -- Active -- Up 0 days 00:13:06
Dynamic Cache:Current Memory Used 1022197Total Heap Size 1271398Cache Overflow Flag 0Number of References 237Number of Statement Inserts 32Number of Statement Deletes 13Number of Variation Inserts 21Number of Statements 19
Scenario 8: Monitoring recovery. db2pd -recovery shows several counters to make sure recovery is progressing. Current Log and Current LSN provide the log position. CompletedWork counts the number of bytes completed thus far.
Recovery:Recovery Status 0x00000401Current Log S0000005.LOGCurrent LSN 000002551BEAJob Type ROLLFORWARD RECOVERYJob ID 7Job Start Time (1107380474) Wed Feb 2 16:41:14 2005Job Description Database Rollforward RecoveryInvoker Type UserTotal Phases 2Current Phase 1
Scenario 9: Understanding how much resource a transaction is using. db2pd -transactions provides the number of locks, first lsn, last lsn, logspace used, and space reserved. This can be useful for understanding the behavior of any transaction.
TID AxRegCnt GXID0x000000000451 1 00x0000000003E0 1 00x000000000472 1 0
Scenario 10: Monitoring log usage. db2pd -logs is useful to monitor log usage for a database. By watching the Pages Written output, you can determine whether the log usage is progressing.
For DB2 UDB, Version 8.2.2, db2pd -logs has some new information:
Logs:Current Log Number 2Pages Written 846Method 1 Archive Status SuccessMethod 1 Next Log to Archive 2Method 1 First Failure n/aMethod 2 Archive Status SuccessMethod 2 Next Log to Archive 2Method 2 First Failure n/a
1. If there is a problem with archiving, Archive Status will be set to Failure indicating the most recent log archive failed. Or if there is an ongoing archive failure preventing logs from archiving at all First Failure will be set.
2. If log archiving is proceeding very slowly, Next Log to Archive will be behind Current Log Number. This can cause the log path to fill up, which in turn, can prevent any data changes from occurring in the database when the log path is completely filled.
Scenario 11: Sysplex list. Without db2pd -sysplex, the only way to report the sysplex list is with db2trc.
IP Address Port Priority Connections Status PRDID 9.26.89.87 448 1 0 0
Scenario 12: Generating stack traces.
As of DB2 version 8.2, the "-stacks" attribute can be used to produce stack traces for DB2 processes on Unix and Linux platforms. As of DB2 version 8.2.2 (V8.1 FixPak 9), it can also be used to do the same for DB2 threads on Windows platforms. You might want to use this command iteratively when you suspect that a process or thread is looping or hanging.
If the current call stack for a particular DB2 process is desired, this can be accomplished by issuing "db2pd -stack <pid>", for example:
> db2pd -stack 1335470Attempting to dump stack trace for pid 1335470.See current DIAGPATH for trapfile.
If the call stacks for all of the DB2 processes are desired, use the command "db2pd -stacks", for example:
-stacks>db2pd -stacksAttempting to dump all stack traces for instance.See current DIAGPATH for trapfiles.
If you are using a multi-partitioned environment with multiple physical nodes, you can obtain the information from all of the partitions by using: db2_all "; db2pd -stacks". If the partitions are all logical partitions on the same machine, however, a faster method is to use "db2pd -alldbp -stacks".
Related reference db2pd - Monitor and troubleshoot DB2 Universal Database Command