what is a deadlock in oracle?

what is a deadlock in oracle, how this occurs and how it can be solved?
sakthikumarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MrNedCommented:
A deadlock is when two processes are each waiting for the other to release a lock on an object before they will proceed. e.g.

Session A = lock table A
Session B = lock table B
Session A = try to lock table B, need to wait
Session B = try to lock table A, need to wait
*Deadlock!*

Oracle will automatically detect these and kill one of the sessions. A warning will be written to the alert log to indicate what happened.
0
PilouteCommented:
Hi sathikumar

Just for the sake of clarity :

1) not only a table can be locked in oracle. The deadlocks can occur on several type of resources... For example on rows into the same table :

- user A delete row 1 without commiting
- user B delets row 2 without commiting
- user A wants to delete row 2 (still available because lack of commit from A)
- user B wants to delete row 1 (still available because lack of commit from B)
=> deadlock

2) deadlocks occur because of poor application development. They are not a database problem. The database does exactly what it is supposed to do (it works perfectly). So :
- no need to 'solve' anything (unless give some training to your developers/users)
- oracle will rollback one of the sessions (like the user would have done 'rollback' command). Unfortunately you can not predict which session will be rolled back.

Cheers,
P
0
ajexpertCommented:
Ok, you can simulate the deadlock like this.

1.
Create table TABLEA
(col1 number(10),
 col2 varchar2(100));

2.
Insert 10 rows in above table.

3.
Login to TOAD or any tool and execute the follwing
update tableA
set col2 = 'NEWVALUE';

4. Login to command prompt or SQLPLUS and execute the following
update tableA
set col2 = 'NEWVALUE2';

Do not COMMIT either in step3 or step4

Check if you can simulate the deadlock situation

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jaiminpsoniCommented:
In addition to what is said above, following blog will help. (This is about SQL Server, but concepts hold true for Oracle as well)

http://blogs.msdn.com/b/bartd/archive/tags/sql+deadlocks/default.aspx
0
PilouteCommented:
@jaiminpsoni

SQL Server is not Oracle. Why not reading directly the docs for oracle ?

http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/consist.htm#sthref2043

P
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.