• v$sqlarea和v$lock


    v$sqlarea 保留了每条执行的SQL
    
    
    SQL> delete from t100 where object_id = :n;
    
    1 row deleted.
    
    SQL> select to_char(sysdate,'yyyy-mm-dd,hh24:mi:ss'),a.sql_text,to_char(a.LAST_ACTIVE_TIME,'yyyy-mm-dd,hh24:mi:ss')  from v$sqlarea a  where sql_text like '%delete%t100%';
    
    TO_CHAR(SYSDATE,'YY SQL_TEXT			          TO_CHAR(A.LAST_ACTI
    ------------------- ------------------------------ -----------------------------
    2014-11-14,09:37:28 delete from t100 where object_id = :n  2014-11-14,09:35:17
    		    
    
    
    SQL> select to_char(sysdate,'yyyy-mm-dd,hh24:mi:ss'),a.sql_text,to_char(a.LAST_ACTIVE_TIME,'yyyy-mm-dd,hh24:mi:ss')  from v$sqlarea a  where sql_text like '%delete%t100%';
    
    TO_CHAR(SYSDATE,'YY SQL_TEXT			         TO_CHAR(A.LAST_ACTI
    ------------------- ------------------------------ -------------------
    2014-11-14,09:38:10 delete from t100 where object_id = :n  2014-11-14,09:37:56
    
    
    
    SQL> select to_char(sysdate,'yyyy-mm-dd,hh24:mi:ss'),a.sql_text,to_char(a.LAST_ACTIVE_TIME,'yyyy-mm-dd,hh24:mi:ss')  from v$sqlarea a  where sql_text like '%delete%t100%';
    
    TO_CHAR(SYSDATE,'YY SQL_TEXT			           TO_CHAR(A.LAST_ACTI
    ------------------- ------------------------------ -----------------------------
    2014-11-14,09:43:40 delete from t100 where object_id = :n  2014-11-14,09:42:11
    		    
    
    相同的SQL执行显示的是最后被激活的时间
    
    SQL> select sid,id1,ctime, to_char(sysdate,'yyyy-mm-dd,hh24:mi:ss'),to_char(sysdate - a.ctime / 24 / 60 / 60, 'HH24:MI:SS')
                    as lock_time from v$lock a
                   where type in ('TM','TX');  2    3  
    
           SID	  ID1	   CTIME TO_CHAR(SYSDATE,'YY        LOCK_TIM
    ---------- ---------- ---------- ------------------- ---------------
          1613     176570	     939 2014-11-14,09:50:57 09:35:18
          1613     458783	     939 2014-11-14,09:50:57 09:35:18
    
    
    SQL> select to_char(sysdate,'yyyy-mm-dd,hh24:mi:ss'),a.sql_text,to_char(a.LAST_ACTIVE_TIME,'yyyy-mm-dd,hh24:mi:ss')  from v$sqlarea a  where sql_text like '%delete%t100%'
      2  ;
    
    TO_CHAR(SYSDATE,'YY SQL_TEXT			        TO_CHAR(A.LAST_ACTI
    ------------------- ------------------------------ ---------------------------
    2014-11-14,09:52:01 delete from t100 where object_id = :n  2014-11-14,09:42:11
    
    
    所以无法判断LAST_ACTIVE_TIME和to_char(sysdate - a.ctime / 24 / 60 / 60, 'HH24:MI:SS')Lock时间的关系
    
    通过lats_load_time : 执行计划加载到library cache的时间 也不准确
    
    		    
    select c.sql_text,
           a.*,
           b.object_name,
           to_char(sysdate, 'YYYY-MM-DD,hh24:mi:ss'),
           to_date(to_char(c.LAST_load_TIME, 'hh24:mi:ss'), 'hh24:mi:ss') load_time,
           to_date(to_char(sysdate - a.ctime / 24 / 60 / 60, 'HH24:MI:SS'),
                   'HH24:MI:SS') as lock_time
    
      from (select sid, id1, ctime
              from v$lock
             where sid in (select sid
                             from v$lock
                            where type in ('TM', 'TX')
                              and lmode = 6)
               and type = 'TM') a,
           dba_objects b,
           v$sqlarea c
     where a.id1 = b.object_id   
       and c.PARSING_SCHEMA_NAME = 'TEST'
       and (c.sql_text like '%update%' or c.sql_text like '%delete%' or
           c.sql_text like '%insert%')
       and c.sql_text like '%t100%'
    		    

  • 相关阅读:
    WINDOWS操作系统各种版本(转)
    等待的日子
    多媒体大赛决赛纪事
    如何使用nero刻录数据光盘(转)
    无法显示隐藏文件的方法
    2007年教育技术学专业硕士点招生简章
    教育学专业基础综合推荐教材
    .NET 的发展与变迁
    Windows XP SP3与Vista SP1,谁更强?
    2007年教育学专业基础综合考试大纲
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351997.html
Copyright © 2020-2023  润新知