• 查看持有行锁的SQL


    <pre name="code" class="sql">SQL> select sid, id1, ctime from v$lock where type in ('TM', 'TX');
    
           SID	  ID1	   CTIME
    ---------- ---------- ----------
    	23	76239	       6
    	23     327693	       6
    
    
    
    SQL>   select sql_text, to_char(c.LAST_LOAD_TIME,'hh24:mi:ss') from v$sqlarea c  where sql_text like '%delete%from%t100';
    
    SQL_TEXT		       TO_CHAR(
    ------------------------------ --------
    delete from t100	       23:56:05
    
    
    SQL>  select to_char(sysdate,'hh24:mi:ss' ),ctime,to_char(sysdate- ctime/24/60/60,'HH24:MI:SS') from v$lock  where type in ('TM', 'TX');
    
    TO_CHAR(      CTIME TO_CHAR(
    -------- ---------- --------
    23:56:23	 17 23:56:06
    23:56:23	 17 23:56:06
    
    只需要激活游标的时间<=行锁开始的时间即可
    
    
    select c.sql_text,
           a.*,
           b.object_name,
           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 type in ('TM', 'TX')) a,
           dba_objects b,
           v$sqlarea c
     where a.id1 = b.object_id
       and to_date(to_char(c.LAST_LOAD_TIME, 'hh24:mi:ss'), 'hh24:mi:ss') <=
           to_date(to_char(sysdate - a.ctime / 24 / 60 / 60, 'HH24:MI:SS'),
                   'HH24:MI:SS')
       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%'

    在有绑定变量的情况下,游标有可能时刻刷新,那么active_time的时间会大于lock_time的时间无法判断

    select c.sql_text,
           a.*,
           b.object_name,
           to_date(to_char(c.LAST_active_TIME, 'hh24:mi:ss'), 'hh24:mi:ss') active_time,
           to_date(to_char(sysdate - a.ctime / 24 / 60 / 60, 'HH24:MI:SS'),
                   'HH24:MI:SS') as lock_time,
           to_date(to_char(sysdate - a.ctime / 24 / 60 / 60 - 10 / 24 / 60 / 60,
                           'HH24:MI:SS'),
                   'HH24:MI:SS') min_time
      from (select sid, id1, ctime from v$lock where type in ('TM')) a,
           dba_objects b,
           v$sqlarea c
     where a.id1 = b.object_id
    /*   and to_date(to_char(c.LAST_active_TIME, 'hh24:mi:ss'), 'hh24:mi:ss') <=
           to_date(to_char(sysdate - a.ctime / 24 / 60 / 60, 'HH24:MI:SS'),
                   'HH24:MI:SS')*/
       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%'
    /*   and to_date(to_char(c.LAST_active_TIME + 10 / 24 / 60 / 60, 'hh24:mi:ss'),
                   'hh24:mi:ss') >=
           to_date(to_char(sysdate - a.ctime / 24 / 60 / 60 - 10 / 24 / 60 / 60,
                           'HH24:MI:SS'),
                   'HH24:MI:SS')*/
      and c.sql_text like '%delete from t100 where object_id = :n%';   
    select to_char(sysdate, 'hh24:mi:ss'),
           ctime,
           b.object_name,
           to_char(sysdate - ctime / 24 / 60 / 60, 'HH24:MI:SS') lock_running_sql
      from v$lock a, dba_objects b
     where a.type in ('TM', 'TX')
       and b.owner = 'TEST'
       and a.id1 = b.object_id
       and b.object_name='&object'
       

        在根据sql运行的时间去v$sqlarea 按last_active_time 找,找到相依的SQL


    select c.sql_text,
           a.*,
           b.object_name,
           to_date(to_char(c.LAST_active_TIME, 'hh24:mi:ss'), 'hh24:mi:ss') active_time,
           to_date(to_char(sysdate - a.ctime / 24 / 60 / 60, 'HH24:MI:SS'),
                   'HH24:MI:SS') as lock_time,
           to_date(to_char(sysdate - a.ctime / 24 / 60 / 60 - 10 / 24 / 60 / 60,
                           'HH24:MI:SS'),
                   'HH24:MI:SS') min_time
      from (select sid, id1, ctime from v$lock where type in ('TM')) a,
           dba_objects b,
           v$sqlarea c
     where a.id1 = b.object_id
       and to_date(to_char(c.LAST_active_TIME, 'hh24:mi:ss'), 'hh24:mi:ss') <=
           to_date(to_char(sysdate - a.ctime / 24 / 60 / 60, 'HH24:MI:SS'),
                   'HH24:MI:SS')
       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%'
       and to_date(to_char(c.LAST_active_TIME + 10 / 24 / 60 / 60, 'hh24:mi:ss'),
                   'hh24:mi:ss') >=
           to_date(to_char(sysdate - a.ctime / 24 / 60 / 60 - 10 / 24 / 60 / 60,
                           'HH24:MI:SS'),
                   'HH24:MI:SS')


    
                                        
    
  • 相关阅读:
    已解决: 已引发: "无法加载 DLL“opencv_core2410”: 找不到指定的模块。
    Xcode 设置图片全屏显示
    独创轻松实现拖拽,改变层布局
    WCF Odata 开放数据协议应用
    MVC中,加入的一个aspx页面用到AspNetPager控件处理办法
    关于 HRESULT:0x80070
    Springboot文件上传大小设置
    Jquery Validate 表单验证使用
    Quartz任务调度框架使用
    js中常见命令
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351999.html
Copyright © 2020-2023  润新知