Please find the sql queries below to get the details of db blocks.
Check_db_blocks :
*********************
set linesize 512
select v.instance_name ||' - '|| l1.sid ||' ('||s1.client_identifier||' - '||s1.module||')' || ' IS BLOCKING ' || l2.sid||' ('||s2.client_identifier||' - '||s2.module||')'
|| s1.sql_id || s1.username || s1.program || s1.machine "BLOCKING SESSIONS"
from v$instance v, v$lock l1, v$lock l2, v$session s1, v$session s2
where l1.block =1 and l2.request > 0
and l1.id1=l2.id1
and l1.id2=l2.id2
and l1.sid=s1.sid and l2.sid=s2.sid;
Check_db_locks :
********************
set lines 100
select ' SID '||
sid||' ,Serial# '||serial#||' user '||username||' is getting blocked by SID '||blocking_session|| ' for last '||seconds_in_wait||' seconds and wait_event '||event||' for SQL_ID '||sql_id
||' (Locked_Object_ID '||row_wait_obj#||' locked_block_id '||row_wait_block#||' locked_row_id '||row_wait_row#||')' "Active Locks"
from
v$session
where
lockwait is not null and ROW_WAIT_OBJ#!=-1 and seconds_in_wait>10
order by
sid;
To get the blocking SID details
***********************************
set lines 300
col machine for a20
col MODULE for a15
col program for a20
col EVENT for a30
col USERNAME for a10
col OSUSER for a08
select sid,serial#,sql_id,username,status,machine,osuser,module,program,event from v$session where sid=&sid;
col SQL_TEXT for a75
select sql_text from v$sqltext where sql_id ='&sql_id' order by piece;
Useful SQL Statements
***************************
If you encounter a lock related hang scenario the following SQL statements can be used to help isolate the waiters and blockers:
Show all sessions waiting for any lock:
*******************************************
SELECT event, p1, p2, p3 FROM v$session_wait WHERE wait_time= 0 AND event like 'enq%';
SELECT sid, p1raw, p2, p3 FROM v$session_wait WHERE wait_time = 0 AND event like 'enq: TX%';
SELECT sw.sid,p.SPID, sw.p1raw, sw.p2, sw.p3 FROM v$session_wait sw,v$process p WHERE wait_time = 0 AND event like 'enq: TX%';
Show sessions waiting for a TX lock:
*****************************************
SELECT * FROM v$lock WHERE type='TX' AND request>0;
Show sessions holding a TX lock:
**************************************
SELECT * FROM v$lock WHERE type='TX' AND lmode > 0;
Show which segments have undergone the most row lock waits:
************************************************************************
SELECT owner, object_name, subobject_name, value FROM v$segment_statistics
WHERE statistic_name='row lock waits' AND value > 0 ORDER BY 4 DESC;
Wait about few minutes or so, and then run the script again. You may compare the differences of corresponding entries in the VALUE column to see which object(s) has undergone the most row lock contention.
Check_db_blocks :
*********************
set linesize 512
select v.instance_name ||' - '|| l1.sid ||' ('||s1.client_identifier||' - '||s1.module||')' || ' IS BLOCKING ' || l2.sid||' ('||s2.client_identifier||' - '||s2.module||')'
|| s1.sql_id || s1.username || s1.program || s1.machine "BLOCKING SESSIONS"
from v$instance v, v$lock l1, v$lock l2, v$session s1, v$session s2
where l1.block =1 and l2.request > 0
and l1.id1=l2.id1
and l1.id2=l2.id2
and l1.sid=s1.sid and l2.sid=s2.sid;
Check_db_locks :
********************
set lines 100
select ' SID '||
sid||' ,Serial# '||serial#||' user '||username||' is getting blocked by SID '||blocking_session|| ' for last '||seconds_in_wait||' seconds and wait_event '||event||' for SQL_ID '||sql_id
||' (Locked_Object_ID '||row_wait_obj#||' locked_block_id '||row_wait_block#||' locked_row_id '||row_wait_row#||')' "Active Locks"
from
v$session
where
lockwait is not null and ROW_WAIT_OBJ#!=-1 and seconds_in_wait>10
order by
sid;
To get the blocking SID details
***********************************
set lines 300
col machine for a20
col MODULE for a15
col program for a20
col EVENT for a30
col USERNAME for a10
col OSUSER for a08
select sid,serial#,sql_id,username,status,machine,osuser,module,program,event from v$session where sid=&sid;
col SQL_TEXT for a75
select sql_text from v$sqltext where sql_id ='&sql_id' order by piece;
Useful SQL Statements
***************************
If you encounter a lock related hang scenario the following SQL statements can be used to help isolate the waiters and blockers:
Show all sessions waiting for any lock:
*******************************************
SELECT event, p1, p2, p3 FROM v$session_wait WHERE wait_time= 0 AND event like 'enq%';
SELECT sid, p1raw, p2, p3 FROM v$session_wait WHERE wait_time = 0 AND event like 'enq: TX%';
SELECT sw.sid,p.SPID, sw.p1raw, sw.p2, sw.p3 FROM v$session_wait sw,v$process p WHERE wait_time = 0 AND event like 'enq: TX%';
Show sessions waiting for a TX lock:
*****************************************
SELECT * FROM v$lock WHERE type='TX' AND request>0;
Show sessions holding a TX lock:
**************************************
SELECT * FROM v$lock WHERE type='TX' AND lmode > 0;
Show which segments have undergone the most row lock waits:
************************************************************************
SELECT owner, object_name, subobject_name, value FROM v$segment_statistics
WHERE statistic_name='row lock waits' AND value > 0 ORDER BY 4 DESC;
Wait about few minutes or so, and then run the script again. You may compare the differences of corresponding entries in the VALUE column to see which object(s) has undergone the most row lock contention.
Comments
Post a Comment