oradebug 用法小结(二)


INSTRODUCTION

 Oracle utility called oradebug. This tool is primarily used by Oracle worldwide customer support .With oradebug utility you can literally see the database engine. The
oradebug is especially useful when things go very bad - e.g. the database just stops, hangs, or the database keeps crashing with the ORA-0600 error! To run this tool you must have administrator privileges.
ORADEBUG工具主要用于下面场景中

- enabling/disabling the SQL tracing for another user's session.
- suspending intensive processes 进程挂起
- finding information about shared memory and semaphores  发现共享内存和信号量的信息
- closing the trace file so that new one can be generated 关闭trace file,以便能够产生新的trace file
- manipulating and dumping internal structures    操纵和dump出内部结构
- wake up processes etc.                            唤醒进程



COMMAND

Oradebug
 is a command that can be executed from SQL*Plus (or Svrmgrl in Oracle 8i and lower releases) to display or dump diagnostics information.
Execute the "ORADEBUG HELP" command to obtain a list of valid ORADEBUG commands.


> 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
PDUMP          [interval=]     Invoke named dump periodically
               [ndumps=]   [addr]
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
SETTRACEFILEID         Set tracefile identifier
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
IPC                                      Dump ipc information
UNLIMIT                                  Unlimit the size of the trace file
CALL           [-t count] [arg1]...[argn]  Invoke function with arguments
CORE                                     Dump core without crashing process
PROCSTAT                                 Dump process statistics


EXAMPLE

oradebug setmypid

> oradebug help setmypid
SETMYPID                                 Debug current process

为了方便定位到trace文件,我们在这里指定trace文件的名字
> alter session set tracefile_identifier='mytrace';

查看当前的trace文件的路径
> oradebug tracefile_name
/s01/oracle/app/oracle/diag/rdbms/test/test/trace/test_ora_2844_mytrace.trc


追踪进程

oradebug setospid

> select * from v$mystat where rownum=1;


       SID STATISTIC#      VALUE
---------- ---------- ----------
         1          0          0

> select spid,pid from v$process
  2  where addr=(select paddr from v$session where sid=1);


SPID                            PID
------------------------ ----------
2844                             17

> oradebug setospid 2844
Oracle pid: 17, Unix process pid: 2844, image: oracle@uumile (TNS V1-V3)

oradebug setorapid

使用上面的查询结果
> oradebug setorapid 17
Oracle pid: 17, Unix process pid: 2844, image: oracle@uumile (TNS V1-V3)


测试跟踪事件

oradebug event

> oradebug help event
EVENT                              Set trace event in process
> oradebug unlimit
Statement processed.
> oradebug event 10046 trace name context forever,level 12;
Statement processed.
> oradebug event 10046 trace name context off;

更多关于oracle interval event ,请参考
http://blog.itpub.net/28697282/viewspace-1479325/

Event numbers can be found in $ORACLE_HOME/rdbms/mesg/oraus.msg (in unix or linux)
http://www.eygle.com/digest/2008/04/oracle_internal_events_introdu.html


唤醒进程

oradebug wakeup

当需要smon进程来清理临时段时,可以用这个命令来唤醒smon进程,使之清理临时段。

> oradebug help wakeup
WAKEUP                          Wake up Oracle process
 
> select pid from v$process p,v$bgprocess b 
  2  where b.paddr=p.addr
  3  and name='SMON';

       PID
----------
        13

> oradebug wakeup 13
Statement processed.

挂起和恢复进程

挂起进程

oradebug suspend
oradebug also allows you to suspend a process. Firstly you need to identify the shadow process
that you want to suspend. Then set your debug session to point to that process.

将某个进程挂起,这里我们以挂起某个会话的进程为例进行说明
session A
> select * from v$mystat where rownum=1;

       SID STATISTIC#      VALUE
---------- ---------- ----------
         1          0          0

session B
> select * from v$mystat where rownum=1;

       SID STATISTIC#      VALUE
---------- ---------- ----------
        23          0          0

> select a.username,a.sid,a.serial#,b.spid from v$session a,v$process b where a.paddr=b.addr
  2  order by username;
USERNAME                              SID    SERIAL# SPID
------------------------------ ---------- ---------- ------------------------
SYS                                    23        107 4595
SYS                                     1          5 2844

假设我们将session A 挂起
session B
> oradebug setospid 2844
Oracle pid: 17, Unix process pid: 2844, image: oracle@uumile (TNS V1-V3)
> oradebug suspend
Statement processed.

恢复进程

oradebug resume

> oradebug resume


查看下当前的等待事件
sys@TEST(127.0.0.1)>  select sid,event,state from v$session_wait;

会话挂起时,通过v$session_wait可以看到有关debug的wait event :  debugger command

追踪进程信息

oradebug procstat

> oradebug help procstat
PROCSTAT                                 Dump process statistics
> select pid from v$process p,v$bgprocess b
  2  where b.paddr=p.addr
  3  and name='PMON';


       PID
----------
         2

> oradebug setorapid 2
Oracle pid: 2, Unix process pid: 2838, image: oracle@uumile (PMON)
> oradebug procstat
Statement processed.
> oradebug tracefile_name
/s01/oracle/app/oracle/diag/rdbms/test/test/trace/test_pmon_2838.trc

获取trace文件名

oradebug tracefile_name

> oradebug help tracefile_name
TRACEFILE_NAME                           Get name of trace file
输出类似如下结果
> oradebug tracefile_name
/s01/oracle/app/oracle/diag/rdbms/test/test/trace/test_ora_3148.trc


关闭跟踪

oradebug close_trace

> oradebug help close_trace
CLOSE_TRACE                              Close trace file
> oradebug close_trace
Statement processed.

清洗缓冲区

oradebug flush

To flush the current contents of the trace buffer to the trace file use
> oradebug help flush
FLUSH                                    Flush pending writes to trace file
> oradebug flush
Statement processed.



更多用法,请参考
http://www.juliandyke.com/Diagnostics/Tools/ORADEBUG/ORADEBUG.html
http://www.orafaq.com/wiki/Oradebug




来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28697282/viewspace-1479070/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/28697282/viewspace-1479070/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值