2.2 使用22923 事件
--具体步骤如下:
1. 设置22923 event trace expdp操作:
SQL> alter system set events '22923 trace nameerrorstack level 3';
2. 执行expdp 命令。
3. 取消22923 event:
SQL> alter system set events '22923trace name errorstack off';
--设置event:
SQL> alter system set events '22923trace name errorstack level 3';
System altered.
--执行expdp:
[Oracle@asm backup]$expdp system/oracle DIRECTORY=backup DUMPFILE=dave.dmp LOGFILE=dave.logTABLES=tianlesoftware
Export: Release 11.2.0.3.0 - Production onMon May 27 20:15:59 2013
Copyright (c) 1982, 2011, Oracle and/or itsaffiliates. All rights reserved.
Connected to: Oracle Database 11gEnterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic StorageManagement, OLAP, Data Mining
and Real Application Testing options
Starting"SYSTEM"."SYS_EXPORT_TABLE_02": system/******** DIRECTORY=backupDUMPFILE=dave.dmp LOGFILE=dave.log TABLES=tianlesoftware
Estimate in progress using BLOCKS method...
Processing object typeTABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 9 MB
Processing object typeTABLE_EXPORT/TABLE/TABLE
Processing object typeTABLE_EXPORT/TABLE/PRE_TABLE_ACTION
. . exported"SYSTEM"."TIANLESOFTWARE" 7.215 MB 74608 rows
Master table "SYSTEM"."SYS_EXPORT_TABLE_02"successfully loaded/unloaded
******************************************************************************
Dump file set forSYSTEM.SYS_EXPORT_TABLE_02 is:
/u01/backup/dave.dmp
Job"SYSTEM"."SYS_EXPORT_TABLE_02" successfully completed at20:16:15
--查看trace,其生成的trace 和我们2.1 节一样。
2个trace 文件在BACKGROUND_DUMP_DEST目录下:
Master Process trace file: <SID>_dm<number>_<process_id>.trc
Worker Process trace file: <SID>_dw<number>_<process_id>.trc
还有一个在USER_DUMP_DEST目录:
Shadow Processtrace file: <SID>_ora_<process_id>.trc
--取消event:
SQL> alter system set events'22923 trace name errorstack off';
System altered.
2.3 使用10046 事件
10046 事件有如下级别:
event 10046, level 1 = enable standardSQL_TRACE functionality
event 10046, level 4 = as level 1, plus trace the BIND values
event 10046, level 8 = as level 1, plus trace the WAITs
event 10046, level 12 = as level 1, plus trace the BIND values and the WAITs
不同级别的使用情况如下:
level 1: lowest level tracing - not alwayssufficient to determine cause of errors;
level 4: useful when an error in DataPump's worker or master process occurs;
level 12: useful when there is an issuewith Data Pump performance.
注意:
当我们设置10046的级别高于8或者12的时候,需要将TIMED_STATISTICS设置为TRUE. 临时的将这个参数设置为true,可以将trace数据性能的影响降到最低。
一般只有遇到性能问题时,才会使用8或者12的level。
[oracle@asm trace]$ orz param timed_statistics
Session altered.
NAME ISDEFAULT SESMO SYSMOD VALUE
------------------- --------- -------------- ----------
timed_statistics TRUE TRUE IMMEDIATE TRUE
在11gR2里,该参数默认为true。
如果不是,调整SQL 如下:
ALTER SYSTEM SET timed_statistics = TRUE SCOPE = memory;
ALTER SYSTEM SET timed_statistics = FALSE SCOPE = memory;
2.3.1 在数据库级别设置
可能的expdp/impdp 异常循序结束了,这时候我们就没有办法根据进程进行信息的捕捉。因此为了分析,可能就需要重新运行一次,这时候就可以在数据库级别设置10046事件。
--设置:
CONNECT / as sysdba
ALTER SYSTEM SET EVENTS '10046 trace name context forever, level 4';
注意: 在数据库级别设置,会trace所有进程。 所以在生产系统慎用,除非有停机窗口,否则会影响系统性能。
--启动Export/Impdp:
[oracle@asm backup]$ expdp system/oracleDIRECTORY=backup DUMPFILE=dave.dmp LOGFILE=dave.log TABLES=tianlesoftware
--在数据泵完成后,立即取消10046的设置:
ALTER SYSTEM SET EVENTS '10046 trace name context off';
2.3.2 对当前正在运行的数据泵进程进行10046 trace
2.3.2.1 查看expdp进程
--进行expdp:
[oracle@asm trace]$ expdp system/oracleDIRECTORY=backup DUMPFILE=dave.dmp LOGFILE=dave.log TABLES=tianlesoftware
Export: Release 11.2.0.3.0 - Production onMon May 27 20:56:52 2013
Copyright (c) 1982, 2011, Oracle and/or itsaffiliates. All rights reserved.
Connected to: Oracle Database 11gEnterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic StorageManagement, OLAP, Data Mining
and Real Application Testing options
Starting"SYSTEM"."SYS_EXPORT_TABLE_02": system/******** DIRECTORY=backupDUMPFILE=dave.dmp LOGFILE=dave.log TABLES=tianlesoftware
Estimate in progress using BLOCKS method...
Processing object typeTABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 9 MB
Processing object typeTABLE_EXPORT/TABLE/TABLE
Processing object typeTABLE_EXPORT/TABLE/PRE_TABLE_ACTION
--查看数据泵进程的信息:
set lines 150 pages 100 numwidth 7
col username for a10
col spid for a7
SQL> col program for a25
SQL> select to_char(sysdate,'YYYY-MM-DDHH24:MI:SS') "DATE", s.program, s.sid,
s.status, s.username, d.job_name, p.spid, s.serial#, p.pid
2 3 from v$session s, v$process p,dba_datapump_sessions d
4 where p.addr=s.paddr ands.saddr=d.saddr;
DATE PROGRAM SID STATUS USERNAME JOB_NAME SPID SERIAL# PID
------------------- --------------------- ------- -------- ---------------------------------- ------- ------- -------
2013-05-27 20:59:30 oracle@asm (DW00) 23 ACTIVE SYSTEM SYS_EXPORT_TABLE_02 8173 311 23
2013-05-27 20:59:30 oracle@asm (DM00) 58 ACTIVE SYSTEM SYS_EXPORT_TABLE_02 8171 85 36
2013-05-27 20:59:30 ude@asm (TNS V1-V3) 22 ACTIVE SYSTEM SYS_EXPORT_TABLE_02 8167 1077 34
2.3.2.2 使用sys.dbms_system.set_ev设置10046
在上节的查询结果里:
Data Pump Master process (DM00)的SID 是58,serial#是85.
Data Pump Worker process (DW01)的SID 是23,serial#是311.
使用10046 跟踪活动session的语法如下:
Syntax: DBMS_SYSTEM.SET_EV([SID],[SERIAL#],[EVENT],[LEVEL],'')
--在level 4跟踪Worker process进程(Bind values):
execute sys.dbms_system.set_ev(23,311,10046,4,'');
-- stop tracing:
execute sys.dbms_system.set_ev(23,311,10046,0,'');
--在level 8 跟踪Master进程(Waits):
execute sys.dbms_system.set_ev(143,50,10046,8,'');
-- stop tracing:
execute sys.dbms_system.set_ev(143,50,10046,0,'');
2.3.2.3 使用oradebug 设置10046
上节使用的是SQL中操作,其实用oradebug操作更方便。
可以在oradebug中设置SPID,来进行trace:
--在level 4跟踪Worker process进程(Bind values):
oradebug setospid 8173
oradebug unlimit
oradebug event 10046 trace name context forever, level 4
oradebug tracefile_name
--在level 8 跟踪Master进程(Waits):
oradebug setospid 8171
oradebug unlimit
oradebug event 10046 trace name context forever, level 8
oradebug tracefile_name
--stop tracing:
oradebug event 10046 trace name context off
2.3.2.4 使用tkprof 分析trace文件
10046 生成的trace 文件可读性并不好,所有我们可以使用tkprof工具进行格式化,方便阅读。
如:
$ tkprof orcl_dm00_17292.trctkprof_orcl_dm00_17292.out waits=y sort=exeela
$ tkprof orcl_dw01_17294.trctkprof_orcl_dw01_17294.out waits=y sort=exeela
[oracle@asm dave]$ tkprof
Usage: tkprof tracefile outputfile[explain= ] [table= ]
[print= ] [insert= ] [sys= ][sort= ]
table=schema.tablename Use'schema.tablename' with 'explain=' option.
explain=user/password Connectto ORACLE and issue EXPLAIN PLAN.
print=integer List only the first 'integer' SQLstatements.
aggregate=yes|no
insert=filename List SQLstatements and data inside INSERT statements.
sys=no TKPROF does notlist SQL statements run as user SYS.
record=filename Record non-recursivestatements found in the trace file.
waits=yes|no Record summaryfor any wait events found in the trace file.
sort=option Set of zero ormore of the following sort options:
prscnt number of times parse wascalled
prscpu cpu time parsing
prsela elapsed time parsing
prsdsk number of disk readsduring parse
prsqry number of buffers forconsistent read during parse
prscu number of buffers forcurrent read during parse
prsmis number of misses inlibrary cache during parse
execnt number of execute wascalled
execpu cpu time spent executing
exeela elapsed time executing
exedsk number of disk readsduring execute
exeqry number of buffers forconsistent read during execute
execu number of buffers forcurrent read during execute
exerow number of rows processedduring execute
exemis number of library cachemisses during execute
fchcnt number of times fetch wascalled
fchcpu cpu time spent fetching
fchela elapsed time fetching
fchdsk number of disk readsduring fetch
fchqry number of buffers forconsistent read during fetch
fchcu number of buffers forcurrent read during fetch
fchrow number of rows fetched
userid userid of user that parsedthe cursor
更多内容参考:
Oracle SQLTrace 和 10046 事件 http://www.linuxidc.com/Linux/2013-06/85233.htm
更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12
