转载-Oracle 常用的dump命令

Oracle 跟踪事件 set event

http://blog.csdn.net/tianlesoftware/archive/2009/12/10/4977827.aspx

 

 

事件 说明 例子
Event 10013 - Monitor Transaction Recovery 在Startup时跟踪事务恢复 ALTER SESSION SET EVENTS '10013 trace name context forever, level 1';
Event 10015 - Dump Undo Segment Headers- 在事务恢复后做Dump回退段头信息 ALTER SESSION SET EVENTS '10015 trace name context forever, level 1';
Event 10032 - Dump Sort Statistics Dump排序的统计信息 ALTER SESSION SET EVENTS '10032 trace name context forever, level 10';
Event 10033 - Dump Sort Intermediate Run Statistics 排序过程中,内存排序区和临时表空间的交互情况 ALTER SESSION SET EVENTS '10033 trace name context forever, level 10';
Event 10045 - Trace Free List Management Operations FREELIST的管理操作 ALTER SESSION SET EVENTS '10045 trace name context forever, level 1';
Event 10046 - Enable SQL Statement Trace 跟踪SQL,有执行计划,邦定变量和等待的统计信息,level 12最详细。 ALTER SESSION SET EVENTS '10046 trace name context forever, level 12';
LEVEL定义如下:
1:SQL 语句,执行计划和执行状态
4:1的内容加上绑定变量信息
8:1的信息加上等待事件信息
12:1+4+8
Event 10053 - Dump Optimizer Decisions 在分析SQL语句时,Dump出优化器所做的选择,级别level 1最详细 ALTER SESSION SET EVENTS '10053 trace name context forever, level 1';
LEVEL定义如下:
1:状态和估算信息
2:只显示估算信息
Event 10060 - Dump Predicates DUMP SQL语句中的断语信息。需要在需要DUMP的用户下创建以下表
CREATE TABLE kkoipt_table
(c1 INTEGER,
c2 VARCHAR2(80));
断语信息会写入该表
CREATE TABLE kkoipt_table
(c1 INTEGER,
c2 VARCHAR2(80));
断语信息会写入该表
ALTER SESSION SET EVENTS '10060 trace name context forever, level 1';
Event 10065 - Restrict Library Cache Dump Output for State Object Dumps 限制对象状态DUMP的时候LIBRARY CACHE信息的详细程度 ALTER SESSION SET EVENTS '10065 trace name context forever, level level';
Event 10079 - Dump SQL*Net Statistics- Dump SQL*NeT的统计信息 ALTER SESSION SET EVENTS '10079 trace name context forever, level 2';
Event 10081 - Trace High Water Mark Changes HWM的改变 ALTER SESSION SET EVENTS '10081 trace name context forever, level 1';
Event 10104 - Dump Hash Join Statistics HASH JOIN的统计信息 ALTER SESSION SET EVENTS '10104 trace name context forever, level 10';
Event 10128 - Dump Partition Pruning Information 分区表调整信息 ALTER SESSION SET EVENTS '10128 trace name context forever, level level';
Level取值:
1   Dump pruning descriptor for each partitioned object
0x0002 Dump partition iterators
0x0004 Dump optimizer decisions about partition-wise joins
0x0008 Dump ROWID range scan pruning information
在9.0.1或者后面的版本,在level 2后还需要建立如下的表:
CREATE TABLE kkpap_pruning
(
partition_count    NUMBER,
iterator           VARCHAR2(32),
partition_level    VARCHAR2(32),
order_pt         VARCHAR2(12),
call_time        VARCHAR2(12),
part#             NUMBER,
subp#              NUMBER,
abs#               NUMBER
);
Event 10200 - Dump Consistent Reads DUMP一致读的信息 ALTER SESSION SET EVENTS '10200 trace name context forever, level 1';
Event 10201 - Dump Consistent Read Undo Application DUMP一致性读涉及UNDO信息的内容 ALTER SESSION SET EVENTS '10201 trace name context forever, level 1';
Event 10220 - Dump Changes to Undo Header Dump出Undo头信息的改变 ALTER SESSION SET EVENTS '10220 trace name context forever, level 1';
Event 10221 - Dump Undo Changes Dump Undo的改变 ALTER SESSION SET EVENTS '10221 trace name context forever, level 7';
Event 10224 - Dump Index Block Splits / Deletes 索引块的分裂和D删除信息 ALTER SESSION SET EVENTS '10224 trace name context forever, level 1';
Event 10225 - Dump Changes to Dictionary Managed Extents DUMP字段管理的扩展变化 ALTER SESSION SET EVENTS '10225 trace name context forever, level 1';
Event 10231 全表扫描时跳过坏块,在有坏块的情况下做数据拯救时很有用 ALTER SYSTEM SET EVENTS '10231 trace name context forever,level 10';
Event 10241 - Dump Remote SQL Execution 远程SQL语句的执行信息 ALTER SESSION SET EVENTS '10241 trace name context forever, level 1';
Event 10246 - Trace PMON Process 跟踪PMON进程 只能修改参数,不能用ALTER SYSTEM
event = "10246 trace name context forever, level 1"
Event 10248 - Trace Dispatcher Processes 跟踪DISPATCHER的工作情况        event = "10248 trace name context forever, level 10"
Event 10249 - Trace Shared Server (MTS) Processes- 跟踪共享服务器的工作情况 event = "10249 trace name context forever, level 10"
Event 10270 - Debug Shared Cursors 跟踪共享CURSORS的情况 event = "10270 trace name context forever, level 10"
Event 10299 - Debug Prefetching 跟踪表数据块和索引数据块的PREFETCHING event = "10299 trace name context forever, level 1"
Event 10357 - Debug Direct Path ALTER SESSION SET EVENTS '10357 trace name context forever, level 1';
Event 10390 - Dump Parallel Execution Slave Statistics 跟踪并行操作中的SLAVE的状态 ALTER SESSION SET EVENTS '10390 trace name context forever, level 1;
Event 10391-Dump Parallel Execution Granule Allocation 跟踪并行操作的粒度 ALTER SESSION SET EVENTS '10391 trace name context forever, level 2';
Event 10393 - Dump Parallel Execution Statistics 跟踪并行操作的状态(每个SLAVE单独列出状态) ALTER SESSION SET EVENTS '10393 trace name context forever, level 1';
Event 10500 - Trace SMON Process 跟踪SMON进程 event = "10500 trace name context forever, level 1"
Event 10608 - Trace Bitmap Index Creation 跟踪BITMAP索引创建的详细过程 ALTER SESSION SET EVENTS '10608 trace name context forever, level 10';
Event 10704 - Trace Enqueues 跟踪锁的使用情况 ALTER SESSION SET EVENTS '10704 trace name context forever, level 1';
Event 10706 - Trace Global Enqueue Manipulation 跟踪全局锁的使用情况 ALTER SESSION SET EVENTS '10706 trace name context forever, level 1';
Event 10708 - Trace RAC Buffer Cache 跟踪RAC环境下的BUFFER CACHE ALTER SESSION SET EVENTS '10708 trace name context forever, level 10';
Event 10710 - Trace Bitmap Index Access 跟踪位图索引的访问情况 ALTER SESSION SET EVENTS '10710 trace name context forever, level 1';
Event 10711 - Trace Bitmap Index Merge Operation 跟踪位图索引合并操作 ALTER SESSION SET EVENTS '10711 trace name context forever, level 1';
Event 10712 - Trace Bitmap Index OR Operation 跟踪位图索引或操作情况 ALTER SESSION SET EVENTS '10712 trace name context forever, level 1';
Event 10713 - Trace Bitmap Index AND Operation 跟踪位图索引与操作 ALTER SESSION SET EVENTS '10713 trace name context forever, level 1';
Event 10714 - Trace Bitmap Index MINUS Operation 跟踪位图索引minus操作 ALTER SESSION SET EVENTS '10714 trace name context forever, level 1';
Event 10715 - Trace Bitmap Index Conversion to ROWIDs Operation 跟踪位图索引转换ROWID操作 ALTER SESSION SET EVENTS '10715 trace name context forever, level 1';
Event 10716 - Trace Bitmap Index Compress/Decompress 跟踪位图索引压缩和解压缩情况 ALTER SESSION SET EVENTS '10716 trace name context forever, level 1';
Event 10717 - Trace Bitmap Index Compaction ALTER SESSION SET EVENTS '10717 trace name context forever, level 1';
Event 10719 - Trace Bitmap Index DML 跟踪位图索引列的DML操作(引起位图索引改变的DML操作) ALTER SESSION SET EVENTS '10719 trace name context forever, level 1';
Event 10730 - Trace Fine Grained Access Predicates 跟踪细粒度审计的断语 ALTER SESSION SET EVENTS '10730 trace name context forever, level 1';
Event 10731 - Trace CURSOR Statements 跟踪CURSOR的语句情况 ALTER SESSION SET EVENTS '10731 trace name context forever, level level';
LEVEL定义
1     Print parent query and subquery
2     Print subquery only
Event 10928 - Trace PL/SQL Execution 跟踪PL/SQL执行情况 ALTER SESSION SET EVENTS '10928 trace name context forever, level 1';
Event 10938 - Dump PL/SQL Execution Statistics 跟踪PL/SQL执行状态。使用前需要执行rdbms/admin下的tracetab.sql ALTER SESSION SET EVENTS '10938 trace name context forever, level 1';
flush_cache 刷新BUFFER CACHE ALTER SESSION SET EVENTS 'immediate trace name flush_cache';
DROP_SEGMENTS 手工删除临时段。当这些临时段无法自动清除的时候可以手工清除 alter session set events 'immediate trace name DROP_SEGMENTS level ts#+1';
ts#是指要删除临时段的表空间的ts#

