View previous topic :: View next topic |
Author |
Message |
Hema_Manyam Beginner
Joined: 15 Dec 2005 Posts: 20 Topics: 9
|
Posted: Thu Dec 29, 2005 3:53 am Post subject: DB2 - delay |
|
|
Hi,
Is there a delay command in DB2 ?
Suppose if I have batch DB2 pgm, and if I encounter deadlock then I want to delay for 3 min and then again perform the same statement to avoid deadlock. How is it possible to delay in db2 ?
Thanks
Hema |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
Manas Biswal Intermediate

Joined: 29 Nov 2002 Posts: 382 Topics: 27 Location: Chennai, India
|
Posted: Thu Dec 29, 2005 10:11 am Post subject: |
|
|
Hema_Manyam,
There are a lot of different scenarios that you need to consider when handling deadlocks in DB2. Most of the time, you really have no control over deadlocks, and DB2 will automatically rollback one of the transactions involved in a deadlock.
DB2 deadlocks should be avoided and you can do various things both at an application level and at the database configuration level to minimise deadlocks. But as far as "handling" deadlocks is concerned, DB2 does most of the work and the application has limited control over it.
When DB2 detects a deadlock, two scenarios can potentially happen to your application -
1. DB2 attempts to rollback the SQL and the UOW of the current application. If the rollback is successful, then the application abends with a SQLCODE of -911. You have to redo the transaction or the job again. You cannot retry the SQL within the same transaction or job.
2. If the attempt to rollback fails, then DB2 throws the -913 SQL exception, which you can capture from within your application and retry the transaction (after the delay that you mentioned).
Again, the above two scenrios depend on the interfacing application. The behavior id different for TSO BATCH, DLI Batch, IMS and CICS applications accessing DB2.
Sometimes, your application can control and resume/retry after a deadlock and sometimes it can't. I would suggest that you go through the DB2 for Z/OS manual before coding for deadlocks.
You can use the below as a starting point -
http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db2.doc.apsg/bjnqmstr283.htm
HTH....Regards,
Manas _________________ There is no path to peace. Peace is the path.
- Mahatma Gandhi (1869-1948) |
|
Back to top |
|
 |
a_seshu Beginner

Joined: 30 Sep 2004 Posts: 16 Topics: 4 Location: Chennai
|
Posted: Fri Dec 30, 2005 12:40 pm Post subject: |
|
|
Hema_Manyam
Think this way.....
Your program encountered a deadlock at a particular point... You end up getting an sql code of -911 or -913. All the work done in your program in that LUW (Logical Unit of Work) would have been rolled back by then. Now do you think there is any advantage doing a delay and reattempting the same operation???
Take this example
You have a sequence of three updates to perform a process for an update.
Code: | Update Table1
Update Table2
Update Table3 |
Now Update Table1 and Update Table2 completed successfully. Now for updating Table3 u had a deadlock. Now when the control returns back to the program from DB2, you will end up with an SQL Code of -911/-913 and remember DB2 rolled back the updates for Table1 and Table2. Now even if you delay and update Table3, you have lost the updates for Table1 and Table2.
If you dont have any updates/inserts/deletes (write operations to DB2) in a LUW, you can proceed with your approach but if you have any thing like that, the delay logic wont work.
In those cases, I would suggest abend the program at that point and restart from the abending record. _________________ I dont think I would ever stop learning. - Seshu. |
|
Back to top |
|
 |
Hema_Manyam Beginner
Joined: 15 Dec 2005 Posts: 20 Topics: 9
|
Posted: Sat Dec 31, 2005 12:52 am Post subject: |
|
|
Thanks Manas & a_seshu. I realise, I am out of my mind when I am posting this question. Here is the reason why it happened.
Currently I am also working in IDMS, here when deadlock happens we close all files, rebind the areas and then use delay command to try again. Hence I was thinking in that mode and have raised this query. Later I realised that it is not possible to do db2 bind inside the program similar to IDMS.
Thanks guys for your detailed explanation.
Regards,
Hema. |
|
Back to top |
|
 |
|
|