oracle實驗記錄 (使用hanganlyze&oradebug)
針對oracle的DML dead lock oracle 會通過pmon發現並自動清理 回退其中的一個操作(是該事務的一個操作,而不是回退整個transaction),當PINS 或latches時oracle 不會檢測處理這種dead lock
使用hanganlye可以檢視db中各種資源的堵塞情況
例簡單的lock 等待
SQL> create table t1 (a int);
表已建立。
SQL> select distinct sid from v$mystat;
SID
----------
159
SQL> insert into t1 values(1);
已建立 1 行。
SQL> commit;
提交完成。
SQL> update t1 set a=2;
已更新 1 行。
SQL> select distinct sid from v$mystat;
SID
----------
146
SQL> update t1 set a=3;(hange住了)
LEVEL
1-2 Only HANGANALYZE output, no process dump at all(只有hanganalyeze輸出,不dump任何程式)
3 Level 2 + Dump only processes thought to be in a hang (IN_HANG state)(DUMP IN_HANGE狀態的程式)
4 Level 3 + Dump leaf nodes (blockers) in wait chains (LEAF,LEAF_NW,IGN_DMP state)
5 Level 4 + Dump all processes involved in wait chains (NLEAF state)
10 Dump all processes (IGN state)
SQL> oradebug setmypid
已處理的語句 ORADEBUG setinst all(寫上這個的話 對所有instance)
SQL> oradebug hanganalyze 3
Hang Analysis in d:\oracle\product\10.2.0\admin\xh\udump\xh_ora_23712.trc
打看下trace 檔案
Open chains found:
Chain 1 :
<0/159/1/0x3424c60c/21212/SQL*Net message from client>
-- <0/146/23/0x3424e3bc/23324/enq: TX - row lock contention>
~可以看到oracle發現 159,l46爭奪LOCK ,wait_event:146等待159釋放lock(TX)
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):
上面是解釋下面的格式
nodenum:hanganalyze為記錄session自動建立的編號,從0開始
sid:session sid
CNODE:node id
sess_srno:session serial#
ospid:os process id(v$process spid)
state:node狀態
adjlist:blocker node
predecessor:waiter node
nodestat:又有幾種狀態
in_hang:表示該node處於dead lock,一般還是其它node(blocker)也處於該狀態
leaf/leaf_nw:此node一般是 BLOCKER,用predecessor可判斷是否是blocker,leaf說明 該node沒有等待資源,leaf_nw可能是沒有等待其它資源或者在使用CPU
NLEAF:一般是被堵塞資源,一般表示db發生效能問題,而不是hang
IGN/IGN-PMP:這類會話通常被認為是空閒會話,除非其adjlist列裡存在node。如果是非空閒會話則說明其adjlist裡的node正在等待其他node釋放資源。
SINGLE_NODE/SINGLE_NODE_NW:近似於空閒會話
以上解釋參考 ITPUB文件 使用hanganaly 楊洪志
([nodenum]/cnode/sid/sess_srno/session/ospid/state/start/finish/[adjlist]/predecessor):
[141]/0/142/50/0x3432b2dc/23712/SINGLE_NODE_NW/1/2//none
[142]/0/143/1/0x3432c5a4/21232/SINGLE_NODE/3/4//none
[143]/0/144/4/0x3432d86c/22208/SINGLE_NODE/5/6//none
[145]/0/146/23/0x3432fdfc/23324/NLEAF/7/10/[158]/none
[148]/0/149/1/0x34333654/18920/SINGLE_NODE/11/12//none
[154]/0/155/1/0x3433a704/20880/IGN/13/14//none
[155]/0/156/1/0x3433b9cc/20864/IGN/15/16//none
[156]/0/157/122/0x3433cc94/23964/SINGLE_NODE/17/18//none
[158]/0/159/1/0x3433f224/21212/LEAF/8/9//145
[159]/0/160/1/0x343404ec/19360/IGN/19/20//none
分析上面:
[145]/0/146/23/0x3432fdfc/23324/NLEAF/7/10/[158]/none
SID 146,SERIAL#,23,NODESTAT:nleaf(被堵塞資源),ADJLIST:158(blocker 158(NODE)),PERDECESSOR:none
[158]/0/159/1/0x3433f224/21212/LEAF/8/9//145
SID 159,SERIAL#1,NODESTAT:LEAF(BLOCKEER),ADJLIST:NULL,PERDECESSOR:被阻塞資源 145NODE
可以看到NODE 158 堵塞了NODE 145
另外兩種設定方式
alter session set events 'immediate trace name hanganalyze level n';
ORADEBUG hanganalyze
使用oradebug
SQL> oradebug help 檢視幫助 Once a process has been selected, this will be used as the ORADEBUG process until another process is selected The SETMYPID command selects the current process as the ORADEBUG process For example ORADEBUG SETMYPID Do not use ORADEBUG SETMYPID if you intend to use the ORADEBUG SUSPEND command SETORAPID command Once a process has been selected, this will be used as the ORADEBUG process until another process is selected The SETORAPID command selects another process using the Oracle PID as the ORADEBUG process The syntax is ORADEBUG SETORAPID pid To obtain the Oracle process ID for a foreground process use SELECT pid FROM v$process Once a process has been selected, this will be used as the ORADEBUG process until another process is selected The SETOSPID command selects the another process using the operating system PID as the ORADEBUG process The syntax is ORADEBUG SETOSPID pid On Unix the PID of interest may have been identified using a top or ps command TRACEFILE_NAME command ORADEBUG TRACEFILE_NAME /export/home/admin/SS92003/udump/ss92003_ora_14917.trc UNLIMIT command To remove the limitation on the size of the trace file use ORADEBUG UNLIMIT FLUSH command ORADEBUG FLUSH ORADEBUG CLOSE_TRACE First select a process using SETORAPID or SETOSPID Do not use SETMYPID as the current ORADEBUG process will hang and cannot be resumed even from another ORADEBUG process For example the command ORADEBUG SUSPEND ORADEBUG RESUME This example demonstrates how to take a heap dump during a large (sorting) query This example requires two sessions, session 1 logged on SYS AS SYSDBA and session 2 which executes the query. In session 2 identify the PID using SELECT pid FROM v$process In session 1 set the Oracle PID using ORADEBUG SETORAPID 12 SELECT ... FROM t1 ORDER BY .... ORADEBUG SUSPEND In session 1 run the heap dump ORADEBUG DUMP HEAPDUMP 1 In session 1 resume session 2 ORADEBUG RESUME RESUME command First select a process using SETORAPID or SETOSPID Do not use SETMYPID as the current ORADEBUG process will hang and cannot be resumed even from another ORADEBUG process For example the command ORADEBUG SUSPEND ORADEBUG RESUME See SUSPEND for an example of use of the SUSPEND and RESUME commands WAKEUP command ORADEBUG WAKEUP pid SELECT pid FROM v$process ORADEBUG WAKEUP 6 DUMP command ORADEBUG DUMP dumpname level ORADEBUG SETMYPID ORADEBUG EVENT event TRACE NAME CONTEXT FOREVER, LEVEL level ORADEBUG SETORAPID 8 ORADEBUG SESSION_EVENT event TRACE NAME CONTEXT FOREVER, LEVEL level ORADEBUG SESSION_EVENT 10046 TRACE NAME CONTEXT FOREVER, LEVEL 12 ORADEBUG DUMPSGA ORADEBUG DUMPVAR SGA variable_name ORADEBUG DUMPVAR SGA kcbnhb The names of SGA variables can be found in X$KSMFSV.KSMFSNAM. Variables in this view are suffixed with an underscore e.g. kcbnhb_ ORADEBUG PEEK address length For example ORADEBUG PEEK 0x20005F0C 12 POKE ORADEBUG POKE address length value For Example ORADEBUG POKE 0x20005F0C 4 0x46495845 IPC ORADEBUG IPC On Solaris, similar information can be obtained using the operating system command ipcs -b Freeze the instance using ORADEBUG FFBEGIN ORADEBUG SGATOFILE directory ORADEBUG FFRESUMEINST 基本使用 SQL> oradebug event 10046 trace name context forever,level 12 使用OSPID(os process id,v$process中SPID) SQL> select distinct sid from v$mystat; SID SPID PID SQL> insert into t1 values(1);(SID 146 已經hang) SQL> oradebug resume;(另一SESSION ) 已建立 1 行。(SID 146) SQL> oradebug setorapid 20 (針對 oracle process id,v$process pid)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12020513/viewspace-615165/,如需轉載,請註明出處,否則將追究法律責任。
HELP [command] Describe one or all commands
SETMYPID Debug current process
SETOSPID
SETORAPID
SHORT_STACK Dump abridged OS stack
DUMP
DUMPSGA [bytes] Dump fixed SGA
DUMPLIST Print a list of available dumps
EVENT
SESSION_EVENT
DUMPVAR
DUMPTYPE
SETVAR
PEEK
POKE
WAKEUP
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
-R
SETINST
SGATOFILE
DMPCOWSGA
MAPCOWSGA
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
WATCH
DELETE
SHOW
CORE Dump core without crashing process
UNLIMIT Unlimit the size of the trace file
PROCSTAT Dump process statistics
CALL
SETMYPID command
Before using ORADEBUG commands, a process must be selected. Depending on the commands to be issued, this can either be the current process or another process
ORADEBUG SETMYPID can be used to select the current process to run systemwide commands such as dumps
Before using ORADEBUG commands, a process must be selected. Depending on the commands to be issued, this can either be the current process or another process
where pid is the Oracle process ID of the target process For example
ORADEBUG SETORAPID 9
The Oracle process id for a process can be found in V$PROCESS.PID
WHERE addr =
(
SELECT paddr FROM v$session
WHERE sid = DBMS_SUPPORT.MYSID
);
Alternatively, if the DBMS_SUPPORT package is not available use
SELECT pid FROM v$process
WHERE addr =
(
SELECT paddr FROM v$session
WHERE sid =
(
SELECT sid FROM v$mystat WHERE ROWNUM = 1
)
);
To obtain the process ID for a background process e.g. SMON use
SELECT pid FROM v$process
WHERE addr =
(
SELECT paddr FROM v$bgprocess
WHERE name = 'SMON'
);
To obtain the process ID for a dispatcher process e.g. D000 use
SELECT pid FROM v$process
WHERE addr =
(
SELECT paddr FROM v$dispatcher
WHERE name = 'D000'
);
To obtain the process ID for a shared server process e.g. S000 use
SELECT pid FROM v$process
WHERE addr =
(
SELECT paddr FROM v$shared_server
WHERE name = 'S000'
);
To obtain the process ID for a job queue process e.g. job 21 use
SELECT pid FROM v$process
WHERE addr =
(
SELECT paddr FROM v$session
WHERE sid =
(
SELECT sid FROM dba_jobs_running WHERE job = 21
)
);
To obtain the process ID for a parallel execution slave e.g. P000 use
SELECT pid FROM v$px_process
WHERE server_name = 'P000';
SETOSPID command
Before using ORADEBUG commands, a process must be selected. Depending on the commands to be issued, this can either be the current process or another process
where pid is the operating system process ID of the target process For example
ORADEBUG SETOSPID 34345
The operating system process ID is the PID on Unix systems and the thread number on Windows NT/2000 systems
This command prints the name of the current trace file e.g.
For example
This command does not work on Windows 2000 (Oracle 9.2)
In Oracle 8.1.5 and below the maximum size of the trace file is restricted by default. This means that large dumps (LIBRARY_CACHE, BUFFERS) may fail.
In Oracle 8.1.6 and above the maximum size of the trace file defaults to UNLIMITED
To flush the current contents of the trace buffer to the trace file use
CLOSE_TRACE command
To close the current trace file use
SUSPEND command
This command suspends the current process
suspends the current process
The command
resumes the current process
While the process is suspended ORADEBUG can be used to take dumps of the current process state e.g. global area, heap, subheaps etc.
WHERE addr IN
(
SELECT paddr FROM v$session
WHERE sid = dbms_support.mysid
);
In this example the PID was 12
In session 2 start the query
In session 1 suspend session 2
The query in session 2 will be suspended
The heapdump will show the memory structures allocated for the sort. At this point further dumps e.g. subheap dumps can be taken.
The query in session 2 will resume execution
This command resumes the current process
suspends the current process
The command
resumes the current process
While the process is suspended ORADEBUG can be used to take dumps of the current process state e.g. global area, heap, subheaps etc.
To wake up a process use
For example to wake up SMON, first obtain the PID using
WHERE addr =
(
SELECT paddr FROM v$bgprocess
WHERE name = 'SMON'
);
If the PID is 6 then send a wakeup call using
To perform. a dump use
For example for a level 4 dump of the library cache use
ORADEBUG DUMP LIBRARY_CACHE 4
EVENT command
To set an event in a process use
For example to set event 10046, level 12 in Oracle process 8 use
ORADEBUG EVENT 10046 TRACE NAME CONTEXT FOREVER, LEVEL 12
SESSION_EVENT command
To set an event in a session use
For example
DUMPSGA
To dump the fixed SGA use
DUMPVAR
To dump an SGA variable use
e.g.
which returns the number of hash buckets in the buffer cache
PEEK
To peek memory locations use
where address can be decimal or hexadecimal and length is in bytes
returns 12 bytes starting at location 0x20005f0c
To poke memory locations use
where address and value can be decimal or hexadecimal and length is in bytes
ORADEBUG POKE 0x20005F10 4 0x44205349
ORADEBUG POKE 0x20005F14 2 0x5A45
WARNING Do not use the POKE command on a production system
To dump information about operating system shared memory and semaphores configuration use the command
This command does not work on Windows NT or Windows 2000 (Oracle 9.2)
Dumping the SGA
In some versions it is possible to dump the entire SGA to a file
Dump the SGA to a file using
Unfreeze the instance using
使用oradebug來設定 event
SQL> oradebug setmypid
已處理的語句
SQL> oradebug unlimit 不限制trace 大小
已處理的語句
已處理的語句
SQL> oradebug event 10046 trace name context off
已處理的語句
使用oradebug 掛起程式
----------
146
SQL> select spid,pid from v$process a,v$session b where a.addr=b.paddr and b.sid=14(另一個SESSION)
6;
------------ ----------
23324 20
SQL> oradebug setospid 23324
Oracle pid: 20, Windows thread id: 23324, image: ORACLE.EXE (SHAD)
SQL> oradebug suspend
已處理的語句
已處理的語句
SQL>
Windows thread id: 23324, image: ORACLE.EXE (SHAD)
SQL> oradebug suspend
已處理的語句
SQL>
另外orade 還有些dump功能
SQL> oradebug dump library_cache 4;
已處理的語句
相關文章
- 大資料實驗記錄大資料
- Oracle實驗(03):number的使用Oracle
- Laravel 使用個人經驗記錄Laravel
- mysql load 相關實驗記錄MySql
- 使用ogg 從oracle 同步mysql遇到問題記錄OracleMySql
- STM32F207DAC實驗記錄
- 使用DBUA升級 Oracle 11.2.0.4到Oracle 19C的問題記錄Oracle
- SEO 經驗記錄
- laravel-admin 使用經驗記錄一波Laravel
- 2.13.3 使用 Oracle Wallet 實現在DBCA中使用身份驗證Oracle
- overlay網路隔離實驗失敗記錄
- 《learn to count everything》論文閱讀、實驗記錄
- Oracle實驗(04):floatOracle
- Oracle報錯>記錄被另外一個使用者鎖定Oracle
- STM32F207串列埠實驗記錄串列埠
- vscode 使用記錄VSCode
- IPython 使用記錄Python
- Ubuntu使用記錄Ubuntu
- webpack使用記錄Web
- angr使用記錄
- Mac使用記錄Mac
- vim使用記錄
- codesandbox 使用記錄
- supervisor 使用記錄
- MinIO使用記錄
- vue 使用記錄Vue
- css使用記錄CSS
- phpword使用記錄PHP
- GRPC使用記錄RPC
- kaggle使用記錄
- Oracle實驗(01):字元 & 位元組Oracle字元
- 使用 HTML 實現截圖-html2canvas使用記錄HTMLCanvas
- oracle awr快照點不記錄問題Oracle
- Python使用ClickHouse的實踐與踩坑記錄Python
- Navicat Oracle 刪除使用者錯誤ora-01922 個人記錄Oracle
- 專案重構經驗記錄
- Redis 使用記錄(一)Redis
- linux apache 使用記錄LinuxApache
- Git 命令使用記錄Git