Recovery from Deadlock in Database:
How can we recover from deadlock? / Rollback in deadlock / Guidelines to choose deadlock victim
Recovery from deadlock can be done in three steps;
Guidelines to choose victim:
- The length of the transaction – We need to choose the transaction which is younger.
- The data items used by the transaction – The transactions that are used less number of data items.
- The data items that are to be locked – The transaction that needs to lock many more data items compared to that are already locked.
- How many transactions to be rolled back? – We need to choose transaction or transactions that would cause less number of other transactions to be rolled back (cascading rollback)
2. Rollback: Once we have identified the transaction or transactions that are to be rolled back, then rollback them. This can be done in two ways;