溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Oracle如何使用hanganalyze命令分析數(shù)據(jù)庫hang

發(fā)布時(shí)間:2021-11-08 13:57:04 來源:億速云 閱讀:256 作者:小新 欄目:建站服務(wù)器

小編給大家分享一下Oracle如何使用hanganalyze命令分析數(shù)據(jù)庫hang,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

1. 數(shù)據(jù)庫hang的幾種可能性
oracle 死鎖或者系統(tǒng)負(fù)載非常高比如cpu使用或其他一些鎖等待很高都可能導(dǎo)致系統(tǒng)hang住,比如大量的DX鎖。
通常來說,我們所指的系統(tǒng)hang住,是指應(yīng)用無響應(yīng),普通的sqlplus幾乎無法操作等等。
2. 如何進(jìn)行hang分析?hang分析有哪些level?如何選擇level?
hanganalyze有如下幾種level:
10     Dump all processes (IGN state)
5      Level 4 + Dump all processes involved in wait chains (NLEAF state)
4      Level 3 + Dump leaf nodes (blockers) in wait chains (LEAF,LEAF_NW,IGN_DMP state)
3      Level 2 + Dump only processes thought to be in a hang (IN_HANG state)
1-2    Only HANGANALYZE output, no process dump at all
如何選擇level?
一般來說,不建議使用3以上級(jí)別的hang分析,因?yàn)榭赡軙?huì)產(chǎn)生非常大的trace,還可能對(duì)系統(tǒng)的IO有一定影響。
從oracle 9i開始 hanganalyze提供給了對(duì)rac的支持。
有如下2種方式:
1) ALTER SESSION SET EVENTS 'immediate trace name HANGANALYZE level <level>';
2) 使用oradebug 命令
   ORADEBUG setmypid
   ORADEBUG setinst all
   ORADEBUG -g def hanganalyze <level>  ---針對(duì)rac的用法
   oradebug setmypid
   oradebug hanganalyze 3               ---非rac環(huán)境
通常在做hang分析的時(shí)候,oracle建議同時(shí)做一個(gè)systemstate的dump
oradebug SYSTEMSTATE dump level 2     level 2即可, 包含了所有session的信息。
      sqlplus -prelim / as sysdba       ---10g可以使用此方式登錄
      oradebug setospid <process ID>
      oradebug unlimit
      oradebug dump systemstate 10
補(bǔ)充:有時(shí)候我們可能還需要對(duì)某個(gè)進(jìn)程進(jìn)行trace aix環(huán)境,我們可以使用dbx命令
如下例子:
dbx -a PID (where PID = any oracle shadow process)       ---通過ps -ef|grep xxx查看
dbx() print ksudss(10)
dbx() detach
3. 如何解讀hang分析的trace文件,獲取有用信息?
*** ACTION NAME:() 2010-03-12 00:04:01.497
*** MODULE NAME:(sqlplus@S7_C_YZ_YZSJK(TNS V1-V3)) 2010-03-12 00:04:01.497    ---模塊名 跟v$session.module_name一樣
*** SERVICE NAME:(SYS$USERS) 2010-03-12 00:04:01.497
*** SESSION ID:(5184.45287) 2010-03-12 00:04:01.497           --sid (5184)   serial# (35287)
*** 2010-03-12 00:04:01.497
==============
HANG ANALYSIS:
==============
Found 54 objects waiting for <cnode/sid/sess_srno/proc_ptr/ospid/wait_event>
    <0/5210/10419/0x99d0a88/11215038/No Wait>                 --從這里看 session 5210 阻塞了54個(gè)對(duì)象
Open chains found:
Chain 1 : <cnode/sid/sess_srno/proc_ptr/ospid/wait_event> :   --從這里開始 以下的session都是被前面的5210阻塞 通常來說是一個(gè)阻塞另一個(gè)!
    <0/5210/10419/0x99d0a88/11215038/No Wait>
-- <0/3994/15494/0xd9ac1b0/6574102/enq: TM - contention>
-- <0/4962/58962/0xca03618/5710044/enq: DX - contention>
Other chains found:                                           --下面的session也是被前面所阻塞 不過不是直接阻塞(by Open chains) 間接阻塞!
Chain 2 : <cnode/sid/sess_srno/proc_ptr/ospid/wait_event> :
    <0/4001/31548/0xf9f3ab0/4980956/enq: DX - contention>
