[20240313]使用tpt ashtop.sql脚本的困惑.txt

[20240313]使用tpt ashtop.sql脚本的困惑.txt

–//使用tpt ashtop.sql脚本遇到的问题,做一些分析以及说明:

1.环境:

SYS@127.0.0.1:9014/ywdb> @ver1

PORT_STRING                    VERSION        BANNER

—————————— ————– ——————————————————————————–

x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 – 64bit Production

2.问题:

SYS@127.0.0.1:9014/ywdb> @ ashtop sql_id sql_id=’2cqbg080kv9uh’ &day

    Total                                                                         Distinct Distinct

  Seconds     AAS %This   SQL_ID        FIRST_SEEN          LAST_SEEN           Execs Seen  Tstamps

——— ——- ——- ————- ——————- ——————- ———- ——–

        5      .0  100% | 2cqbg080kv9uh 2024-03-12 14:24:04 2024-03-13 10:54:39          1        5

–//Distinct Execs Seen =1,Distinct Tstamps=5,按照我以前的理解,Distinct Execs Seen相当于执行次数,Distinct Tstamps相当于

–//总的执行时间(注:两条相同sql语句同时执行,sample_time总会有一点点不同,相同的概率应该很低),除非很密集的执行也许可能出现

–//sample_time相同的情况.

–//我看过这条sql语句应该很快完成,根本不可能1次执行需要5秒.

–//感觉那里不对。

3.分析:

–//查看ashtop.sql脚本:



      , COUNT(DISTINCT sql_exec_start||’:’||sql_exec_id) dist_sqlexec_seen

      , COUNT(DISTINCT sample_time) dist_timestamps

SELECT sql_id, sql_exec_start || ‘:’ || sql_exec_id, sample_time

  FROM gV$ACTIVE_SESSION_HISTORY

 WHERE     sql_id = ‘2cqbg080kv9uh’

       AND sample_time BETWEEN SYSDATE – 1 AND SYSDATE;

SQL_ID        SQL_EXEC_START||’:’||SQL_EXEC_ID SAMPLE_TIME

————- ——————————– ———————–

2cqbg080kv9uh :                                2024-03-12 21:38:48.048

2cqbg080kv9uh :                                2024-03-13 10:54:39.810

2cqbg080kv9uh :                                2024-03-13 08:15:53.122

2cqbg080kv9uh :                                2024-03-12 18:41:53.370

2cqbg080kv9uh :                                2024-03-12 14:24:04.705

       

–//噢!! 原来gV$ACTIVE_SESSION_HISTORY视图有一些情况并没有抓取到SQL_EXEC_START,SQL_EXEC_ID的值,这样看到dist_sqlexec_seen=1.

–//不清楚怎么时候会出现这样的情况。

4.总结:

–//Distinct Execs Seen,Distinct Tstamps 只能作为参考.

–//感觉tpt ashtop.sql脚本应该修改为:

COL dist_sqlexec_seen1  HEAD “Distinct|Execs Seen1” FOR 999999



, COUNT(DISTINCT decode(sql_exec_start||’:’||sql_exec_id,’:’,to_char(sample_time,’yyyymmdd hh24:mi:ss.ff3′),sql_exec_start||’:’||sql_exec_id)) dist_sqlexec_seen1

–//或者再增加一个字段也许更加合理一些.

SYS@127.0.0.1:9014/ywdb> @ ashtop sql_id sql_id=’g7ytdh9mxt1s0′ &day

    Total                                                                         Distinct Distinct    Distinct

  Seconds     AAS %This   SQL_ID        FIRST_SEEN          LAST_SEEN           Execs Seen  Tstamps Execs Seen1

——— ——- ——- ————- ——————- ——————- ———- ——– ———–

      991      .0  100% | g7ytdh9mxt1s0 2024-03-17 11:52:15 2024-03-18 11:51:11        636      987         991

SYS@127.0.0.1:9014/ywdb> @ sql_id g7ytdh9mxt1s0

–SQL_ID = g7ytdh9mxt1s0

select count ( :”SYS_B_0″ ) from BSOFT_TEST_CONNECT ;

–//这条语句执行频率非常高, 执行很快,dist_timestamps=987,如果前面dist_sqlexec_seen表示执行次数,明显不妥.

–//dist_sqlexec_seen1=991,说明有4次(991-987)的sample_time存在重复的.

© 版权声明
THE END
支持一下吧
点赞12 分享
评论 抢沙发
头像
请文明发言!
提交
头像

昵称

取消
昵称表情代码快捷回复

    暂无评论内容