This script can check who is locking the table and who is waiting for the table.
--
-- Check who is locking the table and who is waiting for the table.
-- Lock. SQL
-- Purplefox
--
Select/* + choose */
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
/