Oracle deadlock query and processing

1. The phenomenon of database deadlock
During the execution of the program, click the OK or Save button, the program does not respond, and no error occurs.
Second, the principle of deadlock
When an operation such as updating or deleting a column of a table in the database is performed, the statement will not be mentioned after the execution is completed.
Post, another statement that updates this column of data will be in a waiting state when it is executed.
The phenomenon at this time is that this statement has been executed, but it has not been executed successfully, and no error has been reported.
Three, deadlock positioning method
By checking the database table, you can check which statement is deadlocked and which machine is deadlocked.
1) Execute the following statement with the dba user
select username,lockwait,status,machine,program from v$session where sid in
(select session_id from v$locked_object)
If there is an output result, it means that there is a deadlock, and you can see which machine the deadlock is. Field Description:
Username: the database user used by the deadlock statement;
Lockwait: The state of deadlock, if there is any content, it is deadlocked.
Status: Status, active means deadlocked
Machine: The machine where the deadlock statement resides.
Program: Which application program the statement that caused the deadlock mainly came from.
2) Execute the following statement with the dba user, you can view the deadlocked statement.
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))
Four, deadlock solution
     Under normal circumstances, as long as the statement that produces the deadlock is submitted, but in the actual execution process. User can
Can you know which sentence is the deadlock. You can close the program and restart it.
 I often encounter this problem in the use of Oracle, so I also summarize a little solution.
1) Find deadlocked processes:
sqlplus "/as sysdba" (sys/change_on_install)


SELECT s.username,l.OBJECT_ID,l.SESSION_ID,s.SERIAL#,
l.ORACLE_USERNAME,l.OS_USER_NAME,l.PROCESS
FROM V$LOCKED_OBJECT l,V$SESSION S WHERE l.SESSION_ID=S.SID;
2) Kill the deadlocked process:
  alter system kill session ‘sid,serial#’; (其中sid=l.session_id)
3) If it still doesn't work:
select pro.spid from v$session ses,v$process pro where ses.sid=XX and ses.paddr=pro.addr;
  where sid is replaced with deadlocked sid: exit
ps -ef|grep spid
  Where spid is the process number of the process, kill the Oracle process
from:http://southking.javaeye.com/blog/550832
 
 

select A.SQL_TEXT, B.USERNAME, C.OBJECT_ID, C.SESSION_ID,
       B.SERIAL#, C.ORACLE_USERNAME,C.OS_USER_NAME,C.Process,
       ''''||C.Session_ID||','||B.SERIAL#||''''
from v$sql A, v$session B, v$locked_object C
where A.HASH_VALUE = B.SQL_HASH_VALUE and
B.SID = C.Session_ID

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326074415&siteId=291194637