oradebug命令詳解

datapeng發表於2014-02-14
oradebug它可以啟動跟蹤任何會話,dump SGA和其它記憶體結構,喚醒ORACLE程式,如SMON、PMON程式,也可以透過程式號使程式掛起和恢復等,還有很多功能,實際上這些功能都不常用,但是我們在看別人做問題診斷時,常看到別人在使用oradebug命令,其實我感覺最好用的就是他可以直接透過命令輸出生成trace檔案的名稱(帶路徑的哦),省去不少麻煩,系統HANG住用它做分析也比較好用,和大家分享一下它最常用的方法!
       以sysdba登陸後
SQL> oradebug help
HELP           [command]                 Describe one or all commands
SETMYPID                                 Debug current process 
SETOSPID                         Set OS pid of process to debug
SETORAPID       ['force']        Set Oracle pid of process to debug
SETORAPNAME                    Set Oracle process name to debug
SHORT_STACK                              Get abridged OS stack--查詢系統記憶體堆疊
CURRENT_SQL                              Get current SQL
DUMP           [addr]  Invoke named dump
DUMPSGA        [bytes]                   Dump fixed SGA
DUMPLIST                                 Print a list of available dumps
EVENT                              Set trace event in process
SESSION_EVENT                      Set trace event in session
DUMPVAR        

[level]  Print/dump a fixed PGA/SGA/UGA variable


DUMPTYPE      
 Print/dump an address with type info

SETVAR        

 Modify a fixed PGA/SGA/UGA variable


