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

来源:这里教程网 时间:2026-03-03 19:41:52 作者:

[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存在重复的. --//当然不能简单的理解每次执行是dist_timestamps/dist_sqlexec_seen1,对于每次执行超过1秒的有一定的参考价值,可以推断每次执 --//行需要的时间。 SYS@127.0.0.1:9014/ywdb> @ ashtop event  sql_id='g7ytdh9mxt1s0'  &day     Total                                                                                                      Distinct Distinct    Distinct   Seconds     AAS %This   EVENT                                      FIRST_SEEN          LAST_SEEN           Execs Seen  Tstamps Execs Seen1 --------- ------- ------- ------------------------------------------ ------------------- ------------------- ---------- -------- -----------      1266      .0   98% |                                            2024-03-18 08:53:33 2024-03-19 08:52:45        852     1261        1266        16      .0    1% | log file sync                              2024-03-18 10:37:38 2024-03-18 21:53:48          1       16          16         9      .0    1% | reliable message                           2024-03-18 09:43:51 2024-03-18 17:58:55          1        9           9         3      .0    0% | SQL*Net message from dblink                2024-03-18 15:23:43 2024-03-18 16:41:05          1        3           3         2      .0    0% | latch free                                 2024-03-18 11:22:46 2024-03-18 16:58:07          2        2           2         1      .0    0% | cursor: pin S                              2024-03-18 09:07:13 2024-03-18 09:07:13          1        1           1 6 rows selected.

相关推荐