.Memory Dumps

1).Global Area
ALTER SESSION SET EVENTS ‘immediate trace name global_area level n’;
1 包含PGA
2 包含SGA
4 包含UGA
8 包含indrect memory

 

2).Library Cache
ALTER SESSION SET EVENTS ‘immediate trace name library_cache level n’;
1 library cache统计信息
2 包含hash table histogram
3 包含object handle
4 包含object结构(Heap 0)

 

3).Row Cache
ALTER SESSION SET EVENTS ‘immediate trace name row_cache level n’;
1 row cache统计信息
2 包含hash table histogram
8 包含object结构

 

4).Buffers
ALTER SESSION SET EVENTS ‘immediate trace name buffers level n’;
1 buffer header
2 level 1 + block header
3 level 2 + block contents
4 level 1 + hash chain
5 level 2 + hash chain
6 level 3 + hash chain
8 level 4 + users/waiters
9 level 5 + users/waiters
10 level 6 + users/waiters

 

5).Buffer
ALTER SESSION SET EVENTS ‘immediate trace name buffer level n’;
n为某个指定block的rdba,该命令可以转储某个block在buffer中的所有版本。

 

6).Heap
ALTER SESSION SET EVENTS ‘immediate trace name heapdump level level’;
1 PGA摘要
2 SGA摘要
4 UGA摘要
8 Current call(CGA)摘要
16 User call(CGA)摘要
32 Large call(LGA)摘要
1025 PGA内容
2050 SGA内容
4100 UGA内容
8200 Current call内容
16400 User call内容
32800 Large call内容

 

