Home > Database > Oracle > body text

How to query deadlock in oracle

WBOY
Release: 2022-01-25 16:51:52
Original
7073 people have browsed it

In Oracle, you can use the select statement to query deadlocks. This statement is used for simple data query. The syntax is "select * from v$session where sid in (select session_id from v$locked_object)".

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 it is dead Lock.

  • Status: Status, active means deadlocked

  • Machine: The machine where the deadlock statement is located.

  • Program: From which application the statements that generate deadlocks mainly come from

2) Use the dba user to execute the following statements, you can view the deadlock Lock 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)

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!