In a DB2 database, what is meant by a deadlock between transactions?

Difficulty: Easy

Correct Answer: A situation in which two or more transactions are each waiting for locks held by the other, so none of them can proceed

Explanation:


Introduction / Context:
Deadlocks are classic concurrency problems in relational databases such as DB2, Oracle, and SQL Server. They occur when transactions hold locks on resources and wait in a circular dependency. This question checks whether you can correctly describe what a deadlock is in DB2, which is an important concept for database administration and application performance tuning.


Given Data / Assumptions:

  • The database system is DB2, but the concept is similar across relational databases.
  • Multiple transactions are executing concurrently.
  • Locks are used to protect rows, pages, or tables from conflicting updates.
  • The question asks for the meaning of a deadlock, not how to resolve it.


Concept / Approach:
A deadlock occurs when two or more transactions each hold a lock on some resource and then request another resource that is locked by the other transaction. Each transaction waits for a lock that will never be released because the other transaction is also waiting. This circular wait means that none of the transactions involved can make further progress. The database detects this situation and typically rolls back one of the transactions to break the deadlock. Therefore, the correct answer must describe mutual waiting for locks in a circular dependency, not simple network failures or backups.


Step-by-Step Solution:
1. Recall that DB2 uses locks to control concurrent access and maintain data consistency. 2. Understand that a transaction may hold a lock on one row and request another lock on a different row or table. 3. Imagine two transactions: Transaction A holds Resource 1 and wants Resource 2, while Transaction B holds Resource 2 and wants Resource 1. 4. In this scenario, each transaction waits indefinitely because neither can release its current lock without acquiring the other. 5. Recognize that this condition is called a deadlock and match it with the option that describes mutual waiting for locks.


Verification / Alternative check:
You can verify by recalling how DB2 handles deadlocks: the database periodically checks for cycles in the lock graph. When a deadlock is detected, DB2 chooses a victim transaction to roll back, freeing its locks so that the other transaction can proceed. This behavior would not be necessary for simple network issues or scheduled backups, which further confirms that mutual lock waiting is the defining feature of a deadlock.


Why Other Options Are Wrong:

  • Option B is wrong because a network connectivity loss is a communication problem, not a logical locking cycle within the database.
  • Option C is wrong because scheduled backups may affect performance or concurrency, but they are not defined as deadlocks.
  • Option D is wrong because a deadlock requires a cycle; a transaction that simply holds locks and completes successfully while others wait is not necessarily part of a deadlock.


Common Pitfalls:
One pitfall is confusing deadlocks with general lock waits or timeouts. A lock timeout occurs when a transaction waits too long for a lock, but a deadlock specifically involves circular waiting. Another common mistake is assuming that deadlocks are always due to hardware issues rather than poorly ordered locking strategies in the application. Understanding this difference helps developers design transactions that acquire locks in a consistent order to reduce the risk of deadlocks.


Final Answer:
The correct answer is A situation in which two or more transactions are each waiting for locks held by the other, so none of them can proceed, because this describes the classic circular wait condition that defines a deadlock in DB2 and other relational databases.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion