http://blog.itpub.net/16832682/viewspace-1249765/
最近因为项目上出现了PL/SQL性能的问题,因此需要对已经开发好的并发程序进行调优的工作。调优有个很重要的步骤就是获取并发程序的trace file,从而才能知道是哪一段SQL出现了问题。
下面就针对如何获取并发程序的trace file做个归纳:
1.在并发程序注册页面启动跟踪功能;
2.提交并发,待并发跑完之后获取trace ID,可以用如下代码来完成:
SELECT ‘Request id: ‘ || Request_Id,
‘Trace id: ‘ || Oracle_Process_Id,
‘Trace Flag: ‘ || Req.Enable_Trace,
‘Trace Name:‘ || Dest.Value || ‘/‘ || Lower(Dbnm.Value) || ‘_ora_‘ || Oracle_Process_Id || ‘_ANONYMOUS.trc‘,
‘Prog. Name: ‘ || Prog.User_Concurrent_Program_Name,
‘File Name: ‘ || Execname.Execution_File_Name || Execname.Subroutine_Name,
‘Status : ‘ || Decode(Phase_Code, ‘R‘, ‘Running‘) || ‘-‘ ||
Decode(Status_Code, ‘R‘, ‘Normal‘),
‘SID Serial: ‘ || Ses.Sid || ‘,‘ || Ses.Serial#,
‘Module : ‘ || Ses.Module
FROM Fnd_Concurrent_Requests Req,
V$session Ses,
V$process Proc,
V$parameter Dest,
V$parameter Dbnm,
Fnd_Concurrent_Programs_Vl Prog,
Fnd_Executables Execname
WHERE Req.Request_Id = &REQUEST_ID
AND Req.Oracle_Process_Id = Proc.Spid(+)
AND Proc.Addr = Ses.Paddr(+)
AND Dest.Name = ‘user_dump_dest‘
AND Dbnm.Name = ‘db_name‘
AND Req.Concurrent_Program_Id = Prog.Concurrent_Program_Id
AND Req.Program_Application_Id = Prog.Application_Id
AND Prog.Application_Id = Execname.Application_Id
AND Prog.Executable_Id = Execname.Executable_Id
在sql执行完获取Trace Name列的值,进入对应目录下:
3.利用tkprof文件解析trc文件:
tkprof erpprd_ora_10481_2510.trc /tmp/2510.trc
4.用Filezilla等FTP工具登陆到对应的目录下,并将生成的tkp文件down到本地
5.用记事本或者Notepad++等文档编辑工具打开下载下来的tkp文件:
最后的事情,那就是一句句的查看sql,看具体哪一段sql消耗比较大。