PEEK           [level]      Print/Dump memory
POKE                Modify memory
WAKEUP                          Wake up Oracle process
SUSPEND                                  Suspend execution
RESUME                                   Resume execution
FLUSH                                    Flush pending writes to trace file
CLOSE_TRACE                              Close trace file
TRACEFILE_NAME                           Get name of trace file
LKDEBUG                                  Invoke global enqueue service debugger
NSDBX                                    Invoke CGS name-service debugger
-G               Parallel oradebug command prefix
-R               Parallel oradebug prefix (return output
SETINST              Set instance list in double quotes
SGATOFILE               Dump SGA to file; dirname in double quotes
DMPCOWSGA       Dump & map SGA as COW; dirname in double quotes
MAPCOWSGA               Map SGA as COW; dirname in double quotes
HANGANALYZE    [level] [syslevel]        Analyze system hang
FFBEGIN                                  Flash Freeze the Instance
FFDEREGISTER                             FF deregister instance from cluster
FFTERMINST                               Call exit and terminate instance
FFRESUMEINST                             Resume the flash frozen instance
FFSTATUS                                 Flash freeze status of instance
SKDSTTPCS                Helps translate PCs to names
WATCH          
 Watch a region of memory

DELETE         watchpoint    Delete a watchpoint
SHOW           watchpoints        Show  watchpoints
DIRECT_ACCESS   Fixed table access
CORE                                     Dump core without crashing process
IPC                                      Dump ipc information
UNLIMIT                                  Unlimit the size of the trace file
PROCSTAT                                 Dump process statistics
CALL           [-t count] [arg1]...[argn]  Invoke function with arguments
上面試oradebug的命令引數,可以實現我們不同的跟蹤方式,功能還是比較強大的,我們先測試一個用oradebug做oracle process級10046
SQL> select distinct sid from v$mystat;

       SID
----------
        96

SQL> select spid,pid from v$Process where addr=(select paddr from v$session where sid=96);

SPID                            PID
------------------------ ----------
2556166                          19

SQL> !ps -ef | grep LOCAL
  oracle  3670242 10485930   0 11:25:50      -  0:00 oraclexupeng11g (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
  oracle  2556166  2031934   0 11:13:54      -  0:00 oraclexupeng11g (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))
  oracle 10617238  2031934   0 11:34:30  pts/0  0:00 grep LOCAL
對SPID系統程式進行追蹤

SQL> oradebug setorapid 19
Oracle pid: 19, Unix process pid: 2556166, image: oracle@cecgt (TNS V1-V3)
SQL> oradebug event 10046 trace name context forever,level 28;
Statement processed.
SQL> oradebug tracefile_name
/u01/app/oracle/diag/rdbms/xupeng11g/xupeng11g/trace/xupeng11g_ora_2556166.trc
SQL> !more /u01/app/oracle/diag/rdbms/xupeng11g/xupeng11g/trace/xupeng11g_ora_2556166.trc 我們這裡檢視完整的一段就行了,看用oradebug trace 10046事件的內容。
*** 2014-02-13 12:22:03.400
WAIT #0: nam='SQL*Net message from client' ela= 79182308 driver id=1650815232 #bytes=1 p3=0 obj#=528 tim=11404921879
=====================
PARSING IN CURSOR #24 len=202 dep=1 uid=0 oct=3 lid=0 tim=11404923285 hv=3819099649 ad='70000017ede6ec8' sqlid='3nkd3g3ju5ph1'
select obj#,type#,ctime,mtime,stime, status, dataobj#, flags, oid$, spare1, spare2 from obj$ where owner#=:1 and name=:2 and na
mespace=:3 and remoteowner is null and linkname is null and subname is null
END OF STMT
PARSE #24:c=0,e=747,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=4,plh=0,tim=11404923283
BINDS #24:
 Bind#0
  oacdty=02 mxl=22(22) mxlc=00 mal=00 scl=00 pre=00
  oacflg=08 fl2=0001 frm=00 csi=00 siz=24 off=0
  kxsbbbfp=111c1c958  bln=22  avl=01  flg=05
  value=0
 Bind#1
  oacdty=01 mxl=32(01) mxlc=00 mal=00 scl=00 pre=00
  oacflg=18 fl2=0001 frm=01 csi=873 siz=32 off=0
  kxsbbbfp=111c1c920  bln=32  avl=01  flg=05
  value="T"
 Bind#2
  oacdty=02 mxl=22(22) mxlc=00 mal=00 scl=00 pre=00
  oacflg=08 fl2=0001 frm=00 csi=00 siz=24 off=0
  kxsbbbfp=111c1c8f0  bln=24  avl=02  flg=05
  value=1
EXEC #24:c=10000,e=20358,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=4,plh=853875749,tim=11404943911
FETCH #24:c=0,e=52,p=0,cr=4,cu=0,mis=0,r=1,dep=1,og=4,plh=853875749,tim=11404944012
STAT #24 id=1 cnt=1 pid=0 pos=1 obj=18 op='TABLE ACCESS BY INDEX ROWID OBJ$ (cr=4 pr=0 pw=0 time=0 us cost=3 size=77 card=1)'
STAT #24 id=2 cnt=1 pid=1 pos=1 obj=37 op='INDEX RANGE SCAN I_OBJ2 (cr=3 pr=0 pw=0 time=0 us cost=2 size=0 card=1)'
CLOSE #24:c=0,e=86,dep=1,type=3,tim=11404944134 

我們用dump獲取系統狀態資訊
SQL> select spid,pid from v$Process where addr=(select paddr from v$session where sid=160);

SPID                            PID
------------------------ ----------
2032030                          21

設定跟蹤
SQL> oradebug setospid 2032030  或者換成pid也行
Oracle pid: 21, Unix process pid: 2032030, image: oracle@cecgt (TNS V1-V3)
指定SPID之後,我們就可以使用dump相關資訊了,這些dump內容有很多,我們看一下
SQL> oradebug dumplist
TRACE_BUFFER_ON
TRACE_BUFFER_OFF
LATCHES
PROCESSSTATE
SYSTEMSTATE
INSTANTIATIONSTATE
REFRESH_OS_STATS
CROSSIC
CONTEXTAREA
HANGDIAG_HEADER
HEAPDUMP
HEAPDUMP_ADDR
POKE_ADDRESS
POKE_LENGTH
POKE_VALUE
POKE_VALUE0
GLOBAL_AREA
REALFREEDUMP
FLUSH_JAVA_POOL
POOL_SIMULATOR
PGA_DETAIL_GET
PGA_DETAIL_DUMP
PGA_DETAIL_CANCEL
PGA_SUMMARY
MODIFIED_PARAMETERS
EVENT_TSM_TEST
ERRORSTACK
CALLSTACK
TEST_STACK_DUMP
TEST_GET_CALLER
RECORD_CALLSTACK
EXCEPTION_DUMP
BG_MESSAGES
ENQUEUES
KSTDUMPCURPROC
KSTDUMPALLPROCS
KSTDUMPALLPROCS_CLUSTER
SIMULATE_EOV
KSFQP_LIMIT
KSKDUMPTRACE
DBSCHEDULER
LDAP_USER_DUMP
LDAP_KERNEL_DUMP
DUMP_ALL_OBJSTATS
DUMPGLOBALDATA
HANGANALYZE
HANGANALYZE_PROC
HANGANALYZE_GLOBAL
GES_STATE
OCR
CSS
CRS
SYSTEMSTATE_GLOBAL
GIPC
MMAN_ALLOC_MEMORY
MMAN_CREATE_DEF_REQUEST
MMAN_CREATE_IMM_REQUEST
MMAN_IMM_REQUEST
DUMP_ALL_COMP_GRANULE_ADDRS
DUMP_ALL_COMP_GRANULES
DUMP_ALL_REQS
DUMP_TRANSFER_OPS
DUMP_ADV_SNAPSHOTS
ADJUST_SCN
NEXT_SCN_WRAP
CONTROLF
FLUSH_CACHE
FULL_DUMPS
BUFFERS
RECOVERY
SET_TSN_P1
BUFFER
PIN_BLOCKS
BC_SANITY_CHECK
PIN_RANDOM_BLOCKS
SET_NBLOCKS
CHECK_ROREUSE_SANITY
DUMP_PINNED_BUFFER_HISTORY
KCBO_OBJ_CHECK_DUMP
KCB_WORKING_SET_DUMP
REDOLOGS
ARCHIVE_ERROR
LOGHIST
REDOHDR
LOGERROR
OPEN_FILES
DATA_ERR_ON
DATA_READ_ERR_ON
DATA_ERR_OFF
BLK0_FMTCHG
UPDATE_BLOCK0_FORMAT
TR_SET_BLOCK
TR_SET_ALL_BLOCKS
TR_SET_SIDE
TR_CRASH_AFTER_WRITE
TR_READ_ONE_SIDE
TR_CORRUPT_ONE_SIDE
TR_RESET_NORMAL
TEST_DB_ROBUSTNESS
LOCKS
GC_ELEMENTS
FILE_HDRS
KRB_CORRUPT_INTERVAL
KRB_CORRUPT_SIZE
KRB_CORRUPT_REPEAT
KRB_CORRUPT_OFFSET
KRB_PIECE_FAIL
KRB_OPTIONS
KRB_FAIL_INPUT_FILENO
KRB_SIMULATE_NODE_AFFINITY
KRB_TRACE
KRB_BSET_DAYS
KRB_SET_TIME_SWITCH
KRB_OVERWRITE_ACTION
KRB_CORRUPT_SPHEADER_INTERVAL
KRB_CORRUPT_SPHEADER_REPEAT
KRB_CORRUPT_SPBITMAP_INTERVAL
KRB_CORRUPT_SPBITMAP_REPEAT
KRB_CORRUPT_SPBAD_INTERVAL
KRB_CORRUPT_SPBAD_REPEAT
KRB_UNUSED_OPTION
KRBMRSR_LIMIT
KRBMROR_LIMIT
KRBABR_TRACE
KRDRSBF
KRC_TRACE
KRA_OPTIONS
KRA_TRACE
FBTAIL
FBINC
FBHDR
FLASHBACK_GEN
KTPR_DEBUG
DUMP_TEMP
DROP_SEGMENTS
TEST_SPACEBG
TREEDUMP
LONGF_CREATE
KDLIDMP
ROW_CACHE
LIBRARY_CACHE
LIBRARY_CACHE_OBJECT
CURSORDUMP
CURSORTRACE
CURSOR_STATS
XS_SESSION_STATE
SHARED_SERVER_STATE
LISTENER_REGISTRATION
JAVAINFO
KXFPCLEARSTATS
KXFPDUMPTRACE
KXFPBLATCHTEST
KXFXSLAVESTATE
KXFXCURSORSTATE
KXFRHASHMAP
WORKAREATAB_DUMP
KUPPLATCHTEST
OBJECT_CACHE
SAVEPOINTS
RULESETDUMP
RULESETDUMP_ADDR
FAILOVER
OLAP_DUMP
SELFTESTASM
ASMDISK_ERR_ON
ASMDISK_READ_ERR_ON
ASMDISK_ERR_OFF
IOERREMUL
IOERREMULRNG
ALRT_TEST
AWR_TEST
AWR_FLUSH_TABLE_ON
AWR_FLUSH_TABLE_OFF
ASHDUMP
MMON_TEST
ATSK_TEST
HM_FW_TRACE
HM_FDG_VERS
IR_FW_TRACE
KSDTRADV_TES
在這些dump選項中,大部分都有24681012等幾個跟蹤級別。在使用的時候要根據具體的情況來選擇級別,不同級別的影響不一樣。
為了獲取全面的資訊,我們使用level 10
SQL> oradebug unlimit
Statement processed.
SQL> oradebug dump systemstate 10
Statement processed.
SQL> oradebug tracefile_name
/u01/app/oracle/diag/rdbms/xupeng11g/xupeng11g/trace/xupeng11g_ora_2032030.trc
*** 2014-02-13 14:42:44.140
Processing Oradebug command 'dump systemstate 10'
===================================================
SYSTEM STATE (level=10)
------------
System global information:
     processes: base 0x70000017f2dc6d0, size 150, cleanup 0x70000017f2e7408
     allocation: free sessions 0x70000017f343dc0, free calls 0x0
     control alloc errors: 0 (process), 0 (session), 0 (call)
     PMON latch cleanup depth: 0
     seconds since PMON's last scan for dead processes: 52
     system statistics:
0 OS CPU Qt wait time
762 logons cumulative
24 logons current
48731 opened cursors cumulative
29 opened cursors current
1201 user commits
0 user rollbacks
7230 user calls
496615 recursive calls
2438 recursive cpu usage
4 pinned cursors current
325991 session logical reads
0 session stored procedure space
1929 CPU used when call started
3746 CPU used by this session
1307212 DB time
0 cluster wait time
72445489 concurrency wait time
165 application wait time
1310983 user I/O wait time
0 scheduler wait time
87778877 non-idle wait time
35641 non-idle wait count
0 session connect time
0 process last non-idle time
1013656413808 session uga memory
553837976 session uga memory max
4591 messages sent
4591 messages received
52440 background timeouts
0 remote Oradebug requests
536394816 session pga memory
560708672 session pga memory max
0 recursive system API invocations
2 enqueue timeouts
12 enqueue waits
0 enqueue deadlocks
112575 enqueue requests
2567 enqueue conversions
112558 enqueue releases
0 global enqueue gets sync
0 global enqueue gets async
0 global enqueue get time
0 global enqueue releases
21247 physical read total IO requests
64 physical read total multi block requests
0 physical read requests optimized
339247616 physical read total bytes
13191 physical write total IO requests
22 physical write total multi block requests
178188288 physical write total bytes
517435904 cell physical IO interconnect bytes
0 spare statistic 1
0 spare statistic 2
0 spare statistic 3
0 spare statistic 4
0 IPC CPU used by this session
0 gcs messages sent
0 ges messages sent
0 global enqueue CPU used by this session
SO: 0x70000017f0cd860, type: 1, owner: 0x0, flag: INIT/-/-/0x00 if: 0x3 c: 0x3
 proc=0x0, name=cleanup state object, file=kss.h LINE:2051 ID:, pg=0
(cleanup state object) description: ASM file cleanup
latch: 0x700000000045c08
BEGIN DISPATCHER DUMPS
 DISPATCHER 0x700000179e4e3e0 (0, 1)
  Holder:
  ----------------------------------------
  SO: 0x700000179e4e468, type: 83, owner: 0x70000000000b360, flag: INIT/-/-/0x00 if: 0x3 c: 0x3
   proc=0x70000017c2b4818, name=circuit holder, file=kmc.h LINE:2612 ID:, pg=0
  (circuit holder) disp = 0x700000179e4e3e0 (0, 1), proc = (0x70000017c2b4818, 1)
END DISPATCHER DUMPS
END OF SYSTEM STATE
這裡我們就生成了一個完整的dump,這個dump是基於作業系統的,拿到手我們就可以分析了!!
oradebug session級別的10046跟蹤和sql_trace的差不多,我就不再闡述了。

我們再用oradebug 做系統hang住原因分析,這裡有一個前提看是hang到什麼程度,如果sys使用者可以登入到庫上 我們就用 oradebug,如果hang死了就需要我們想別的方法
我這裡只列出命令:
oradebug setmypid
oradebug unlimit
oradebug setinst all   --RAC環境
oradebug hanganalyze 3  -- 級別一般指定為3足夠了
oradebug -g def dump systemstate 10  --RAC環境
oradebug tracefile_name

獲取某程式的狀態資訊
   oradebug setospid 22180
   oradebug dump processstate 10
   oradebug tracefile_name
獲取程式錯誤資訊狀態
   oradebug setospid 22180
   oradebug dump errorstack 3
追蹤造成錯誤資訊的原因,如ORA-04031
   oradebug event 4031 trace name errorstack level 3

oradebug的功能還有很多,我們列舉出了常用的功能。後續還會有一些調優的方法論和工具推薦給大家!!!

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