SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Productio
NLSRTL Version 10.2.0.4.0 - Production
SQL> alter session set events '10046 trace name context forever, level 12';
ERROR:
ORA-01031: insufficient privileges
设置10046事件时出现了ORA-01031: insufficient privileges
给用户授予alter session 的权限,试试
SQL> conn / as sysdba
Connected.
SQL> grant alter session to user;
Grant succeeded.
SQL> conn user/password
Connected.
SQL> select * from v$mystat where rownum=1;
SID STATISTIC# VALUE
---------- ---------- ----------
445 0 1
--在session级别开启10046 Event
SQL> alter session set events '10046 trace name context forever, level 12';
会话已更改。
SQL> set timing on;
SQL> select count(policyno) as sumcount
2 from Prpjinvoiceloan
3 Where SettleType = '0'
4 AND PayRefDate IS Null
5 AND PRINTERCODE = '3300112003';
SUMCOUNT
----------
0
已用时间: 00: 00: 00.29
--关闭10046 Event
SQL> alter session set events '10046 trace name context off';
会话已更改。
已用时间: 00: 00: 00.01
--查询生产trace文件的路径
SQL> select d.value || '/' || lower(rtrim(i.instance, chr(0))) || '_ora_' || 2 p.spid || '.trc' trace_file_name 3 from (select p.spid 4 from v$mystat m, v$session s, v$process p 5 where m.statistic# = 1 6 and s.sid = m.sid and p.addr = s.paddr) p, 7 (select t.instance 8 from v$thread t, v$parameter v 9 where v.name = 'thread' 10 and (v.value = 0 or t.thread# = to_number(v.value))) i, 11 (select value from v$parameter where name = 'user_dump_dest') d;
TRACE_FILE_NAME
--------------------------------------------------------------------------------
/oracle/app/admin/ca561dev/udump/ca561dev_ora_1712218.trc
已用时间: 00: 00: 00.23
SQL> exit
--为了方便阅读,使用oracle自带的tkprof格式化trace文件
/oracle/app/admin/ca561dev/udump$tkprof ca561dev_ora_1712218.trc 2.txt aggregate=no explain=user/password
--查看格式化后的文件
/oracle/app/admin/ca561dev/udump$ more 2.txt
。。。省略部分信息。。。
********************************************************************************
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
--------------------------------------------------------------------------------
*** SESSION ID:(445.18365) 2010-11-18 16:00:26.300
********************************************************************************
select count(policyno) as sumcount
from Prpjinvoiceloan
Where SettleType = '0'
AND PayRefDate IS Null
AND PRINTERCODE = '3300112003'
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.01 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 0.01 0.25 615 615 0 1
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 4 0.01 0.26 615 615 0 1