7

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?

3

List the current database activities:

db2top -d [dbname]

This command will show you database locks:

db2pd -d [dbname] -lock wait 
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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