what is a deadlock in oracle?

what is a deadlock in oracle, how this occurs and how it can be solved?
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.

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

Oracle will automatically detect these and kill one of the sessions. A warning will be written to the alert log to indicate what happened.
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.

Ok, you can simulate the deadlock like this.

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

Insert 10 rows in above table.

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

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
In addition to what is said above, following blog will help. (This is about SQL Server, but concepts hold true for Oracle as well)


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


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.