[20220102]使用ashtop与dashtop脚本的小问题.txt
--//最近做优化工作,一直使用tpt的ashtop与dashtop脚本探察数据库问题,发现使用中一个小问题.
--//说明一下,使用ashtop查询的是gv$active_session_history视图,dashtop查询的是dba_hist_active_sess_history视图.
--//有时候两者要经常交替使用.
--//有时候我需要查询一个实例的情况,经常执行
@ashtop sql_id,inst_id 1=1 &day
--//切换为dashtop执行时出现问题
> @dashtop sql_id,inst_id 1=1 &day
sql_id,inst_id
*
ERROR at line 85:
ORA-00904: "INST_ID": invalid identifier
--//实际上问题在于dba_hist_active_sess_history视图里面没有inst_id字段,变成了instance_number字段.也就是换成
--//dashtop执行的是:
@dashtop sql_id,instance_number 1=1 &day
--//两者切换非常麻烦,修改一下dashtop.sql脚本:
(SELECT
a.instance_number inst_id,
a.*
...
FROM dba_hist_active_sess_history a) a
--//这样执行如下就没有任何问题,切换执行起来很方便.
@dashtop sql_id,inst_id 1=1 &day
--//再比如我们应用执行的程序名一种是小写另外一种是大写的风格的类型,tpt脚本定义一个字段program2.只要修改如下就可以统一起
--//来.
CASE WHEN a.session_type = 'BACKGROUND' OR REGEXP_LIKE(a.program, '.*\([PJ]\d+\)') THEN
REGEXP_REPLACE(SUBSTR(a.program,INSTR(a.program,'(')), '\d', 'n')
ELSE
'('||REGEXP_REPLACE(REGEXP_REPLACE(a.program, '(.*)@(.*)(\(.*\))', '\1'), '\d', 'n')||')'
END || ' ' program2
--//可以修改为
CASE WHEN a.session_type = 'BACKGROUND' OR REGEXP_LIKE(lower(a.program), '.*\([PJ]\d+\)') THEN
REGEXP_REPLACE(SUBSTR(lower(a.program),INSTR(a.program,'(')), '\d', 'n')
ELSE
'('||REGEXP_REPLACE(REGEXP_REPLACE(lower(a.program), '(.*)@(.*)(\(.*\))', '\1'), '\d', 'n')||')'
END || ' ' program2
--//如果你不想修改可以直接在查询是增加字段.
,lower(a.program) program1
,lower(a.module) module1
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2850485/ ,如需转载,请注明出处,否则将追究法律责任。