Query and Handling of Oracle Database Deadlock Problem

    Recently, I encountered the problem of oracle database deadlock in my work. The following is the query and processing method of the reproduced problem, intrusion and deletion.

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 certain table in the database is performed, the statement is not
submitted , and another statement that updates the data in this column will be in a state of Waiting state,
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.
3. Deadlock positioning method
By checking the database table, it is possible to check which statement is deadlocked and which machine is the deadlock.
1) Use the dba user to execute the following statement
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 there is a deadlock and you can see the deadlock Which machine is the lock? Field description:
Username: the database user used by the deadlock statement;
Lockwait: the status of the deadlock, if there is any content, it means that it is deadlocked.
Status: Status, active means deadlocked
Machine: The machine where the deadlock statement is located.
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))

Fourth, the solution to deadlock
     In general, as long as the statement that produces the deadlock is submitted, but in the actual execution process. The user
may not know which statement caused 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

 

From: http://xinxiangsui2018.blog.163.com/blog/static/106097856201010304532280/


Guess you like

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