Home > Database > Oracle > body text

How to query deadlock in oracle

WBOY
Release: 2022-02-17 17:13:18
Original
32553 people have browsed it

In Oracle, you can use the dba user to execute the "select username, lockwait, status, machine, program from v$session where sid in" statement to query the deadlock. If there is a result, the deadlock will be displayed.

How to query deadlock in oracle

The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.

How to query deadlock in oracle

1. Check 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)
Copy after login

If there is an output result, then Explain that there is a deadlock, and you can see which machine is the deadlock. Field description:

Username: The database user used in the deadlock statement;

Lockwait: The status of the deadlock. If there is content, it means that it is deadlocked.

Status: Status, active means deadlocked

Machine: The machine where the deadlock statement is located.

Program: Which application does the deadlock statement mainly come from?

2) Use the dba user to execute the following statement to 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))
Copy after login

2. Solution to deadlock

1) Find the deadlocked process:

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;
Copy after login

2) Kill the deadlocked process: alter system kill session ' sid,serial#'; (where sid=l.session_id)

3) If it still cannot be solved:

select pro.spid from v$session ses,
v$process pro
where
ses.sid=XX
and ses.paddr=pro.addr;
Copy after login

Replace sid with the deadlocked sid:

Recommended Tutorial: "Oracle Video Tutorial"

The above is the detailed content of How to query deadlock in oracle. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template