Oracle 常用dump命令

it2022-05-05  54

以前也整理过一遍有关跟踪事件的文章,不过命令方面没有这篇强。

 

Oracle 跟踪事件 set event

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

 

 

.Memory Dumps

1).Global AreaALTER SESSION SET EVENTS ‘immediate trace name global_area level n’;1 包含PGA2 包含SGA4 包含UGA8 包含indrect memory

 

2).Library CacheALTER SESSION SET EVENTS ‘immediate trace name library_cache level n’;1 library cache统计信息2 包含hash table histogram3 包含object handle4 包含object结构(Heap 0

 

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

 

4).BuffersALTER SESSION SET EVENTS ‘immediate trace name buffers level n’;1 buffer header2 level 1 + block header3 level 2 + block contents4 level 1 + hash chain5 level 2 + hash chain6 level 3 + hash chain8 level 4 + users/waiters9 level 5 + users/waiters10 level 6 + users/waiters

 

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

 

6).HeapALTER 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 HeapOracle 9.0.1版本之前ALTER SESSION SET EVENTS ‘immediate trace name heapdump_addr level n’;nsubheap的地址,转储的是subheap的摘要信息nsubheap的地址+1,转储的则是subheap的内容Oracle 9.2.0版本之后ALTER SESSION SET EVENTS ‘immediate trace name heapdump_addr level n, addr m’;其中msubheap的地址n1转储subheap的摘要,n2转储subheap的内容

 

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

 

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

 

10).Error StateALTER SESSION SET EVENTS ‘immediate trace name errorstack level n’;0 Error stack1 level 0 + function call stack2 level 1 + process state3 level 2 + context area

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

 

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

 

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

 

14).EventsALTER SESSION SET EVENTS ‘immediate trace name events level n’;1 session2 process3 system

 

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

 

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

 

17).Background MessagesALTER SESSION SET EVENTS ‘immediate trace name bg_messages level n’;npid+1

 

.File Dumps

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

 

2).Tree DumpALTER SESSION SET EVENTS ‘immediate trace name treedump level n’;nobject_id

 

3).Undo Segment HeaderALTER SYSTEM DUMP UNDO_HEADER ’segment_name’;

 

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

 

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

 

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

 

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

 

8).Redo logALTER SYSTEM DUMP LOGFILE ‘FileName’;ALTER SYSTEM DUMP LOGFILE ‘FileName’SCN MIN MinimumSCNSCN MAX MaximumSCNTIME MIN MinimumTimeTIME MAX MaximumTimeLAYER LayerOPCODE OpcodeDBA MIN FileNumber . BlockNumberDBA MAX FileNumber . BlockNumberRBA MIN LogFileSequenceNumber . BlockNumberRBA MAX LogFileSequenceNumber . BlockNumber;其中time = (((((yyyy – 1988)) * 12 + mm – 1) * 31 + dd – 1) * 24 + hh) * 60 + mi) * 60 + ss;

 

9).LoghistALTER 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. 使用autotraceset autotrace ON | ON EXPLAIN | ON STATISTICS | TRACEONLY | TRACEONLY EXPLAINset 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_trace10046事件可以在全局设置,也可以在session级设置。

 

3. 使用set events immediatealter 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 errorstackalter 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 unlimitoradebug event 10046 trace name context forever,level 12;oradebug event 10046 trace name context off;

这类同样用到很少。

 

7. 使用dbms_system.set_evexec 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的跟踪

 

 

 

转载于:https://www.cnblogs.com/hibernate315/archive/2009/12/10/2399354.html

相关资源:数据结构—成绩单生成器

最新回复(0)