[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存在重复的.
发表评论