①连接到scott下,查询scott对应的sid,serial#
SQL> select sid,serial#,username from v$session where username='SCOTT';
SID SERIAL# USERNAME
---------- ---------- ------------------------------
133 15 SCOTT
②开启对scott用户的跟踪:
SQL>exec dbms_system.set_sql_trace_in_session(133,15,true);
PL/SQL procedure successfully completed.
③在scott下进行操作
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BONUS TABLE
DEPT TABLE
EMP TABLE
SALGRADE TABLE
T1 TABLE
T2 TABLE
T3 TABLE
TEST TABLE
TEST_PAR TABLE
9 rows selected.
SQL> create table dt as select * from dept;
Table created.
④关闭对scott用户的跟踪:
SQL> exec dbms_system.set_sql_trace_in_session(133,15,false);
PL/SQL procedure successfully completed.
⑤查询trace文件的位置:
SQL> select value from v$diag_info where name like 'Default Trace File';
VALUE
--------------------------------------------------------------------------------
/u01/app/oracle/diag/rdbms/ora11gr2/ORA11GR2/trace/ORA11GR2_ora_4264.trc
⑥查看生成的trace文件目录:
[oracle@host02 ~]$ cd /u01/app/oracle/diag/rdbms/ora11gr2/ORA11GR2/trace
[oracle@host02 trace]$ ls -lrt
-rw-r----- 1 oracle oinstall 3290 Oct 17 15:53 ORA11GR2_ora_4318.trm
-rw-r----- 1 oracle oinstall 833329 Oct 17 15:53 ORA11GR2_ora_4318.trc
⑦用tkporf查看生成的trace文件:
[oracle@host02 trace]$ tkprof ORA11GR2_ora_4318.trc trace1
TKPROF: Release 11.2.0.4.0 - Development on Mon Oct 17 16:06:36 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
[oracle@host02 trace]$ ls trace1.prf
trace1.prf
[oracle@host02 trace]$ cat trace1.prf
太大啦,我不粘了。