7).Sub Heap
Oracle 9.0.1版本之前
ALTER SESSION SET EVENTS ‘immediate trace name heapdump_addr level n’;
若n为subheap的地址,转储的是subheap的摘要信息
若n为subheap的地址+1,转储的则是subheap的内容
Oracle 9.2.0版本之后
ALTER SESSION SET EVENTS ‘immediate trace name heapdump_addr level n, addr m’;
其中m为subheap的地址
n为1转储subheap的摘要,n为2转储subheap的内容

 

8).Process State
ALTER SESSION SET EVENTS ‘immediate trace name processstate level n’;

 

9).System State
ALTER SESSION SET EVENTS ‘immediate trace name systemstate level n’;

 

10).Error State
ALTER SESSION SET EVENTS ‘immediate trace name errorstack level n’;
0 Error stack
1 level 0 + function call stack
2 level 1 + process state
3 level 2 + context area


11).Hang Analysis
ALTER SESSION SET EVENTS ‘immediate trace name hanganalyze level n’;

 

12).Work Area
ALTER SESSION SET EVENTS ‘immediate trace name workareatab_dump level n’;
1 SGA信息
2 Workarea Table摘要信息
3 Workarea Table详细信息

 

13).Latches
ALTER SESSION SET EVENTS ‘immediate trace name latches level n’;
1 latch信息
2 统计信息

 

