Sei sulla pagina 1di 6

IBM Global Services

Document Information
Prepared By Reviewed/Updated by Tested the actions in the document by Approved By Name Sambaraju Kiran Kumar Rajesh Chandramohan Sambaraju Kiran Kumar Date

Lock Monitors for DB2 UDB Database


1. Purpose
The purpose of this document is to describe the process to capture locks information for any DB2 UDB database.

2. Scope
DB2 UDB is product from IBM and is used to manager relational database. To keep the database up to mark with all other databases, by providing monitors to capture locks information which in turn will be used for analyzing the applications design so that the DB2 database will not get struck with locks.

3. Introduction / Overview
Diagnosing and correcting lock contention situations in large DB2 environments can be complex and time consuming. This lock event monitor along with other facilities, are designed to simplify this task by collecting locking data. The lock event monitor is used to capture descriptive information about lock events at the time that they occur. The information captured identifies the key applications involved in the lock contention that resulted in the lock 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 lock owner. The information collected by the lock event monitor is written in binary format to an unformatted event table in the database. The captured data is processed in a post-capture step improving the efficiency of the capture process.

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 and starts when the database is activated. The DB2DETAILDEADLOCK event monitor must be disabled and removed; otherwise both the deprecated and new event monitors will be collecting data and will significantly affect performance.

To remove the DB2DETAILDEADLOCK event monitor, issue the following 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 event monitor: 1. You must create a LOCK EVENT monitor using the CREATE EVENT MONITOR FOR LOCKING statement. You provide a name for the monitor and the name of an unformatted event table into which the lock event data will be written. Below mentioned SQL creates a lock event monitor named LOCKEVMON CREATE EVENT MONITOR LOCKEVMON FOR LOCKING WRITE TO UNFORMATTED EVENT TABLE Note: The lock event monitor replaces the deprecated deadlock event monitors (CREATE EVENT MONITOR FOR DEADLOCKS statement and DB2DETAILDEADLOCK) and the deprecated lock timeout reporting feature (DB2_CAPTURE_LOCKTIMEOUT registry variable) with a simplified and consistent interface for gathering locking event data, and adds the ability to capture data on lock waits. The information collected by the lock event monitor (which is created above) is written in binary format to an unformatted event table in the database. After a locking event has occurred, the binary data in the unformatted event table can be transformed into an XML or a text document using a supplied Java-based application called db2evmonfmt. In addition, you can format the binary event data in the unformatted event table BLOB column into either an XML report document, using the EVMON_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 event monitor includes the following: 1. The lock that resulted in an event 2. The application holding the lock that resulted in the lock event 3. The applications that were waiting for or requesting the lock that result in the lock event 4. What the applications were doing during the lock event

2. Configure and use db2evmonfmt tool for reading event monitor data The Java-based, generic XML parser tool, db2evmonfmt, produces a readable flat-text output (text version) or a formatted XML output from the data 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 and compile this tool, before you can use it, by performing the following steps: a. Locate the source code in the sqllib/samples/java/jdbc directory and compile it b. Before compiling the Java source code, copy the two files (db2evmonfmt.java + DB2EvmonLocking.xsl) to your current working directory c. Compile the copied java file using the below command javac db2evmonfmt.java Notes: A JDK (Java Development Kit) is required to compile the db2evmonfmt utility. Because a JDK is installed with each DB2 server product, you can use the Java compiler (javac) of the DB2 installation. d. After the succesful compilation, a new class file named db2evmonfmt.class will be created and is ready for use. The generated class (which is treated as the db2evmonfmt tool) file reads the unformatted lock events' data and generates the output in a readable format based on the parameters provided while using running the tool e. To read the locks events' data use the below command. By default, the output of the utility is written to standard out, so redirect its output into a text file. 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 in XML 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 preceded by the java keyword in order to run successfully. The Java version required is that which is installed with the DB2 product from the sqllib/java/jdk64 directory.

6. Post Check list


After performing the above steps, to check the lock event's state, try executing the 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 32 hours from the package cache unformatted event table PKG in database SAMPLE, 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 database SAMPLE, 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, extracting all events that match the event type LOCKWAIT in the last 5 hours, issue the following command: java db2evmonfmt -f lock.xml -ftext -type lockwait -hours 5 Example 4 To obtain a formatted text output using the created XSLT style sheet SUMMARY.XSL for all events in the unformatted event table UOW in database SAMPLE, 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 lock event monitor. 1. There is no automatic purging of the lock event data written to the unformatted event table. You must periodically purge data from the table. 2. You can output the collected event monitor data to only the unformatted event table. 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. FAQ
Use the below provided urls to find more details about the Lock event monitors 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/dm1004lockeventmonitor/

8. Step by Step
No Step-1 Step-2 Steps Install the DB2 UDB which has Lock monitor feature. Create the Lock event monitor event to capture locks related data to be collected in the db2 tables 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. Execute the db2evmonfmt tool by using the java commands on the db2evmonfmt class file which is created by compiling the db2evmonfmt java file Collect the generated output data which is in readable format and use it for analysis. Yes/No

Step-3

Step-4 Step-5

Potrebbero piacerti anche