Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know how to check the DB is in a lock state or not, but my question is how to find out which query caused the lock on table /db.

IS there any log file getting created if something unexpected happens to the database?

share|improve this question
up vote 1 down vote accepted

List the current database activities:

db2top -d [dbname]

This command will show you database locks:

db2pd -d [dbname] -lock wait 
share|improve this answer

db2pd as explained in this same post is a very good option.

Add to that, you can use the procedure:

db2 "call monreport.lockwait()"

This procedure is going to show you in a very organized way the locks currently existing in your database.

After check the application id that holds the locks, try to identify the SQL Statement that is causing the lock. If not present, try to take the snapshot for all the applications, search for the application id and check the query being executed ( and any extra info you may need ).

db2 get snapshot for applications on (DATABASE_NAME) > applications_snapshot.txt

if you want to check the locks snapshot, that is also possible:

db2 get snapshot for locks on (DATABASE_NAME) > locks_snapshot.txt

Last but not least important, db2top is a great tool to monitor the locks, lockwaits, etc, and do it "live":

db2top -d (database_name)

option "U"

if needed, options "U,L"

Hope it helps. Rodrigo Trombeta

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.