Deadlocks for 200 - Database Specialists

Deadlocks For $1000:
Let’s Play Jeopardy!
Iggy Fernandez
Database Specialists, Inc.
www.dbspecialists.com
TCOUG Fall Meeting 2008
Speaker Qualifications
 Oracle DBA at Database Specialists
 Editor of the Journal of the Northern California Oracle
Users Group
 Author of Beginning Oracle Database 11g
Administration
2
Deadlock example—Overlapping data
 Transaction A: Delete from child where
child_ID=1;
 Transaction B: Delete from child where
child_ID=2;
 Transaction A: Delete from child where
child_ID=2;
 Transaction A: Delete from child where
child_ID=1;
3
Deadlock example—
non-overlapping data!
 Transaction A: Delete from child where
child_ID=1;
 Transaction B: Delete from child where
child_ID=2;
 Transaction A: Delete from parent where
parent_ID=1;
 Transaction B: Delete from parent where
parent_ID=2;
4
Further Reading
 Understanding and Interpreting Deadlocks or
What to Do When You Encounter ORA-00060
by Mark Bobak. Available for download at the
Oak Table website
www.oaktable.net/userFiles.jsp
 Metalink document 164661.1: ORA60/Deadlocks Most Common Causes
 Metalink document 62365.1: What to do with
“ORA-60 Deadlock Detected” Errors.
5
Deadlocks for 100
Which of the following situations is an example of an
Oracle deadlock? Pick all that apply.
1. A situation in which a blocking session becomes
inactive but does not release its locks.
2. A situation in which a blocking session is itself
blocked by another session.
3. A situation in which two sessions are trying to modify
a row of data that has previously been modified by the
other.
4. A cycle in the “wait-for” diagram.
5. A situation in which a session is blocking itself, i.e.,
“self-deadlock.”
6
Deadlocks for 200
What kind of situation cannot result in an Oracle
deadlock? Pick all that apply.
1. A situation involving a single table, because
deadlocks cannot occur if everybody is modifying the
same table.
2. A situation involving a single user, because sessions
owned by the same user cannot deadlock with each
other.
3. A situation involving a single session, because a
session cannot deadlock with itself.
4. A situation not involving any locking activity
whatsoever.
7
Deadlocks for 300
Who receives the “ORA-00060: deadlock
detected while waiting for resource” error
message?
1. The participant that is blocking the others.
2. Only one of the participants in the deadlock,
selected by Oracle.
3. All the participants in the deadlock.
8
Deadlocks for 400
What is the effect on any session that receives
the “ORA-00060: deadlock detected while
waiting for resource” error message?
1. The statement that it was executing is rolled
back.
2. Its transaction is rolled back.
3. It is terminated.
4. It depends on the circumstances.
9
Deadlocks for 500 (Daily Double)
What action must the database administrator take
to resolve the deadlock?
1. Terminate the session that is blocking the
others.
2. Terminate any one of the sessions
participating in the deadlock.
3. Terminate all the sessions participating in the
deadlock.
4. None of the above.
10
Deadlocks for 600
What is the recommended action that a session should
take when it receives an ORA-00060 error message?
1. Issue the ROLLBACK TO SAVEPOINT command and
repeat the statement that it was executing when it
received the ORA-00060 error message.
2. Repeat its entire transaction; there is no need to issue
an explicit ROLLBACK command because Oracle has
already rolled back the entire transaction.
3. Repeat the entire transaction; the session must first
issue an explicit ROLLBACK command because
Oracle has not rolled back the transaction.
11
Deadlocks for 700
What causes a deadlock in Oracle? Pick all that
apply.
1. Contention for the same rows of data by
multiple sessions.
2. Physical database design issues such as
unindexed foreign keys.
3. Architectural issues such as block-level
locking.
12
Deadlocks for 800
How does Oracle detect that a deadlock has
occurred?
1. It checks for deadlocks whenever a session
cannot acquire a lock.
2. It checks for deadlocks at regular intervals.
3. It checks for deadlocks whenever the wait
time of a session has exceeded a certain
threshold.
4. It checks for deadlocks whenever the number
of waiting sessions has exceeded a certain
threshold.
13
Deadlocks for 900
How can you obtain a list of all the rows locked
by a transaction? Pick all that apply.
1. By querying V$LOCK in order to identify the
locked rows.
2. By querying V$LOCKED_OBJECT in order to
identify the locked rows.
3. By querying DBA_LOCK in order to identify
the locked rows.
4. None of the above.
14
Deadlocks for 1000!
A transaction issues a SAVEPOINT command and then
locks a data row that is subsequently required by
another transaction. What happens if the blocking
transaction issues a ROLLBACK TO SAVEPOINT
command?
1. The blocking transaction reverses the changes made
to the data row but does not release its lock on the
row.
2. The blocking transaction reverses the changes made
to the data row and releases its lock on the row; the
blocked transaction is automatically unblocked.
3. The blocking transaction reverses the changes made
to the data row and releases its lock on the row, but
the blocked transaction remains blocked.
15
White Paper
 Contains all of the material we discussed today
and more
 Code samples are easier to read
 Easier to cut and paste the code for testing on your
system
 Download:
www.dbspecialists.com/presentations
16
Contact Information
Iggy Fernandez
Database Specialists, Inc.
388 Market Street, Suite 400
San Francisco, CA 94111
Tel: 415-344-0500 Ext. 43
Email: [email protected]
Web: www.dbspecialists.com
17
There’s No Substitute For Experience
 Proven track record with emerging to Fortune
500 clients since 1995.
 Services and support plans tailored to your
business needs and budget.
 Team of recognized industry experts and
thought leaders.
Database Specialists helps you
increase uptime, improve performance,
minimize risk, and reduce costs
18
About Database Specialists
 Database Specialists, Inc. provides Oracle database
consulting in Solaris, Linux, HP-UX, AIX, and Windows
environments.
 Our DBA Pro offering and Database Rx™ tools provide remote
database support and 24/7 coverage at an attractive price
point.
 We specialize in short term projects including upgrades,
performance tuning and health checks.
 Our Oracle DBAs each have a minimum of 10 years of Oracle
experience with a focus on Oracle technology, mission-critical
production support and RAC environments.
 Database Specialists is US-based.
Database Specialists helps you
increase uptime, improve performance,
minimize risk, and reduce costs
19
Deadlocks For $1000:
Let’s Play Jeopardy!
Iggy Fernandez
Database Specialists, Inc.
www.dbspecialists.com
TCOUG Fall Meeting 2008