14).Events
ALTER SESSION SET EVENTS ‘immediate trace name events level n’;
1 session
2 process
3 system

 

15).Locks
ALTER SESSION SET EVENTS ‘immediate trace name locks level n’;

 

16).Shared Server Process
ALTER SESSION SET EVENTS ‘immediate trace name shared_server_state level n’;
n取值为1~14

 

17).Background Messages
ALTER SESSION SET EVENTS ‘immediate trace name bg_messages level n’;
n为pid+1

 

.File Dumps

1).Block
Oracle 7之前
ALTER SESSION SET EVENTS ‘immediate trace name blockdump level n’;
n为block的rdba
Oracle8以后
ALTER SYSTEM DUMP DATAFILE file# BLOCK block#;
ALTER SYSTEM DUMP DATAFILE file#
BLOCK MIN minimum_block#
BLOCK MAX maximum_block#;

 

2).Tree Dump
ALTER SESSION SET EVENTS ‘immediate trace name treedump level n’;
n为object_id

 

3).Undo Segment Header
ALTER SYSTEM DUMP UNDO_HEADER ’segment_name’;

 

4).Undo for a Transaction
ALTER SYSTEM DUMP UNDO BLOCK ’segment_name’ XID xidusn xidslot xidsqn;

 

5).File Header
ALTER SESSION SET EVENTS ‘immediate trace name file_hdrs level n’;
1 控制文件中的文件头信息
2 level 1 + 文件头信息
3 level 2 + 数据文件头信息
10 level 3

 

6).Control file
ALTER SESSION SET EVENTS ‘immediate trace name controlf level n’;
1 文件头信息
2 level 1 + 数据库信息 + 检查点信息
3 level 2 + 可重用节信息
10 level 3

 

7).Redo log Header
ALTER SESSION SET EVENTS ‘immediate trace name redohdr level n’;
1 控制文件中的redo log信息
2 level 1 + 文件头信息
3 level 2 + 日志文件头信息
10 level 3

 

8).Redo log
ALTER SYSTEM DUMP LOGFILE ‘FileName’;
ALTER SYSTEM DUMP LOGFILE ‘FileName’
SCN MIN MinimumSCN
SCN MAX MaximumSCN
TIME MIN MinimumTime
TIME MAX MaximumTime
LAYER Layer
OPCODE Opcode
DBA MIN FileNumber . BlockNumber
DBA MAX FileNumber . BlockNumber
RBA MIN LogFileSequenceNumber . BlockNumber
RBA MAX LogFileSequenceNumber . BlockNumber;
其中time = (((((yyyy – 1988)) * 12 + mm – 1) * 31 + dd – 1) * 24 + hh) * 60 + mi) * 60 + ss;

 

9).Loghist
ALTER SESSION SET EVENTS ‘immediate trace name loghist level n’;
1 dump控制文件中最早和最迟的日志历史项
1 dump 2^n个日志历史项

 

三, Trace 文件使用示例

 

udump下的trc文件可以通过配置不让产生,利用命令
alter system set sql_trace=false;

其他的不能修改,只能手动的启动trace,手动的关闭trace.

 

比如:

alter session set events 'immediate trace name library_cache|controlf|systemstate|processstate|file_hdrs|REDOHDR level 10';

alter session set events 'immediate trace name off';

 

alter session set events '10046 trace name context forever,level 12';
alter session set events '10046 trace name context off';

 

alter system set events '10046 trace name context forever,level 12';
alter system set events '10046 trace name context off';

 

 

 

1. 使用autotrace
set autotrace ON | ON EXPLAIN | ON STATISTICS | TRACEONLY | TRACEONLY EXPLAIN
set autotrace off

这个用法是最简单方便的,执行sql结束之后,会自动在同个窗口显示sql的执行计划和统计信息。

 

2. 使用set events context

SQL> alter session set sql_trace=true;
SQL> alter session set sql_trace=false;

属于当前session级设置

大多数的情况下,我们使用sql_trace跟踪当前进程。通过跟踪当前进程可以发现当前操作的后台数据库递归活动(这在研究数据库新特性时尤其有效),研究SQL执行,发现后台错误等。

 

