Chinaunix首页 | 论坛 | 博客
  • 博客访问: 496923
  • 博文数量: 161
  • 博客积分: 6010
  • 博客等级: 准将
  • 技术积分: 1947
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-25 01:20
文章分类

全部博文(161)

文章存档

2011年(44)

2010年(47)

2009年(48)

2008年(22)

我的朋友

分类: Oracle

2011-02-14 11:03:27

Oradebug命令

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

SHORT_STACK                              Dump abridged OS stack

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

CORE                                     Dump core without crashing process

IPC                                      Dump ipc information

UNLIMIT                                  Unlimit the size of the trace file

PROCSTAT                                 Dump process statistics

CALL            [arg1] ... [argn]  Invoke function with arguments

Oradebug 介绍

--确认要追逐的进程,spidoracle自己的pid

SQL> select s.username, s.sid,s.serial#, p.spid from v$session s ,v$process p where s.paddr=p.addr;

USERNAME                              SID    SERIAL# SPID

------------------------------ ---------- ---------- ------------

                                      170          1 8690

                                      169          1 8692

                                      168          1 8694

                                      167          1 8696

                                      166          1 8698

--查询spid

SQL>  select pid,spid,username from v$process; 

       PID SPID         USERNAME

---------- ------------ ---------------

         1

         2 8690         oracle

         3 8692         oracle

         4 8694         oracle

         5 8696         oracle

         6 8698         oracle

--设定oradebug环境

SQL> oradebug setospid 8763

Oracle pid: 21, Unix process pid: 8763, image: oracle@node1 (q001)

SQL> oradebug unlimit;

Statement processed.

--sid设定后,可以用dump的东西可用oradebug dumplist列出

--设置debug事件,收集完成后关闭debug事件

SQL>oradebug event 10046 trace name context forever, level 8;

SQL>oradebug event 10046 trace name context off;

--获得系统状态

--

SQL>oradebug dump systemstate 10

SQL>oradebug hanganalyze 12

oradebug event 10046 trace name context forever, level 8;
oradebug event 10046 trace name context off; 

--Level

 Level 1: 等同于SQL_TRACE 的功能

 Level 4: 在Level 1的基础上增加收集绑定变量的信息

 Level 8: 在Level 1 的基础上增加等待事件的信息

 Level 12:等同于Level 4+Level 8, 即同时收集绑定变量信息和等待事件信息。

--获得某个进程的状态

SQL>oradebug setospid 3333 --该进程必须是Oracle进程

SQL> oradebug dump processstate 10 


