Thursday, July 4, 2013

How to find out locking details of history ??? lock history history lock historical locks


set lines 380 pages 5000
col B_Time format a24
col W_SID format 999999
col B_SID format 999999
col W_SERIAL format 9999999
col B_SERIAL format 9999999
col W_SQLTEXT format a55 WRAP
col B_SQLTEXT format a55 WRAP
SELECT w.sample_time B_Time,
  w.session_id W_SID,
  w.SESSION_SERIAL# W_SERIAL,
  w.sql_text W_SQLTEXT,
  b.session_id B_SID,
  b.SESSION_SERIAL# B_SERIAL,
  b.sql_text B_SQLTEXT
FROM
  (SELECT DISTINCT TO_CHAR(a.sample_time,'yyyy-mon-dd hh24:mi:ss') sample_time,
    a.sql_id ,
    a.inst_id,
    a.SESSION_ID,
    a.SESSION_SERIAL#,
    a.blocking_session,
    a.blocking_session_serial#,
    a.user_id,
    s.sql_text,
    a.module
  FROM GV$ACTIVE_SESSION_HISTORY a ,
    gv$sql s
  WHERE a.sql_id        =s.sql_id
  AND blocking_session IS NOT NULL
  AND a.user_id        <> 0
  AND a.sample_time    >= TO_DATE('2013-jun-25 11:50:00','yyyy-mon-dd hh24:mi:ss')
  AND a.sample_time    <= TO_DATE('2013-jun-25 12:10:00','yyyy-mon-dd hh24:mi:ss')
--  AND a.sql_id          = 'd0nzggkn5ahzr'
  ) w,
  (SELECT DISTINCT TO_CHAR(a.sample_time,'yyyy-mon-dd hh24:mi:ss') sample_time,
    a.sql_id ,
    a.inst_id,
    a.SESSION_ID,
    a.session_Serial#,
    a.blocking_session,
    a.blocking_session_serial#,
    a.user_id,
    s.sql_text,
    a.module
  FROM GV$ACTIVE_SESSION_HISTORY a ,
    gv$sql s
  WHERE a.sql_id                                        =s.sql_id
  AND blocking_session                                 IS NOT NULL
  AND (a.inst_id,a.blocking_session, a.blocking_session_serial#) IN
    (SELECT inst_id,blocking_session,
      blocking_session_serial#
    FROM GV$ACTIVE_SESSION_HISTORY
    WHERE blocking_session       IS NOT NULL
    AND blocking_session_serial# IS NOT NULL
    )
  AND a.sample_time >= TO_DATE('2013-jun-25 11:50:00','yyyy-mon-dd hh24:mi:ss')
  AND a.sample_time <= TO_DATE('2013-jun-25 12:10:00','yyyy-mon-dd hh24:mi:ss')
  ) b
WHERE w.inst_id = b.inst_id
AND b.inst_id = 3
AND w.blocking_session       = b.session_id
AND w.blocking_session_serial# = b.SESSION_SERIAL#
AND w.sample_time              = b.sample_time;

No comments:

Post a Comment