alter session set events '10046 trace name context forever,level 12';
alter session set events '10046 trace name context off';

10046事件概述:

10046事件是Oracle提供的内部事件,是对SQL_TRACE的增强.

10046事件可以设置以下四个级别:

1 - 启用标准的SQL_TRACE功能,等价于sql_trace

4 - Level 1 加上绑定值(bind values)

8 - Level 1 + 等待事件跟踪

12 - Level 1 + Level 4 + Level 8

类似sql_trace,10046事件可以在全局设置,也可以在session级设置。

 

3. 使用set events immediate
alter session set events 'immediate trace name library_cache|controlf|systemstate|processstate|file_hdrs|REDOHDR level 10';
alter session set events 'immediate trace name off';

Level =1 ,转储Library cache统计信息
Level =2 ,转储hash table概要
Level =4 ,转储Library cache对象,只包含基本信息
Level =8 ,转储Library cache对象,包含详细信息(包括child references,pin waiters等)
Level =16,增加heap sizes信息
Level =32,增加heap信息

 

9i清理buffer cache
   alter session set events 'immediate trace name flush_cache level 1';

   alter session set events = 'immediate trace name flush_cache'

 

4. 使用set events errorstack
alter session set events 'err_num trace name errorstack level 10';
alter session set events 'err_num trace name errorstack off'

err_num=报错代码,如ORA-00942 应该在err_num填入942

 

5. 使用dbms_support(trace别的session)
exec dbms_support.start_trace_in_session(sid=>XX,seiral#=>XXX,wait=>true,binds=>true);
exec dbms_support.stop_trace_in_session(sid=>XX,seiral#=>XXX);

这类trace用到很少,以后再研究。

 

6. 使用oradebug(trace别的session)
oradebug setospid (PID 能从ps -ef 中得出)
oradebug unlimit
oradebug event 10046 trace name context forever,level 12;
oradebug event 10046 trace name context off;

这类同样用到很少。

 

7. 使用dbms_system.set_ev
exec dbms_system.set_ev(sid,serial#,10046,trace_level,'username');
exec dbms_system.set_ev(sid,serial#,10046,0,'username');

通过DBMS_SYSTEM.SET_EV系统包来实现对sql的跟踪

Oracle 跟踪事件 set event

http://blog.csdn.net/tianlesoftware/archive/2009/12/10/4977827.aspx

 

 

.Memory Dumps

1).Global Area
ALTER SESSION SET EVENTS ‘immediate trace name global_area level n’;
1 包含PGA
2 包含SGA
4 包含UGA
8 包含indrect memory

 

2).Library Cache
ALTER SESSION SET EVENTS ‘immediate trace name library_cache level n’;
1 library cache统计信息
2 包含hash table histogram
3 包含object handle
4 包含object结构(Heap 0)

 

3).Row Cache
ALTER SESSION SET EVENTS ‘immediate trace name row_cache level n’;
1 row cache统计信息
2 包含hash table histogram
8 包含object结构

 

4).Buffers
ALTER SESSION SET EVENTS ‘immediate trace name buffers level n’;
1 buffer header
2 level 1 + block header
3 level 2 + block contents
4 level 1 + hash chain
5 level 2 + hash chain
6 level 3 + hash chain
8 level 4 + users/waiters
9 level 5 + users/waiters
10 level 6 + users/waiters

 

5).Buffer
ALTER SESSION SET EVENTS ‘immediate trace name buffer level n’;
n为某个指定block的rdba,该命令可以转储某个block在buffer中的所有版本。

 RDBA (Relative Data Block Address),rdba就是rowid中的rfile#+block# 通过查询ROWID可以得出。

6).Heap
ALTER SESSION SET EVENTS ‘immediate trace name heapdump level level’;
1 PGA摘要
2 SGA摘要
4 UGA摘要
8 Current call(CGA)摘要
16 User call(CGA)摘要
32 Large call(LGA)摘要
1025 PGA内容
2050 SGA内容
4100 UGA内容
8200 Current call内容
16400 User call内容
32800 Large call内容

 

