Академический Документы
Профессиональный Документы
Культура Документы
com
1 de 4
Introduction
By Aleksey
Every application that utilizes a relational database can encounter situations where data is deadlocked
or unavailable. These situations need to be handled programmatically within your code. This article is
designed to introduce the concepts of retry logic related to database transaction locking and
unavailability. Furthermore, this article will explain how to avoid locking issues.
Shevchenko
Even though the concepts discussed in this article pertain to almost all transactional databases and client applications that
use them, do keep in mind that this article uses DB2 (version 9) and Java as points of reference.
Isolation Level
Phenomena
Lost Updates
Dirty Reads
Nonrepeatable Reads
Phantoms
Repeatable Read
No
No
No
No
Read Stability
No
No
No
Yes
Cursor Stability
No
No
Yes
Yes
Uncommitted Read
No
Yes
Yes
Yes
Table 1: DB2 Isolation Levels and the Phenomena That Can Occur When Each Is Used
Locking can be prevented in read-only mode, not ambiguous statements using the
Uncommitted Read Isolation Level.
An SQL statement is considered read-only when it uses any of the following:
1. JOIN
2. SELECT DISTINCT
3. GROUP BY
http://www.developer.com/db/article.php/3708511/Application-Handling...
Post a comment
Email Article
Print Article
Share Articles
15/02/2016 11:38
2 de 4
4. ORDER BY
5. UNION
6. UNION ALL
7. SELECT
8. FOR FETCH ONLY (FOR READ ONLY)
9. SELECT FROM
Your SQL statement is said to be ambiguous if it does include any of the above statements, Therefore, the lock might contain
issues against the resource involved in the statement.
Here are four more recommendations for reducing the number of locks:
1. Set CURRENTDATA to NO. This command tells DB2 that the ambiguous cursor is read-only.
2. Use User Uncommitted Read as much as possible (if appropriate).
3. Close all cursors as soon as possible.
4. Have a correct commit strategy. Make sure your application releases resources as soon as it is deemed appropriate.
http://www.developer.com/db/article.php/3708511/Application-Handling...
15/02/2016 11:38
3 de 4
Conclusion
In this article, you have learned how to minimize the occurrence of locks and how to handle situations in your code when
your database returns error codes that constitute deadlocks and timeouts.
References
IBM DB2 Version 9 for Linux, UNIX, and Windows Performance Guide.
www.ittia.com/dbstar/manual/UG_Gloss.htm
http://www.developer.com/db/article.php/3708511/Application-Handling...
15/02/2016 11:38
http://www.developer.com/db/article.php/3708511/Application-Handling...
4 de 4
15/02/2016 11:38