1.1 开启session sql trace
 alter session set tracefile_identifier='10046';
 alter session set timed_statistics = true;      --默认是true
 alter session set statistics_level=all;               --实例级别设置需要注意,会消耗大量的CPU
 alter session set max_dump_file_size = unlimited;       --默认是unlimited
 alter session set events '10046 trace name context forever,level 12'; --常用的级别是12
1.2 执行要trace的SQL
 select * from scott.dept;
 select empno from scott.emp where empno=7900;
1.3 关闭session sql trace
 alter session set events '10046 trace name context off';
 或者直接退出session
 exit
1.4 查看session sql trace路径
 select tracefile from v$process where addr=(select paddr from v$session where sid=(select distinct sid from v$mystat));
 或者show parameter user_dump_dest ;
 [root@vm01 trace]# cat ora11g_ora_2826_10046.trc
 Trace file /u01/app/oracle/diag/rdbms/ora11g/ora11g/trace/ora11g_ora_2826_10046.trc
 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
 With the Partitioning, OLAP, Data Mining and Real Application Testing options
 ORACLE_HOME = /u01/app/oracle/product/11.2.4/db_1
 System name:    Linux
 Node name:    vm01
 Release:    3.10.0-514.el7.x86_64
 Version:    #1 SMP Tue Nov 22 16:42:41 UTC 2016
 Machine:    x86_64
 Instance name: ora11g
 Redo thread mounted by this instance: 1
 Oracle process number: 19
 Unix process pid: 2826, image: oracle@vm01 (TNS V1-V3)
 *** 2022-03-09 19:08:13.385
 *** SESSION ID:(191.11) 2022-03-09 19:08:13.385
 *** CLIENT ID:() 2022-03-09 19:08:13.385
 *** SERVICE NAME:(SYS$USERS) 2022-03-09 19:08:13.385
 *** MODULE NAME:(sqlplus@vm01 (TNS V1-V3)) 2022-03-09 19:08:13.385
 *** ACTION NAME:() 2022-03-09 19:08:13.385
  
 WAIT #140627976109008: nam='SQL*Net message to client' ela= 0 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1646870893385083
*** 2022-03-09 19:09:52.920
 WAIT #140627976109008: nam='SQL*Net message from client' ela= 99534982 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1646870992920316
 CLOSE #140627976109008:c=0,e=11,dep=0,type=1,tim=1646870992920377
 =====================
 PARSING IN CURSOR #140627976103496 len=44 dep=0 uid=0 oct=3 lid=0 tim=1646870992921728 hv=3324433311 ad='eade38c0' sqlid='9vzm5yg32dnwz'
 select empno from scott.emp where empno=7900
 END OF STMT
 PARSE #140627976103496:c=1087,e=1329,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,plh=56244932,tim=1646870992921727
 EXEC #140627976103496:c=32,e=31,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=56244932,tim=1646870992921809
 WAIT #140627976103496: nam='SQL*Net message to client' ela= 1 driver id=1650815232 #bytes=1 p3=0 obj#=-1 tim=1646870992921832
 WAIT #140627976103496: nam='Disk file operations I/O' ela= 36 FileOperation=2 fileno=4 filetype=2 obj#=87109 tim=1646870992921928
 WAIT #140627976103496: nam='db file sequential read' ela= 16 file#=4 block#=155 blocks=1 obj#=87109 tim=1646870992921955
 FETCH #140627976103496:c=156,e=156,p=1,cr=1,cu=0,mis=0,r=1,dep=0,og=1,plh=56244932,tim=1646870992922002
 STAT #140627976103496 id=1 cnt=1 pid=0 pos=1 obj=87109 op='INDEX UNIQUE SCAN PK_EMP (cr=1 pr=1 pw=0 time=163 us cost=0 size=4 card=1)'
 WAIT #140627976103496: nam='SQL*Net message from client' ela= 101 driver id=1650815232 #bytes=1 p3=0 obj#=87109 tim=1646870992922157
 FETCH #140627976103496:c=2,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,plh=56244932,tim=1646870992922173
 WAIT #140627976103496: nam='SQL*Net message to client' ela= 0 driver id=1650815232 #bytes=1 p3=0 obj#=87109 tim=1646870992922183
*** 2022-03-09 19:12:41.496
 WAIT #140627976103496: nam='SQL*Net message from client' ela= 168574494 driver id=1650815232 #bytes=1 p3=0 obj#=87109 tim=1646871161496696
 CLOSE #140627976103496:c=4,e=4,dep=0,type=0,tim=1646871161496749
 =====================
 PARSING IN CURSOR #140627976103496 len=55 dep=0 uid=0 oct=42 lid=0 tim=1646871161496842 hv=2217940283 ad='0' sqlid='06nvwn223659v'
 alter session set events '10046 trace name context off'
 END OF STMT
 PARSE #140627976103496:c=67,e=67,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,plh=0,tim=1646871161496841
 EXEC #140627976103496:c=188,e=189,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,plh=0,tim=1646871161497054
 [root@vm01 trace]#