7).Sub Heap
Oracle 9.0.1版本之前
ALTER SESSION SET EVENTS ‘immediate trace name heapdump_addr level n’;
若n为subheap的地址,转储的是subheap的摘要信息
若n为subheap的地址+1,转储的则是subheap的内容
Oracle 9.2.0版本之后
ALTER SESSION SET EVENTS ‘immediate trace name heapdump_addr level n, addr m’;
其中m为subheap的地址
n为1转储subheap的摘要,n为2转储subheap的内容

 

8).Process State
ALTER SESSION SET EVENTS ‘immediate trace name processstate level n’;

 

9).System State
ALTER SESSION SET EVENTS ‘immediate trace name systemstate level n’;

 

10).Error State
ALTER SESSION SET EVENTS ‘immediate trace name errorstack level n’;
0 Error stack
1 level 0 + function call stack
2 level 1 + process state
3 level 2 + context area


11).Hang Analysis
ALTER SESSION SET EVENTS ‘immediate trace name hanganalyze level n’;

 

12).Work Area
ALTER SESSION SET EVENTS ‘immediate trace name workareatab_dump level n’;
1 SGA信息
2 Workarea Table摘要信息
3 Workarea Table详细信息

 

13).Latches
ALTER SESSION SET EVENTS ‘immediate trace name latches level n’;
1 latch信息
2 统计信息

 

14).Events
ALTER SESSION SET EVENTS ‘immediate trace name events level n’;
1 session
2 process
3 system

 

15).Locks
ALTER SESSION SET EVENTS ‘immediate trace name locks level n’;

 

16).Shared Server Process
ALTER SESSION SET EVENTS ‘immediate trace name shared_server_state level n’;
n取值为1~14

 

17).Background Messages
ALTER SESSION SET EVENTS ‘immediate trace name bg_messages level n’;
n为pid+1

 

.File Dumps

1).Block
Oracle 7之前
ALTER SESSION SET EVENTS ‘immediate trace name blockdump level n’;
n为block的rdba
Oracle8以后
ALTER SYSTEM DUMP DATAFILE file# BLOCK block#;
ALTER SYSTEM DUMP DATAFILE file#
BLOCK MIN minimum_block#
BLOCK MAX maximum_block#;

 

2).Tree Dump
ALTER SESSION SET EVENTS ‘immediate trace name treedump level n’;
n为object_id

 

3).Undo Segment Header
ALTER SYSTEM DUMP UNDO_HEADER ’segment_name’;

 

4).Undo for a Transaction
ALTER SYSTEM DUMP UNDO BLOCK ’segment_name’ XID xidusn xidslot xidsqn;

 

5).File Header
ALTER SESSION SET EVENTS ‘immediate trace name file_hdrs level n’;
1 控制文件中的文件头信息
2 level 1 + 文件头信息
3 level 2 + 数据文件头信息
10 level 3

 

6).Control file
ALTER SESSION SET EVENTS ‘immediate trace name controlf level n’;
1 文件头信息
2 level 1 + 数据库信息 + 检查点信息
3 level 2 + 可重用节信息
10 level 3

 

7).Redo log Header
ALTER SESSION SET EVENTS ‘immediate trace name redohdr level n’;
1 控制文件中的redo log信息
2 level 1 + 文件头信息
3 level 2 + 日志文件头信息
10 level 3

 

8).Redo log
ALTER SYSTEM DUMP LOGFILE ‘FileName’;
ALTER SYSTEM DUMP LOGFILE ‘FileName’
SCN MIN MinimumSCN
SCN MAX MaximumSCN
TIME MIN MinimumTime
TIME MAX MaximumTime
LAYER Layer
OPCODE Opcode
DBA MIN FileNumber . BlockNumber
DBA MAX FileNumber . BlockNumber
RBA MIN LogFileSequenceNumber . BlockNumber
RBA MAX LogFileSequenceNumber . BlockNumber;
其中time = (((((yyyy – 1988)) * 12 + mm – 1) * 31 + dd – 1) * 24 + hh) * 60 + mi) * 60 + ss;

 

9).Loghist
ALTER SESSION SET EVENTS ‘immediate trace name loghist level n’;
1 dump控制文件中最早和最迟的日志历史项
1 dump 2^n个日志历史项

 

三, Trace 文件使用示例

 

udump下的trc文件可以通过配置不让产生,利用命令
alter system set sql_trace=false;