Chain 3 : <cnode/sid/sess_srno/proc_ptr/ospid/wait_event> :
    <0/4014/30717/0xaa27b48/7446746/gc buffer busy>
Chain 4 : <cnode/sid/sess_srno/proc_ptr/ospid/wait_event> :
    <0/4039/42115/0xd9f5710/5595180/PX Deq: Table Q Normal>
Cycle 1 : <sid/sess_srno/proc_ptr/ospid/wait_event> :        -- cycle 通常是死鎖 一般來說很有可能就是hang的根源
    <980/3887/0xe4214964/24065/latch free>
-- <2518/352/0xe4216560/24574/latch free>
-- <55/10/0xe41236a8/13751/latch free>

4. 不同版本hang分析的差異?trace有何異同?
如下是oracle8~10g的 hanganalyze trace信息格式:
Oracle 8.x : [nodenum]/sid/sess_srno/session/state/start/finish/[adjlist]/predecessor
Oracle 9i:   [nodenum]/cnode/sid/sess_srno/session/ospid/state/start/finish/[adjlist]/predecessor
Oracle 10g: [nodenum]/cnode/sid/sess_srno/session/ospid/state/start/finish/[adjlist]/predecessor
Nodenum     --》 每個(gè)session做hanganalyze生成的一個(gè)序列號(hào)
sid         --》 Session ID
sess_srno   --》 Serial#
ospid       --》 OS Process Id (v$process spid)
state       --》 State of the node
adjlist     --》 adjacent node   (Usually represents a blocker node) --通常是阻塞者
predecessor --》 predecessor node (Usually represents a waiter node) --通常是被阻塞者
cnode       --》 節(jié)點(diǎn)號(hào) 從9i開始才有
關(guān)于state 有如下幾種值:
IN_HANG      --》 該狀態(tài)是一個(gè)非常危險(xiǎn)的狀態(tài),通常表現(xiàn)為一個(gè)節(jié)點(diǎn)陷入了死循環(huán)或是hung。 一般來說出現(xiàn)這種情況,該節(jié)點(diǎn)的臨辟節(jié)點(diǎn)也是一樣的狀態(tài) 即adjlist
            如下例子:
            [16]/0/17/154/0x24617be0/26800/IN_HANG/29/32/[185]/19      ---從IN_HANG 我們可以看出 185是16的鄰居節(jié)點(diǎn),185被16阻塞
            [185]/1/16/4966/0x24617270//IN_HANG/30/31/[16]/16          ---從這里看 185阻塞了16(16是waiter)
LEAF         --》通常是被認(rèn)為blockers的重點(diǎn)對(duì)象。那么如何去確定呢? 一般來說,根據(jù)后面的predecesor來判斷該session是不是blocker或者是waiter。
             如下例子:
             [ nodenum]/cnode/sid/sess_srno/session/ospid/state/start/finish/[adjlist]/predecessor
             [16]/0/17/154/0x24617be0/26800/LEAF/29/30//19         --從這里看19是waiter 因此我們認(rèn)為17阻塞了20
             [19]/0/20/13/0x24619830/26791/NLEAF/33/34/[16]/186     
