SQL statement used to check deadlocks in Oracle

Source: Internet
Author: User
Check the SQL statement of the deadlock

1.

Select Sid, decode (Block, 0, 'No', 'yes') blocker, decode (request, 0, 'No', 'yes') Waiter
From v $ lock
Where request> 0 or block> 0
Order by block DESC;

2.

Select BS. username "blocking user", BS. username "DB user ",
WS. username "Waiting user", BS. Sid "Sid", WS. Sid "wsid ",
BS. Serial # "serial #", BS. SQL _address "Address ",
BS. SQL _hash_value "SQL hash", BS. Program "blocking app ",
WS. Program "Waiting app", BS. Machine "blocking Machine ",
WS. Machine "Waiting Machine", BS. osuser "blocking OS user ",
WS. osuser "Waiting OS user", BS. Serial # "serial #",
WS. Serial # "wserial #",
Decode (WK. type,
'Mr ', 'Media recovery ',
'Redo thread', 'redo thread ',
'Non', 'user name ',
'Tx ', 'Transaction ',
'Tm', 'dml ',
'Ul ', 'pl/SQL user lock ',
'Dx ', 'stributed xaction ',
'Cf ', 'control file ',
'Is ', 'instance State ',
'Fs', 'file set ',
'Ir', 'instance recovery ',
'St', 'disk space transaction ',
'Ts', 'temp segment ',
'Iv ', 'library cache invalidation ',
'Ls', 'Log start or switch ',
'Rw ', 'row wait ',
'Sq ', 'sequence number ',
'Te', 'extend table ',
'TT', 'temp table ',
WK. Type
) Lock_type,
Decode (HK. lmode,
0, 'none ',
1, 'null ',
2, 'row-s (SS )',
3, 'row-X (SX )',
4, 'share ',
5,'s/ROW-X (ssx )',
6, 'clusive ',
To_char (HK. lmode)
) Mode_held,
Decode (WK. Request,
0, 'none ',
1, 'null ',
2, 'row-s (SS )',
3, 'row-X (SX )',
4, 'share ',
5,'s/ROW-X (ssx )',
6, 'clusive ',
To_char (WK. Request)
) Mode_requested,
To_char (HK. id1) lock_id1, to_char (HK. Id2) lock_id2,
Decode (HK. Block,
0, 'not blocking',/* not blocking any other processes */
1, 'blocking',/* this lock blocks other processes */
2, 'global',/* This lock is global, so we can't tell */
To_char (HK. Block)
) Blocking_others
From v $ lock HK, V $ session BS, V $ lock wk, V $ session WS
Where HK. Block = 1
And HK. lmode! = 0
And HK. lmode! = 1
And wk. Request! = 0
And wk. Type (+) = HK. Type
And wk. id1 (+) = HK. id1
And wk. Id2 (+) = HK. Id2
And HK. Sid = BS. Sid (+)
And wk. Sid = ws. Sid (+)
And (BS. username is not null)
And (BS. Username <> 'system ')
And (BS. Username <> 'sys ')
Order by 1;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.