其他的不能修改,只能手动的启动trace,手动的关闭trace.

 

比如:

alter session set events 'immediate trace name library_cache|controlf|systemstate|processstate|file_hdrs|REDOHDR level 10';

alter session set events 'immediate trace name off';

 

alter session set events '10046 trace name context forever,level 12';
alter session set events '10046 trace name context off';

 

alter system set events '10046 trace name context forever,level 12';
alter system set events '10046 trace name context off';

 

 

 

1. 使用autotrace
set autotrace ON | ON EXPLAIN | ON STATISTICS | TRACEONLY | TRACEONLY EXPLAIN
set autotrace off

这个用法是最简单方便的,执行sql结束之后,会自动在同个窗口显示sql的执行计划和统计信息。

 

2. 使用set events context

SQL> alter session set sql_trace=true;
SQL> alter session set sql_trace=false;

属于当前session级设置

大多数的情况下,我们使用sql_trace跟踪当前进程。通过跟踪当前进程可以发现当前操作的后台数据库递归活动(这在研究数据库新特性时尤其有效),研究SQL执行,发现后台错误等。

 

alter session set events '10046 trace name context forever,level 12';
alter session set events '10046 trace name context off';

10046事件概述:

10046事件是Oracle提供的内部事件,是对SQL_TRACE的增强.

10046事件可以设置以下四个级别:

1 - 启用标准的SQL_TRACE功能,等价于sql_trace

4 - Level 1 加上绑定值(bind values)

8 - Level 1 + 等待事件跟踪

12 - Level 1 + Level 4 + Level 8

类似sql_trace,10046事件可以在全局设置,也可以在session级设置。

 

3. 使用set events immediate
alter session set events 'immediate trace name library_cache|controlf|systemstate|processstate|file_hdrs|REDOHDR level 10';
alter session set events 'immediate trace name off';

Level =1 ,转储Library cache统计信息
Level =2 ,转储hash table概要
Level =4 ,转储Library cache对象,只包含基本信息
Level =8 ,转储Library cache对象,包含详细信息(包括child references,pin waiters等)
Level =16,增加heap sizes信息
Level =32,增加heap信息

 

9i清理buffer cache
   alter session set events 'immediate trace name flush_cache level 1';

   alter session set events = 'immediate trace name flush_cache'

 

4. 使用set events errorstack
alter session set events 'err_num trace name errorstack level 10';
alter session set events 'err_num trace name errorstack off'

err_num=报错代码,如ORA-00942 应该在err_num填入942

 

5. 使用dbms_support(trace别的session)
exec dbms_support.start_trace_in_session(sid=>XX,seiral#=>XXX,wait=>true,binds=>true);
exec dbms_support.stop_trace_in_session(sid=>XX,seiral#=>XXX);

这类trace用到很少,以后再研究。

 

6. 使用oradebug(trace别的session)
oradebug setospid (PID 能从ps -ef 中得出)
oradebug unlimit
oradebug event 10046 trace name context forever,level 12;
oradebug event 10046 trace name context off;

这类同样用到很少。

 

7. 使用dbms_system.set_ev
exec dbms_system.set_ev(sid,serial#,10046,trace_level,'username');
exec dbms_system.set_ev(sid,serial#,10046,0,'username');

通过DBMS_SYSTEM.SET_EV系统包来实现对sql的跟踪

######################################################

我们可以通过以下代码查询得到Oracle的诊断事件及说明,通过这些,我想就足够了。列举在这里给自己参考。

1.代码

SET linesize 120
SET feedback off
SET SERVEROUTPUT ON
DECLARE
err_msg VARCHAR2(120);
BEGIN
dbms_output.enable (1000000);
FOR err_num IN 10000..10999
LOOP
err_msg := SQLERRM (-err_num);
IF err_msg NOT LIKE '%Message '||err_num||' not found%' THEN
dbms_output.put_line (err_msg);
END IF;
END LOOP;
END;

                      

2.列表

ORA-10000: controlfile debug event, name 'control_file'
ORA-10001: controlfile crash event1
ORA-10002: controlfile crash event2
ORA-10003: controlfile crash event3
………………省略输出了。

你可能感兴趣的:(转载-Oracle 常用的dump命令)