用SQL生成awr报表中的“SQL ordered by Elapsed Time” 部分

以下SQL用于生成awr的以下部分。




--提取&beg_snap 、&end_snap
select * from dba_hist_snapshot x ;
--提取&dbid 
select * from v$database;
--提取$inst_num
select * from v$instance;


select *
  from (select round(nvl((sqt.elap / 1000000), to_number(null)),2) "Elapsed Time (s)",
              round( nvl((sqt.cput / 1000000), to_number(null)),2) "CPU Time (s)",
               sqt.exec,
               round(decode(sqt.exec,
                      0,
                      to_number(null),
                      (sqt.elap / sqt.exec / 1000000)),2) "Elap per Exec (s)",
               round((100 *
               (sqt.elap / (select sum(e.value) - sum(b.value)
                               from dba_hist_sys_time_model b,
                                    dba_hist_sys_time_model e
                              where b.snap_id = &beg_snap and
                                    e.snap_id = &end_snap and
                                    b.dbid = &dbid and
                                    e.dbid = &dbid and
                                    b.instance_number = &inst_num and
                                    e.instance_number = &inst_num and
                                    e.stat_name = 'DB time' and
                                    b.stat_name = 'DB time'))) ,2)norm_val,
               sqt.sql_id,
               decode(sqt.module, null, null, 'Module: ' || sqt.module) SqlModule,
               nvl(to_nchar(SUBSTR(st.sql_text,1,2000)) , (' ** SQL Text Not Available ** ')) SqlText
          from (select sql_id,
                       max(module) module,
                       sum(elapsed_time_delta) elap,
                       sum(cpu_time_delta) cput,
                       sum(executions_delta) exec
                  from dba_hist_sqlstat
                 where dbid = &dbid and
                       instance_number = &inst_num and
                       &beg_snap < snap_id and
                       snap_id <= &end_snap
                 group by sql_id) sqt,
               dba_hist_sqltext st
         where st.sql_id(+) = sqt.sql_id and
               st.dbid(+) = &dbid
         order by nvl(sqt.elap, -1) desc,
                  sqt.sql_id)
 where rownum < 65 and
       (rownum <= 10 or norm_val > 1);

从dba_hist_sqlstat提取更多的指标,调整加粗部分,照葫芦画瓢就可以写出
SQL ordered by CPU Time
SQL ordered by Gets
SQL ordered by Reads
SQL ordered by Executions
SQL ordered by Parse Calls
SQL ordered by Sharable Memory

SQL ordered by Elapsed Time Resources reported for PL/SQL code includes the resources used by all SQL statements called by the code. % Total DB Time is the Elapsed Time of the SQL statement divided into the Total Database Time multiplied by 100 %Total - Elapsed Time as a percentage of Total DB time %CPU - CPU Time as a percentage of Elapsed Time %IO - User I/O Time as a percentage of Elapsed Time Captured SQL account for 62.0% of Total DB Time (s): 22,895 Captured PL/SQL account for 27.9% of Total DB Time (s): 22,895 Elapsed Time (s) Executions Elapsed Time per Exec (s) %Total %CPU %IO SQL Id SQL Module SQL Text 5,836.35 1 5,836.35 25.49 5.21 88.87 6mcpb06rctk0x DBMS_SCHEDULER call dbms_space.auto_space_adv... 5,252.74 1 5,252.74 22.94 4.86 93.44 f544nx44ms6s9 DBMS_SCHEDULER create table "YAWX" 4,466.29 1,464 3.05 19.51 0.03 0.00 dh06pvzvd8qnr JDBC Thin Client select * from ( select p.polic... 614.83 289 2.13 2.69 0.04 0.00 2z3y9kbxs476h JDBC Thin Client select * from ( select p.polic... 501.64 507 0.99 2.19 0.07 0.00 fj7fd394n7y77 JDBC Thin Client select writtenDate, sum(premiu... 494.84 1 494.84 2.16 9.50 36.80 b6usrg82hwsa3 DBMS_SCHEDULER call dbms_stats.gather_databas... 324.01 520 0.62 1.42 82.38 30.46 02a7j0u6cu5m7 JDBC Thin Client update wx_undwrt_detail t set ... 230.67 125 1.85 1.01 0.06 0.00 3xg8jks8aq5x4 JDBC Thin Client select * from ( select p.polic... 211.38 59,688 0.00 0.92 1.85 80.83 4rz6f6c6uy37t JDBC Thin Client select * from WX_OUTUSER where... 206.87 242 0.85 0.90 0.08 0.00 1pzu5n4t8hgaw JDBC Thin Client select writtenDate, sum(premiu... 使用率上涨和哪个SQL有关
10-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值