--也可以获得进程的错误信息状态 
SQL> oradebug dump errorstack 3 
已处理的语句 
(注:本处没有产生新的trace,难道是需要出错的时候才有信息?

--定位现在在使用哪个trace 
SQL> oradebug TRACEFILE_NAME 


高级一点的应用 
1>Trace a session SQL 
1.1>如果是只想抓取用户sql语句的话(level 1),使用DBMS_SYSTEM包 
SQL> select s.username, s.sid,s.serial#, p.spid from v$session s ,v$process p where s.paddr=p.addr;

USERNAME                              SID    SERIAL# SPID

------------------------------ ---------- ---------- ------------

                                      170          1 8690

                                      169          1 8692

                                      168          1 8694

                                      167          1 8696

                                      166          1 8698


 
--开启对进程的trace,记录在trace文件中
SQL> execute dbms_system.set_sql_trace_in_session(143,6,true);  

--关闭追踪

SQL> execute dbms_system.set_sql_trace_in_session(143,6,false);  


1.2>如果想进行更高级别的抓取,level 4,要使用oradebug 
--首先按照前面得到进程的spid 
SQL> oradebug setospid 3260 
Oracle pid: 22, Windows thread id: 3260, image: oracle.exe (SHAD) 
SQL> oradebug event 10046 trace name context forever,level 4 
已处理的语句 
(注:可以同时追踪多个进程,setospid …. , Oradebug …10046…) 

--抓取后取消追踪使用 
SQL> oradebug event 10046 trace name context off 

--获得tracename

SQL>oradebug tracefile_name 


2>Tracing errors use oradebug 
例如要追踪能造成ORA-00942/952错误的会话,则 
SQL> oradebug event 942 trace name errorstack level 3 
已处理的语句 
SQL> oradebug event 952 trace name errorstack level 3 
已处理的语句 

3>Trace ORA-04030 
ORA-04030是由于某些进程请求的内存不断增大最后导致溢出的错误 
SQL > oradebug setodpid  
SQL > oradebug unlimit 
SQL > oradebug dump heapdump 5 this dump PGA and UGA heaps 


4>waking up PMON to release DDL locks 
首先确认PMON进程是who 
SQL> select pid,spid from v$process p,v$bgprocess b 
where b.paddr=p.addr 
and name='PMON'; 

PID SPID 
---------- ------------ 
2 3608 
SQL> oradebug wakeup 2 
已处理的语句 

5>暂停和启动进程(suspending and resuming a process) 
SQL> oradebug setospid *** 
SQL> oradebug suspend 
Or 
SQL> oradebug setospid *** 
SQL> oradebug resume 

6>DUMP很多东西 
oradebug可以dump很多内容,例如latch / library_cache / locks / controlfile 
具体可参照 oradebug dumplist 的信息 
例子: 
oradebug dump controlf 10 
oradebug dump file_hdrs 10 


--------------------------------------------------------------------------
oradebug 可以帮助我们做很多事情,如dump内存信息、设置事件、挂起进程等。本文主要介绍如何使用oradebug挂起进程。 
为什么要挂起进程呢?比如因为开发人员对数据库执行一个很大的操作,严重影响了数据库的正常运行,此时你有两个选择: 
1、删掉进程 
2、暂停进程 

实际上,我们往往不能十分确定把进程直接kill掉会造成什么后果,所以暂停进程的执行就是一个比较折中的选择。 
要暂停进程步骤很简单:首先找到进程,然后暂停就可以了。 
使用oradebug暂停进程时,可以使用pid,也可以使用spid。要找出这些信息有很多方式了,比如可以在操作系统中 ps -ef、可以通过v$sessionv$processv$bgprocess等视图通过关联得到。 

下面通过一个例子来说明如何 oradebug干预进程的执行状态: 
1、找出进程号 
本例我们要挂起以用户suk登录的会话: 
sys用户登录查询: 
SQL> select pid,spid from v$process where addr in (select paddr from v$session where username='SCOTT'); 

PID SPID 
---------- ------------ 
10 4107 

2、设置要操作的进程号 
有两种方法: 
1)spid设置 
SQL> oradebug setospid 4107 
Oraclepid: 10, Unix process pid: 4107, image:oracle@suk(TNS V1-V3) 
2)pid设置 
SQL> oradebug setorapid 10 
Unix process pid: 4107, image:oracle@suk(TNS V1-V3) 

3、暂停进程执行 
SQL> oradebug suspend 
Statement processed. 
此时,进程号为4107的进程将会处于挂起状态。我们稍后可以重启它。 

4、重启进程 
重启进程也要先设置进程号: 
SQL> oradebug setospid 4107 
Oracle pid: 10, Unix process pid: 4107, image:oracle@suk(TNS V1-V3) 
SQL> oradebug resume

Statement processed. 
注意:不能在会话中suspend当前会话。如果那样做的话,当前会话会被hang,并且不能被其他session resume,只能kill方式关闭。

--------------------------------------------------------------------------

阅读(2438) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2011-06-05 01:53:33

大连法律咨询在线 http://www.fabowang.com 大连律师在线咨询 http://www.fabowang.com 大连法律顾问网 http://www.fabowang.com 大连律师咨询 http://www.fabowang.com

chinaunix网友2011-03-05 16:33:27

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com