LEAF_NW     --》 跟leaf類似 不過可能會(huì)占用cpu
NLEAF       --》該狀態(tài)的session通常被認(rèn)為 “stuck” session。即其他session所需要的資源正被其holding。
IGN         --》該狀態(tài)的session通常是處理IDLE狀態(tài),除非其adjlist存在,如果是,那么該session正在等待其他session。
IGN_DMP     --》跟 IGN 類似。
如下例子:
[nodenum]/cnode/sid/sess_srno/session/ospid/state/start/finish/[adjlist]/predecessor
[16]/0/17/154/0x24617be0/26800/LEAF/29/30//19
[19]/0/20/13/0x24619830/26791/NLEAF/33/34/[16]/186
[189]/1/20/36/0x24619830//IGN/95/96/[19]/none
[176]/1/7/1/0x24611d80//IGN/75/76//none
----從上面看,189在等待19,19在等待16,而176是一個(gè)idle session。
SINGLE_NODE,SINGLE_NODE_NW 可以認(rèn)為跟LEAF,LEAF_NW一樣,除非沒有依賴對(duì)象。
本節(jié)我基于scott用戶產(chǎn)生兩個(gè)會(huì)話,模擬死鎖會(huì)話(一個(gè)update,一個(gè)delete)
SQL> oradebug help
HELP           [command]                 Describe one or all commands
SETMYPID                                 Debug current process
SETOSPID       <ospid>                   Set OS pid of process to debug
SETORAPID      <orapid> ['force']        Set Oracle pid of process to debug
SHORT_STACK                              Dump abridged OS stack
DUMP           <dump_name> <lvl> [addr]  Invoke named dump
DUMPSGA        [bytes]                   Dump fixed SGA
DUMPLIST                                 Print a list of available dumps
EVENT          <text>                    Set trace event in process
SESSION_EVENT  <text>                    Set trace event in session
DUMPVAR        <p|s|uga> <name> [level]  Print/dump a fixed PGA/SGA/UGA variable
DUMPTYPE       <address> <type> <count>  Print/dump an address with type info
SETVAR         <p|s|uga> <name> <value>  Modify a fixed PGA/SGA/UGA variable
PEEK           <addr> <len> [level]      Print/Dump memory
POKE           <addr> <len> <value>      Modify memory
WAKEUP         <orapid>                  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             <Inst-List | def | all>   Parallel oradebug command prefix
-R             <Inst-List | def | all>   Parallel oradebug prefix (return output
SETINST        <instance# .. | all>      Set instance list in double quotes
SGATOFILE      <SGA dump dir>         Dump SGA to file; dirname in double quotes
DMPCOWSGA      <SGA dump dir> Dump & map SGA as COW; dirname in double quotes
MAPCOWSGA      <SGA dump dir>         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      <ifname>  <ofname>        Helps translate PCs to names
WATCH          <address> <len> <self|exist|all|target>  Watch a region of memory
DELETE         <local|global|target> watchpoint <id>    Delete a watchpoint
SHOW           <local|global|target> 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           <func> [arg1] ... [argn]  Invoke function with arguments
SQL> oradebug hanganalyze 3;
Hang Analysis in /oracle/admin/orcl/udump/orcl_ora_2622.trc
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
-bash-3.2$ more /oracle/admin/orcl/udump/orcl_ora_2622.trc
/oracle/admin/orcl/udump/orcl_ora_2622.trc
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
ORACLE_HOME = /oracle/product/10.2.0/db_1
System name:    Linux
Node name:      truerhel5
Release:        2.6.18-164.el5
Version:        #1 SMP Tue Aug 18 15:51:48 EDT 2009
Machine:        x86_64
Instance name: orcl
Redo thread mounted by this instance: 1
Oracle process number: 21
Unix process pid: 2622, image:oracle@truerhel5(TNS V1-V3)

*** SERVICE NAME:(SYS$USERS) 2010-08-07 21:11:10.818
*** SESSION ID:(145.36) 2010-08-07 21:11:10.818
*** 2010-08-07 21:11:10.818
==============
HANG ANALYSIS:
==============
Open chains found:
Chain 1 : <cnode/sid/sess_srno/proc_ptr/ospid/wait_event> : --每列的注解:分為cnode sid sess_srno proc_ptr ospid wait_event
    <0/148/27/0x70e5e4a8/2543/SQL*Net message from client>   --會(huì)話148(持鎖會(huì)話)
-- <0/146/84/0x70e5f478/2607/enq: TX - row lock contention> --會(huì)話146(等待鎖會(huì)話),競爭事件為:row lock contention
Other chains found:
Chain 2 : <cnode/sid/sess_srno/proc_ptr/ospid/wait_event> :
    <0/144/108/0x70e5ccf0/2614/jobq slave wait>
Chain 3 : <cnode/sid/sess_srno/proc_ptr/ospid/wait_event> :
    <0/145/36/0x70e5fc60/2622/No Wait>
Chain 4 : <cnode/sid/sess_srno/proc_ptr/ospid/wait_event> :
    <0/150/2/0x70e623e8/2338/Streams AQ: waiting for time man>
Chain 5 : <cnode/sid/sess_srno/proc_ptr/ospid/wait_event> :
    <0/151/1/0x70e5ec90/2319/Streams AQ: qmn coordinator idle>
Chain 6 : <cnode/sid/sess_srno/proc_ptr/ospid/wait_event> :
    <0/158/7/0x70e61c00/2336/Streams AQ: qmn slave idle wait>
Extra information that will be dumped at higher levels:
[level  4] :   1 node dumps -- [REMOTE_WT] [LEAF] [LEAF_NW]
[level  5] :   5 node dumps -- [SINGLE_NODE] [SINGLE_NODE_NW] [IGN_DMP]
[level  6] :   1 node dumps -- [NLEAF]
[level 10] :  13 node dumps -- [IGN]

State of nodes
([nodenum]/cnode/sid/sess_srno/session/ospid/state/start/finish/[adjlist]/predecessor):
[143]/0/144/108/0x70f5dcf8/2614/SINGLE_NODE/1/2//none
[144]/0/145/36/0x70f5f130/2622/SINGLE_NODE_NW/3/4//none
[145]/0/146/84/0x70f60568/2607/NLEAF/5/8/[147]/none
[147]/0/148/27/0x70f62dd8/2543/LEAF/6/7//145
[149]/0/150/2/0x70f65648/2338/SINGLE_NODE/9/10//none
[150]/0/151/1/0x70f66a80/2319/SINGLE_NODE/11/12//none
[154]/0/155/1/0x70f6bb60/2315/IGN/13/14//none
[155]/0/156/1/0x70f6cf98/2313/IGN/15/16//none
[157]/0/158/7/0x70f6f808/2336/SINGLE_NODE/17/18//none
[159]/0/160/1/0x70f72078/2305/IGN/19/20//none
[160]/0/161/1/0x70f734b0/2303/IGN/21/22//none
[161]/0/162/1/0x70f748e8/2301/IGN/23/24//none
[162]/0/163/1/0x70f75d20/2299/IGN/25/26//none
[163]/0/164/1/0x70f77158/2297/IGN/27/28//none
[164]/0/165/1/0x70f78590/2295/IGN/29/30//none
[165]/0/166/1/0x70f799c8/2293/IGN/31/32//none
[166]/0/167/1/0x70f7ae00/2291/IGN/33/34//none
[167]/0/168/1/0x70f7c238/2289/IGN/35/36//none
[168]/0/169/1/0x70f7d670/2287/IGN/37/38//none
[169]/0/170/1/0x70f7eaa8/2285/IGN/39/40//none
====================
END OF HANG ANALYSIS
====================
其內(nèi)容意思大概如下
cnode--節(jié)點(diǎn)代號(hào),如果為rac,其值就存在,單節(jié)點(diǎn)的值為0
sid---session的sid
sess_srno---session的serial#
proc_ptr--系統(tǒng)進(jìn)程指向的address
ospid ----進(jìn)程號(hào)
wait_event---session的等待事件

轉(zhuǎn)摘白大師部分節(jié)選
Hanganalyze是從Oracle 8i r2(8.1.6)開始提供的,其用法十分簡單:
ALTER SESSION SET EVENTS 'immediate trace name HANGANALYZE level <level>';
或者
ORADEBUG hanganalyze <level>
比如:
sql>oradebug setmypid;
sql>oradebug hanganalyze 3;
對(duì)于<LEVEL>:
      10     Dump all processes (IGN state)
      5      Level 4 + Dump all processes involved in wait chains (NLEAF state)
      4      Level 3 + Dump leaf nodes (blockers) in wait chains (LEAF,LEAF_NW,IGN_DMP state)
      3      Level 2 + Dump only processes thought to be in a hang (IN_HANG state)
    1-2    Only HANGANALYZE output, no process dump at all
-bash-3.2$ sqlplus -prelim '/as sysdba' --通過prelim選項(xiàng)進(jìn)入已經(jīng)hang?。ㄕ7绞竭M(jìn)不了sqlplus)的數(shù)據(jù)庫
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Aug 7 21:17:42 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
SQL> show parameter sga
ORA-01012: not logged on
SQL> conn /as sysdba
Prelim connection established
SQL>

看完了這篇文章,相信你對(duì)“Oracle如何使用hanganalyze命令分析數(shù)據(jù)庫hang”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI