免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1460 | 回复: 2
打印 上一主题 下一主题

[求助] 求跟踪sql 语句的方法 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-03-24 16:09 |只看该作者 |倒序浏览
据库是oracle9i,客户端上跑了一个企业的应用程序(无源码),想跟踪软件中某一步所执行的sql语句,该如何做?

架构是c/s/s 就是客户端(java编写),中间件(jboss/tomcat),oracle ,请高手指教,谢谢。

论坛徽章:
0
2 [报告]
发表于 2013-03-26 09:31 |只看该作者
试试v$session

论坛徽章:
0
3 [报告]
发表于 2013-04-02 14:02 |只看该作者
下面是10046 trace的用法 请您参考:
10046 trace
To gather 10046 trace at the session level:

alter session set tracefile_identifier='10046';
alter session set timed_statistics = true;
alter session set statistics_level=all;
alter session set max_dump_file_size = unlimited;
alter session set events '10046 trace name context forever,level 12';
-- Execute the queries or operations to be traced here --
select * from dual;
exit;

If the session is not exited then the trace can be disabled using:
alter session set events '10046 trace name context off';
-----------------------------------------------------------------------------------------------------------

If trace from an existing session is required then oradebug can be used to attach to the session and initiate 10046 tracing.

The first step is to identify the session to be traced by some means:

For example, in SQL*Plus, start a session to find the OS process id (spid) for the target session:

select p.PID,p.SPID,s.SID from v$process p,v$session s where s.paddr = p.addr and s.sid = &SESSION_ID /
SPID is the operating system Process identifier (os pid)
PID is the Oracle Process identifier (ora pid)


Once the OS process id for the process has been determined then the trace can be initialised as follows:

Lets assume that the process to be traced has an os pid of 9834.

Login to SQL*Plus as a dba and execute the following:

connect / as sysdba
oradebug setospid 9834
oradebug unlimit
oradebug event 10046 trace name context forever,level 12
Remember to replace the example '9834' value with the actual os pid.

Note that it is also possible to attach to a session via oradebug using the 'setorapid'.
In this case the PID (Oracle Process identifier ) would be used (rather than the 'SPID') and the oradebug text would change to:

connect / as sysdba
oradebug setorapid 9834
oradebug unlimit
oradebug event 10046 trace name context forever,level 12

Remember to replace the example '9834' value with the actual ora pid.

To disable oradebug tracing once tracing is finished:

oradebug event 10046 trace name context off

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP