[20211130]完善tpt t.sql脚本.txt --//最近一直在看tpt脚本,在tpt脚本有一个人脚本用来获取跟踪文件。脚本t.sql,脚本很简单。 $ cat t.sql SELECT value tracefile FROM v$diag_info WHERE name = 'Default Trace File'; --//实际上脚本仅仅支持11g以上,在10g下无法使用,会报错。看了许多tpt脚本,自己修改看看,完善这部分功能。 --//利用变量的替换功能实现。 $ cat ttt.sql def trc=unknown column tracefile noprint new_value trc define noprint='noprint' --define noprint='' set termout off head off col tpt_version_old &noprint new_value _tpt_version_old col tpt_version_new &noprint new_value _tpt_version_new col tpt_noprint &noprint new_value _tpt_noprint WITH version AS (SELECT TO_NUMBER (SUBSTR (version, 1, 2)) v FROM v$instance) SELECT CASE WHEN v <= 10 THEN '' ELSE '--' END tpt_version_old ,CASE WHEN v > 10 THEN '' ELSE '--' END tpt_version_new FROM version; --set termout on head on SELECT &&_tpt_version_new value tracefile , 1 tpt_noprint FROM &&_tpt_version_new v$diag_info, dual where &&_tpt_version_new name = 'Default Trace File' and 1=1; SELECT &&_tpt_version_old value ||'/'||(select instance_name from v$instance) ||'_ora_'|| &&_tpt_version_old (select spid||case when traceid is not null then '_'||traceid else null end &&_tpt_version_old from v$process where addr = (select paddr from v$session &&_tpt_version_old where sid = (select sid from v$mystat &&_tpt_version_old where rownum = 1 &&_tpt_version_old ) &&_tpt_version_old ) &&_tpt_version_old ) || '.trc' tracefile, 1 tpt_noprint from v$parameter where name = 'user_dump_dest'; set termout on head on prompt prompt tracefile_identifier = &trc prompt col tracefile print --//注:实际上以下两句在init.sql有不需要定义,因为登录是自动通过login.sql调用init.sql. def trc=unknown column tracefile noprint new_value trc --//测试: --//10g的环境: SCOTT@192.168.100.33:1521/test> @ ver1 PORT_STRING VERSION BANNER ------------------------------ -------------- ---------------------------------------------------------------- x86_64/Linux 2.4.xx 10.2.0.4.0 Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi SCOTT@192.168.100.33:1521/test> @ ttt tracefile_identifier = /u01/app/oracle/admin/test/udump/test_ora_10503.trc SCOTT@192.168.100.33:1521/test> @ ti New tracefile_identifier = /u01/app/oracle/admin/test/udump/test_ora_10503.trc SCOTT@192.168.100.33:1521/test> @ ttt tracefile_identifier = /u01/app/oracle/admin/test/udump/test_ora_10503_0001.trc --//注意 ti.sql脚本使用新的方式获取trc文件这样在10g下不对。ti.sql输出结果有错。 --//11g的环境: SCOTT@book> @ 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 SCOTT@book> @ ttt tracefile_identifier = /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_63951.trc SCOTT@book> @ ti New tracefile_identifier = /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_63951_0001.trc SCOTT@book> @ ttt tracefile_identifier = /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_63951_0001.trc --//随便贴上我改写ti.sql脚本: $ cat ti.sql -- Copyright 2018 Tanel Poder. All rights reserved. More info at http://tanelpoder.com -- Licensed under the Apache License, Version 2.0. See LICENSE.txt for terms & conditions. @@saveset column _ti_sequence noprint new_value _ti_sequence set feedback off heading off select trim(to_char( &_ti_sequence + 1 , '0999' )) "_ti_sequence" from dual; alter session set tracefile_identifier="&_ti_sequence"; set feedback on heading on set termout off column tracefile noprint new_value trc set termout off head off define noprint='noprint' --define noprint='' col tpt_version_old &noprint new_value _tpt_version_old col tpt_version_new &noprint new_value _tpt_version_new col tpt_noprint &noprint new_value _tpt_noprint WITH version AS (SELECT TO_NUMBER (SUBSTR (version, 1, 2)) v FROM v$instance) SELECT CASE WHEN v <= 10 THEN '' ELSE '--' END tpt_version_old ,CASE WHEN v > 10 THEN '' ELSE '--' END tpt_version_new FROM version; --set termout on head on SELECT &&_tpt_version_new value tracefile , 1 tpt_noprint FROM &&_tpt_version_new v$diag_info, dual where &&_tpt_version_new name = 'Default Trace File' and 1=1; SELECT &&_tpt_version_old value ||'/'||(select instance_name from v$instance) ||'_ora_'|| &&_tpt_version_old (select spid||case when traceid is not null then '_'||traceid else null end &&_tpt_version_old from v$process where addr = (select paddr from v$session &&_tpt_version_old where sid = (select sid from v$mystat &&_tpt_version_old where rownum = 1 &&_tpt_version_old ) &&_tpt_version_old ) &&_tpt_version_old ) || '.trc' tracefile, 1 tpt_noprint from v$parameter where name = 'user_dump_dest'; set termout on head on -- SELECT value tracefile FROM v$diag_info WHERE name = 'Default Trace File'; -- this is from from old 9i/10g days... -- -- select value ||'/'||(select instance_name from v$instance) ||'_ora_'|| -- (select spid||case when traceid is not null then '_'||traceid else null end -- from v$process where addr = (select paddr from v$session -- where sid = (select sid from v$mystat -- where rownum = 1 -- ) -- ) -- ) || '.trc' tracefile -- from v$parameter where name = 'user_dump_dest'; set termout on @@loadset prompt New tracefile_identifier = &trc prompt col tracefile print --//理论讲init.sql也存在问题,我下载的版本还是使用旧的模式,我不想修改了,我建议修改为新的方式,毕竟10g以下版本现在很少 --//人用了。 SELECT value tracefile FROM v$diag_info WHERE name = 'Default Trace File';
[20211130]完善tpt t.sql脚本.txt
来源:这里教程网
时间:2026-03-03 17:14:27
作者:
编辑推荐:
- [20211130]完善tpt t.sql脚本.txt03-03
- oracle19c连pdb03-03
- oracle19C技术架构03-03
- oracle打补丁回顾03-03
- 2021 DFA亚洲最具影响力设计奖作品03-03
- [20211130]为什么出现负数.txt03-03
- ORACLE常见视图和表整理03-03
- 被格式化的硬盘文件能恢复吗,三步恢复格式化硬盘03-03
下一篇:
相关推荐
-
雷神推出 MIX PRO II 迷你主机:基于 Ultra 200H,玻璃上盖 + ARGB 灯效
2 月 9 日消息,雷神 (THUNDEROBOT) 现已宣布推出基于英
-
制造商 Musnap 推出彩色墨水屏电纸书 Ocean C:支持手写笔、第三方安卓应用
2 月 10 日消息,制造商 Musnap 现已在海外推出一款 Oce
热文推荐
- oracle打补丁回顾
oracle打补丁回顾
26-03-03 - 2021 DFA亚洲最具影响力设计奖作品
2021 DFA亚洲最具影响力设计奖作品
26-03-03 - 被格式化的硬盘文件能恢复吗,三步恢复格式化硬盘
被格式化的硬盘文件能恢复吗,三步恢复格式化硬盘
26-03-03 - 【ASK_ORACLE】Oracle Data Guard(一)DG架构
【ASK_ORACLE】Oracle Data Guard(一)DG架构
26-03-03 - Oracle:open_cursors
Oracle:open_cursors
26-03-03 - EXCEL不可读怎么办,修复EXCEL文件不可读
EXCEL不可读怎么办,修复EXCEL文件不可读
26-03-03 - goldengate抽取进程延迟90小时
goldengate抽取进程延迟90小时
26-03-03 - 文件夹删除了如何恢复?轻松恢复教学
文件夹删除了如何恢复?轻松恢复教学
26-03-03 - Stefania Infante的超现实色彩的概念性插画
Stefania Infante的超现实色彩的概念性插画
26-03-03 - Oracle:TABLE MONITORING
Oracle:TABLE MONITORING
26-03-03
