zoukankan      html  css  js  c++  java
  • oracle查看执行最慢与查询次数最多的sql语句及其执行速度很慢的问题分析

    在ORACLE数据库应用调优中,一个SQL的执行次数/频率也是常常需要关注的,因为某个SQL执行太频繁,要么是由于应用设计有缺陷,需要在业务逻辑上做出优化处理,要么是业务特殊性所导致。如果执行频繁的SQL,往往容易遭遇一些并发性的问题。 那么如何查看ORACLE数据库某个SQL的执行频率/次数呢? 下面来看看完整的示例代码。

    一、查询执行最慢的sql

     1 select *
     2  from (select sa.SQL_TEXT,
     3         sa.SQL_FULLTEXT,
     4         sa.EXECUTIONS "执行次数",
     5         round(sa.ELAPSED_TIME / 1000000, 2) "总执行时间",
     6         round(sa.ELAPSED_TIME / 1000000 / sa.EXECUTIONS, 2) "平均执行时间",
     7         sa.COMMAND_TYPE,
     8         sa.PARSING_USER_ID "用户ID",
     9         u.username "用户名",
    10         sa.HASH_VALUE
    11      from v$sqlarea sa
    12      left join all_users u
    13       on sa.PARSING_USER_ID = u.user_id
    14      where sa.EXECUTIONS > 0
    15      order by (sa.ELAPSED_TIME / sa.EXECUTIONS) desc)
    16  where rownum <= 50;

    二、查询次数最多的 sql

    1 select *
    2  from (select s.SQL_TEXT,
    3         s.EXECUTIONS "执行次数",
    4         s.PARSING_USER_ID "用户名",
    5         rank() over(order by EXECUTIONS desc) EXEC_RANK
    6      from v$sql s
    7      left join all_users u
    8       on u.USER_ID = s.PARSING_USER_ID) t
    9  where exec_rank <= 100;

    三、Oracle查询SQL语句执行的耗时

     1 select a.sql_text SQL语句,
     2        b.etime 执行耗时,
     3        c.user_id 用户ID,
     4        c.SAMPLE_TIME 执行时间,
     5        c.INSTANCE_NUMBER 实例数,
     6        u.username 用户名, a.sql_id SQL编号
     7   from dba_hist_sqltext a,
     8        (select sql_id, ELAPSED_TIME_DELTA / 1000000 as etime
     9           from dba_hist_sqlstat
    10          where ELAPSED_TIME_DELTA / 1000000 >= 1) b,
    11        dba_hist_active_sess_history c,
    12        dba_users u
    13  where a.sql_id = b.sql_id
    14    and u.username = 'POADB'
    15    and c.user_id = u.user_id
    16    and b.sql_id = c.sql_id
    17    and a.sql_text like '%insert into TTTTTT %'
    18  order by  SAMPLE_TIME desc,
    19   b.etime desc;

    四:定位系统里面哪些SQL脚本存在TABLE ACCESS FULL行为

    1 select * from v$sql_plan v
    2 where v.operation = 'TABLE ACCESS'
    3 and v.OPTIONS = 'FULL'
    4 and v.OBJECT_OWNER='POSDB';
    1 select s.SQL_TEXT from v$sqlarea s
    2 where s.SQL_ID = '4dpd97jh2gzsd'
    3 and s.HASH_VALUE = '1613233933'
    4 and s.PLAN_HASH_VALUE = '3592287464';
    5 
    6 /*或者*/
    7 select s.SQL_TEXT from v$sqlarea s where s.ADDRESS ='00000000A65D2318';
  • 相关阅读:
    【Tools__技巧】软件技巧整理归纳
    【JS__框架】主页面F5刷新iframe框架页面
    为类型增加选择属性
    单元测试mock当前时间
    silverlight属性改变事件通知
    修改博客园推荐人数增加W效果
    Enum扩展特性,代替中文属性
    Python爬虫-萌妹子图片
    吐槽下魅族
    使用openXML 不用插件导出excel
  • 原文地址:https://www.cnblogs.com/lgx5/p/14350138.html
Copyright © 2011-2022 走看看