Upload
prakash6849
View
243
Download
0
Embed Size (px)
Citation preview
7/27/2019 Lock Monitors for DB2 UDB
1/6
IBM Global Services
Document Information
Name Date
Prepared By Sambaraju Kiran Kumar
Reviewed/Updated by Rajesh Chandramohan
Tested the actions inthe document by
Sambaraju Kiran Kumar
Approved By
7/27/2019 Lock Monitors for DB2 UDB
2/6
Lock Monitors for DB2 UDB Database
1. Purpose
The purpose of this document is to describe the process to capture locksinformation for any DB2 UDB database.
2. Scope
DB2 UDB is product from IBM and is used to manager relationaldatabase. To keep the database up to mark with all other databases, byproviding monitors to capture locks information which in turn will be usedfor analyzing the applications design so that the DB2 database will not getstruck with locks.
3. Introduction / Overview
Diagnosing and correcting lock contention situations in large DB2environments can be complex and time consuming. This lock eventmonitor along with other facilities, are designed to simplify this task bycollecting locking data.
The lock event monitor is used to capture descriptive information aboutlock events at the time that they occur. The information captured identifiesthe key applications involved in the lock contention that resulted in thelock event. Information is captured for both the lock requestor(applications that received the deadlock or lock timeout error, or waited
for a lock for more than the specified amount of time) and the current lockowner.
The information collected by the lock event monitor is written in binaryformat to an unformatted event table in the database. The captured datais processed in a post-capture step improving the efficiency of the captureprocess.
4. Pre check list
Before creating the lock monitors, perform the following steps:
The deprecated detailed deadlock event monitor,DB2DETAILDEADLOCK, is created by default for each database andstarts when the database is activated.
The DB2DETAILDEADLOCK event monitor must be disabled andremoved; otherwise both the deprecated and new event monitors will becollecting data and will significantly affect performance.
7/27/2019 Lock Monitors for DB2 UDB
3/6
To remove the DB2DETAILDEADLOCK event monitor, issue thefollowing SQL statements:
SET EVENT MONITOR DB2DETAILDEADLOCK state 0
DROP EVENT MONITOR DB2DETAILDEADLOCK
5. Detailed Procedure
Two steps are required to capture lock event data using the locking eventmonitor:
1. You must create a LOCK EVENT monitor using the CREATE EVENTMONITOR FOR LOCKING statement. You provide a name for themonitor and the name of an unformatted event table into which the lockevent data will be written.
Below mentioned SQL creates a lock event monitor namedLOCKEVMON
CREATE EVENT MONITOR LOCKEVMON FOR LOCKING WRITE TOUNFORMATTED EVENT TABLE
Note: The lock event monitor replaces the deprecated deadlock eventmonitors (CREATE EVENT MONITOR FOR DEADLOCKS statement andDB2DETAILDEADLOCK) and the deprecated lock timeout reportingfeature (DB2_CAPTURE_LOCKTIMEOUT registry variable) with asimplified and consistent interface for gathering locking event data, andadds the ability to capture data on lock waits.
The information collected by the lock event monitor (which is createdabove) is written in binary format to an unformatted event table in thedatabase. After a locking event has occurred, the binary data in theunformatted event table can be transformed into an XML or a textdocument using a supplied Java-based application called db2evmonfmt.In addition, you can format the binary event data in the unformatted eventtable BLOB column into either an XML report document, using theEVMON_FORMAT_UE_TO_XML table function, or into a relational table,using the EVMON_FORMAT_UE_TO_TABLES procedure.
Some of the information for lock events collected by the lock eventmonitor includes the following:
1. The lock that resulted in an event2. The application holding the lock that resulted in the lock event3. The applications that were waiting for or requesting the lock that resultin the lock event4. What the applications were doing during the lock event
7/27/2019 Lock Monitors for DB2 UDB
4/6
2. Configure and use db2evmonfmt tool for reading event monitor data
The Java-based, generic XML parser tool, db2evmonfmt, produces areadable flat-text output (text version) or a formatted XML output from thedata generated by an event monitor that uses the unformatted event table.Based on the parameters that you specify, the db2evmonfmt tool determines
how to parse the event monitor data and the type of output to create.
The db2evmonfmt tool is provided as Java source code. You must setup andcompile this tool, before you can use it, by performing the following steps:a. Locate the source code in the sqllib/samples/java/jdbc directory andcompile itb. Before compiling the Java source code, copy the two files(db2evmonfmt.java + DB2EvmonLocking.xsl) to your current workingdirectoryc. Compile the copied java file using the below command
javac db2evmonfmt.java
Notes: A JDK (Java Development Kit) is required to compile thedb2evmonfmt utility. Because a JDK is installed with each DB2 serverproduct, you can use the Java compiler (javac) of the DB2 installation.
d. After the succesful compilation, a new class file named db2evmonfmt.classwill be created and is ready for use. The generated class (which is treated asthe db2evmonfmt tool) file reads the unformatted lock events' data andgenerates the output in a readable format based on the parameters providedwhile using running the toole. To read the locks events' data use the below command. By default, theoutput of the utility is written to standard out, so redirect its output into a textfile.
java db2evmonfmt -d sample -ue emdata.tab_locking -ftext -u username-p password > locktimeout.txt
where the code options are as follows:-d
Database name-ue
Fully qualified path (including the schema) of the unformatted event table-ftext
Output of lock-event information in plain text format (or, output can be inXML format by specifying the option -fxml)
-u User ID for database access-p
Password for database access
Note: The db2evmonfmt utility is a Java-based tool which must be precededby the java keyword in order to run successfully. The Java version required isthat which is installed with the DB2 product from the sqllib/java/jdk64directory.
7/27/2019 Lock Monitors for DB2 UDB
5/6
6. Post Check list
After performing the above steps, to check the lock event's state, try executingthe below mentioned commands.These commands provide information as explained in the examples mentioned
below.
Example 1
To obtain a formatted text output for all events that have occurred in the last 32hours from the package cache unformatted event table PKG in databaseSAMPLE, issue the following command:
java db2evmonfmt -d sample -ue pkg -ftext -hours 32
Example 2
To obtain a formatted text output for all events of type LOCKTIMEOUT that have
occurred in the last 24 hours from unformatted event table LOCK in databaseSAMPLE, issue the following command:java db2evmonfmt -d sample -ue LOCK -ftext -hours 24 type locktimeout
Example 3
To obtain a formatted text output from the XML source file LOCK.XML, extractingall events that match the event type LOCKWAIT in the last 5 hours, issue thefollowing command:
java db2evmonfmt -f lock.xml -ftext -type lockwait -hours 5
Example 4
To obtain a formatted text output using the created XSLT style sheetSUMMARY.XSL for all events in the unformatted event table UOW in databaseSAMPLE, issue the following command:
java db2evmonfmt -d sample -ue uow -ftext -ss summary.xsl
Also have to make a note of the below mentioned limitations in using the lockevent monitor.
1. There is no automatic purging of the lock event data written to the unformattedevent table. You must periodically purge data from the table.2. You can output the collected event monitor data to only the unformatted eventtable. Outputs to file, pipe, and table are not supported.
3. It is suggested that you create only one locking event monitor per database.Each additional event monitor only creates a copy of the same data.
7/27/2019 Lock Monitors for DB2 UDB
6/6
7. FAQ
Use the below provided urls to find more details about the Lock eventmonitors on DB2
http://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=
%2Fcom.ibm.db2.luw.admin.mon.doc%2Fdoc%2Fc0054136.html
http://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.sql.ref.doc%2Fdoc%2Fr0054074.html
http://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.admin.mon.doc%2Fdoc%2Fc0053977.html
http://www.ibm.com/developerworks/data/library/techarticle/dm-1004lockeventmonitor/
8. Step by Step
No Steps Yes/No
Step-1 Install the DB2 UDB which has Lock monitor feature.
Step-2Create the Lock event monitor event to capture locksrelated data to be collected in the db2 tables
Step-3
Create and configure the db2evmonfmt tool to read the
unformatted data collected by the lock event monitors.It can be done by compiling the db2evmonfmt java file.
Step-4
Execute the db2evmonfmt tool by using the javacommands on the db2evmonfmt class file which iscreated by compiling the db2evmonfmt java file
Step-5Collect the generated output data which is in readableformat and use it for analysis.
http://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.admin.mon.doc%2Fdoc%2Fc0054136.htmlhttp://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.admin.mon.doc%2Fdoc%2Fc0054136.htmlhttp://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.sql.ref.doc%2Fdoc%2Fr0054074.htmlhttp://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.sql.ref.doc%2Fdoc%2Fr0054074.htmlhttp://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.admin.mon.doc%2Fdoc%2Fc0053977.htmlhttp://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.admin.mon.doc%2Fdoc%2Fc0053977.htmlhttp://www.ibm.com/developerworks/data/library/techarticle/dm-1004lockeventmonitor/http://www.ibm.com/developerworks/data/library/techarticle/dm-1004lockeventmonitor/http://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.admin.mon.doc%2Fdoc%2Fc0054136.htmlhttp://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.admin.mon.doc%2Fdoc%2Fc0054136.htmlhttp://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.sql.ref.doc%2Fdoc%2Fr0054074.htmlhttp://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.sql.ref.doc%2Fdoc%2Fr0054074.htmlhttp://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.admin.mon.doc%2Fdoc%2Fc0053977.htmlhttp://pic.dhe.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.admin.mon.doc%2Fdoc%2Fc0053977.htmlhttp://www.ibm.com/developerworks/data/library/techarticle/dm-1004lockeventmonitor/http://www.ibm.com/developerworks/data/library/techarticle/dm-1004lockeventmonitor/