HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to find out what caused the database(DB2) in a locking state

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
thehowwhatdb2databaselockingstatefindcausedout

Problem

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?

Solution

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

Code Snippets

db2 "call monreport.lockwait()"
db2 get snapshot for applications on (DATABASE_NAME) > applications_snapshot.txt
db2 get snapshot for locks on (DATABASE_NAME) > locks_snapshot.txt
db2top -d (database_name)

Context

StackExchange Database Administrators Q#8361, answer score: 2

Revisions (0)

No revisions yet.