----Handle Deadlock processes
--View locked tables
Select B.owner,b.object_name,a.session_id,a.locked_mode
From V$locked_object a,dba_objects b
where b.object_id = a.object_id;
--View the user who locked the table
Select B.username,b.sid,b.serial#,logon_time
From V$locked_object a,v$session b
where a.session_id = B.sid order by B.logon_time;
--Handling lock process
Alter system kill session ' sid,serial# ';
--if there is a ora-00031 error, add immediate in the back
Alter system kill session ' sid,serial# ' immediate;
Select Username,lockwait,status,machine,program from v$session where SID in
(select session_id from V$locked_object)
-If there is a result of the output, it indicates which machine is deadlocked and which one can see the deadlock. Field Description:
--Username: The database user used by the deadlock statement;
--Lockwait: The state of the deadlock if there is a content representation being deadlocked.
-Status: State, active indicates deadlock
Machines: The machine where the deadlock statement resides.
Program: The main application from which to generate the deadlock statement.
--2) You can view the deadlock statement by executing the following statement with the DBA user.
Select Sql_text from V$sql where Hash_value in
(select Sql_hash_value from v$session where SID in
(select session_id from V$locked_object))
Oracle Lock Processing Scripts