Oracle 常用dump命令 - 轉

ningzi82發表於2010-10-19

.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
為某個指定blockrdba,該命令可以轉儲某個blockbuffer中的所有版本。

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
內容

[@more@]

7).Sub Heap
Oracle 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的地址
n
1轉儲subheap的摘要,n2轉儲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
blockrdba
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. 使用autotraceset autotrace ON | ON EXPLAIN | ON STATISTICS | TRACEONLY | TRACEONLY EXPLAIN
set autotrace off

這個用法是最簡單方便的,執行結束之後,會自動在同個視窗顯示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事件是提供的內部事件,是對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 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的跟蹤

轉自:http://blog.csdn.net/tianlesoftware/archive/2009/12/10/4977909.aspx

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/789833/viewspace-1039968/,如需轉載,請註明出處,否則將追究法律責任。

相關文章