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?
List the current database activities:
This command will show you database locks:
db2pd as explained in this same post is a very good option.
Add to that, you can use the procedure:
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 ).
if you want to check the locks snapshot, that is also possible:
Last but not least important, db2top is a great tool to monitor the locks, lockwaits, etc, and do it "live":
if needed, options "U,L"
Hope it helps. Rodrigo Trombeta