1. sys用户给管理用户授权。
SQL> grant execute on sys.dbms_system to andy;Grant succeeded.2. 查询被跟踪用户的sid,serial# SQL> select sid,serial# from v$session where username='DBLINK'; SID SERIAL#---------- ----------31 73. 管理用户andy开始跟踪dblink用户SQL> exec sys.dbms_system.set_sql_trace_in_session(31,7,true);PL/SQL procedure successfully completed.4. dblink被跟踪用户执行测试语句。SQL> select * from user_tables;5. 跟踪结束SQL> exec sys.dbms_system.set_sql_trace_in_session(31,7,false);PL/SQL procedure successfully completed.6. dblink用户查询自己当前trace文件号SQL> select * from v$diag_info where name like 'Default%'; INST_ID NAME---------- ----------------------------------------------------------------VALUE--------------------------------------------------------------------------------1 Default Trace File/home/oracle/app/diag/rdbms/orcl/orcl/trace/orcl_ora_3524.trc7. 用tkprof工具生成查看文件[oracle@11g ~]$ tkprof /home/oracle/app/diag/rdbms/orcl/orcl/trace/orcl_ora_3524.trc andy2.txt sys=noTKPROF: Release 11.2.0.1.0 - Development on Mon Nov 17 16:48:38 2014Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.8. 查看跟踪记录[oracle@11g ~]$ cat andy2.txtTKPROF: Release 11.2.0.1.0 - Development on Mon Nov 17 16:48:38 2014Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.Trace file: /home/oracle/app/diag/rdbms/orcl/orcl/trace/orcl_ora_3524.trcSort options: default********************************************************************************count = number of times OCI procedure was executedcpu = cpu time in seconds executing elapsed = elapsed time in seconds executingdisk = number of physical reads of buffers from diskquery = number of buffers gotten for consistent readcurrent = number of buffers gotten in current mode (usually for update)rows = number of rows processed by the fetch or execute call********************************************************************************SQL ID: dtbhjabjx3v1uPlan Hash: 4102440123select * from <-- #刚执行sql找到 user_tables call count cpu elapsed disk query current rows------- ------ -------- ---------- ---------- ---------- ---------- ----------Parse 1 0.09 0.10 0 0 0 0Execute 1 0.00 0.00 0 0 0 0Fetch 2 0.11 0.31 174 1390 0 1------- ------ -------- ---------- ---------- ---------- ---------- ----------total 4 0.21 0.41 174 1390 0 1。。。。省略输出。 OK,结束。 转载请标明出处