01.09.2016 Views

Beginning Oracle Database 11g Administration From Novice to Professional

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

244<br />

CHAPTER 11 FIXING PROBLEMS<br />

ORA-00060: Deadlock Detected<br />

Once again, we see only a minimal explanation in <strong>Oracle</strong> <strong>Database</strong> <strong>11g</strong> Error Messages:<br />

<br />

<br />

<br />

<br />

This error is frequently encountered but is one of the least unders<strong>to</strong>od <strong>Oracle</strong> errors.<br />

A deadlock is a situation in which two transactions interfere with each other; each is waiting<br />

for a lock on a resource locked by the other. The correct thing for the application <strong>to</strong> do<br />

when this error is received is <strong>to</strong> issue the command and retry the transaction.<br />

Create two tables, and , related <strong>to</strong> each other by a referential constraint<br />

(foreign key), and populate them with data by using the following commands:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Suppose that two users try <strong>to</strong> delete the data from the table, but each deletes<br />

records in a different order. At step 3 in the following example, user A will be blocked<br />

because user B has already locked the requested record. User B will be blocked in turn at<br />

step 4, and a deadlock results. To resolve the deadlock, <strong>Oracle</strong> picks either user A or user<br />

B as a victim, and any effects of the last command issued by the victim are rolled back.<br />

To allow the other user <strong>to</strong> proceed, the victim must then issue the command <strong>to</strong><br />

release any other locks it still holds—it can then retry its transaction:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!