使用HangFG進行Oracle Hang分析

realkid4發表於2015-08-31

Database Hang是很嚴重的系統故障。Oracle資料庫是一個極其複雜的整體,多種功能、特性和屬性在各種生產條件下執行的時候,經常會暴露出一些問題,由此一些Hang住現象就會出現。

最常見的Hang表現就是不對外服務、不支援連線、伺服器資源負載較低。主要的根源在於記憶體資源、Latch/Lock鎖定相互等待、後臺程式僵死。發生Hang現象的時候,最簡單、常用的處理方式是自認倒黴,關機重啟(有時候重啟庫不支援)。

放任Hang現象是很危險的,主要在於其對於資料庫可用性是及其嚴重的破壞效應。進行Hang分析,定位問題關鍵、嘗試去解決問題其實是非常重要的。

根據Oracle官方分析策略,Hang發生的時候,需要使用者將系統多個程式的狀態以trace檔案的方式Dump出來,傳送給官方服務支援進行分析。Hang現象很多時候是不能刻意重現的,發生故障時快速定位問題,將狀態迅速匯出來是比較關鍵的。

傳統上,我們使用過oradebughanganalyze配合dump systemstate將系統記憶體狀態、各個程式情況。這種方法操作起來需要命令列支援,而且生成分析檔案分佈在多處。基於此,Oracle官方推薦了HangFGHang File Generator)來支援自動化Hang分析檔案收集。本篇主要介紹HangFG安裝和使用方法,留待不時之需。

 

1、環境說明

 

筆者使用Oracle 11gR2進行測試,具體版本為11.2.0.4

 

 

SQL> select * from v$version;

 

BANNER

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

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

PL/SQL Release 11.2.0.4.0 - Production

CORE    11.2.0.4.0      Production

TNS for Linux: Version 11.2.0.4.0 - Production

NLSRTL Version 11.2.0.4.0 – Production

 

 

下載HangFG要從Oracle官方MOS上,對應文章編號: ID 362094.1。下載後的檔案是一個壓縮格式檔案,透過FTP上傳到伺服器。

 

 

[oracle@sicslife upload]$ ls -l

total 2625144

-rw-r--r--  1 root   root          51200 Aug 31 22:26 hangfg.tar

 

 

2HangFG安裝使用

 

解壓tar檔案,就完成安裝過程。

 

 

[root@sicslife upload]# tar -xvf hangfg.tar

hangfg/

hangfg/haLevel.sh

hangfg/test_rconnection2.sh

hangfg/hangfg.sh

hangfg/test_rconnection.sh

hangfg/ssLocal.sh

hangfg/README

hangfg/test_connection.sh

hangfg/ss.sh

hangfg/haLocalLevel.sh

hangfg/hq.sh

 

 

同其他很多Oracle推出的工具一樣,HangFG是一系列bash scripts構成的程式檔案。

 

 

[root@sicslife upload]# ls -l

total 2625148

drwxr-xr-x  2 oracle oinstall       4096 Oct 25  2012 hangfg

 

[root@sicslife upload]# cd hangfg

[root@sicslife hangfg]# ls -l

total 72

-rwxr-xr-x 1 oracle oinstall   312 Apr  9  2007 haLevel.sh

-rwxr-xr-x 1 oracle oinstall   305 Apr  9  2007 haLocalLevel.sh

-rwxr-xr-x 1 oracle oinstall 30363 Oct 25  2012 hangfg.sh

-rwxr-xr-x 1 oracle oinstall   366 Apr  9  2007 hq.sh

-rw-r--r-- 1 oracle oinstall  4146 Oct 25  2012 README

-rwxr-xr-x 1 oracle oinstall   279 Oct 25  2012 ssLocal.sh

-rwxr-xr-x 1 oracle oinstall   285 Oct 25  2012 ss.sh

-rwxr-xr-x 1 oracle oinstall    86 Apr  9  2007 test_connection.sh

-rwxr-xr-x 1 oracle oinstall    69 Apr  9  2007 test_rconnection2.sh

-rwxr-xr-x 1 oracle oinstall    58 Apr  9  2007 test_rconnection.sh

 

 

呼叫方法上,hangfg是非常簡單的,只包括一個引數作為輸入,用於指定不同程度的分析級別。

分析級別引數:

 

ü  引數值1:對系統最小的影響級別。會持續收集兩次level 3hanganalyze資料,如果系統負載較輕的話,會繼續收集一次level 4級別的hanganalyze

ü  引數值2:系統預設取值。對系統效能有中等程度影響,首先要收集一次level 3hanganalyze。之後如果系統負載可以接受,會進行兩次Level 4級別的hanganalyze操作。如果系統負載過大,會進行一次Level 3級別的hanganalyze操作。系統也會收集一次258級別的系統狀態;

ü  引數值3:連續進行兩次Level 4hanganalyze操作,同時進行一次258級別的系統狀態收集;

 

如果在RAC環境下,hangfg可以自動對所有節點進行收集。

執行hangfg方法。

 

 

[root@sicslife hangfg]# su - oracle

[oracle@sicslife ~]$ cd /upload/hangfg

 

[oracle@sicslife hangfg]$ ./hangfg.sh 2

 

Starting Hang File Generator V 1.2.0 on Mon Aug 31 23:14:23 CST 2015

HANGFG - Written by Carl Davis, Center of Expertise, Oracle Corporation

 

rm: cannot remove `*.tmp': No such file or directory

 

Searching for udump/bdump...

 

/u01/app/oracle/diag/rdbms/sicsdb/sicsdb/trace

/u01/app/oracle/diag/rdbms/sicsdb/sicsdb/trace

Database connection established.

 

Skipping remote node file collection...

Treating collection as single node (non RAC).

 

Please wait. File operations in progress...

Processing Medium Impact Hang Trace Collection...

Starting HangAnalyze Trace. Please Wait...

Statement processed.

Statement processed.

Hang Analysis in /u01/app/oracle/diag/rdbms/sicsdb/sicsdb/trace/sicsdb_ora_19908.trc

HA Filename=/u01/app/oracle/diag/rdbms/sicsdb/sicsdb/trace/sicsdb_ora_19908.trc

blockers=

Blocker info missing. Cannot continue with level 4 dump.

Starting HangAnalyze Trace. Please Wait...

Statement processed.

Statement processed.

Hang Analysis in /u01/app/oracle/diag/rdbms/sicsdb/sicsdb/trace/sicsdb_ora_19923.trc

 

Starting Systemstate Trace. Please Wait...

 

SQL*Plus: Release 11.2.0.4.0 Production on Mon Aug 31 23:16:34 2015

 

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

 

SQL> Connected.

SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> Statement processed.

SQL> Statement processed.

SQL> Statement processed.

SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

 

Copying files to hangFileArchive...

 

Creating tarball of all hangfiles...

 

hangFileArchive/

hangFileArchive/sicsdb_ora_19980.trm

hangFileArchive/sicsdb_ora_19923.trc

hangFileArchive/sicsdb_dbrm_17833.trm

hangFileArchive/alert_sicsdb.log

hangFileArchive/sicsdb_ora_19980.trc

hangFileArchive/sicsdb_ora_19923.trm

hangFileArchive/sicsdb_ora_19908.trc

hangFileArchive/hangfiles.out

hangFileArchive/sicsdb_dbrm_17833.trc

hangFileArchive/sicsdb_ora_19908.trm

./hangfg.sh[1036]: compress: not found [No such file or directory]

 

Program hangfg terminated successfully.

More information contained in hangfg.log

 

 

3、結果解析

 

hangFG操作之後,Oracle例項在對應的dump目錄中生成若干trc檔案。重要的是,工具將資料檔案收集在當前目錄下。

 

 

[oracle@sicslife hangfg]$ ls -l

total 1192

-rw-r--r-- 1 oracle oinstall       0 Aug 31 23:14 conn.test

-rwxr-xr-x 1 oracle oinstall     312 Apr  9  2007 haLevel.sh

-rwxr-xr-x 1 oracle oinstall     305 Apr  9  2007 haLocalLevel.sh

-rw-r--r-- 1 oracle oinstall     127 Aug 31 23:16 hanganalyze.tmp

-rw-r--r-- 1 oracle oinstall    6642 Aug 31 23:16 hangfg.log

-rwxr-xr-x 1 oracle oinstall   30359 Aug 31 23:11 hangfg.sh

drwxr-xr-x 2 oracle oinstall    4096 Aug 31 23:16 hangFileArchive

-rw-r--r-- 1 oracle oinstall    1598 Aug 31 23:16 hangfiles.out

-rw-r--r-- 1 oracle oinstall 1116160 Aug 31 23:16 hfiles.tar

-rwxr-xr-x 1 oracle oinstall     366 Apr  9  2007 hq.sh

-rw-r--r-- 1 oracle oinstall     402 Aug 31 23:14 hq.tmp

-rw-r--r-- 1 oracle oinstall    1220 Aug 31 23:16 localhangfiles.tmp

-rw-r--r-- 1 oracle oinstall    4146 Oct 25  2012 README

-rwxr-xr-x 1 oracle oinstall     279 Oct 25  2012 ssLocal.sh

-rwxr-xr-x 1 oracle oinstall     285 Oct 25  2012 ss.sh

-rwxr-xr-x 1 oracle oinstall      82 Aug 31 23:12 test_connection.sh

-rwxr-xr-x 1 oracle oinstall      65 Aug 31 23:12 test_rconnection2.sh

-rwxr-xr-x 1 oracle oinstall      54 Aug 31 23:12 test_rconnection.sh

 

 

在目錄hangFileArchive中,收集檔案可以直接找到。

 

 

[oracle@sicslife hangfg]$ cd hangFileArchive/

[oracle@sicslife hangFileArchive]$ ls -l

total 1104

-rw-r----- 1 oracle oinstall  91177 Aug 31 23:16 alert_sicsdb.log

-rw-r--r-- 1 oracle oinstall   1598 Aug 31 23:16 hangfiles.out

-rw-r----- 1 oracle oinstall  17963 Aug 31 23:16 sicsdb_dbrm_17833.trc

-rw-r----- 1 oracle oinstall    550 Aug 31 23:16 sicsdb_dbrm_17833.trm

-rw-r----- 1 oracle oinstall   3224 Aug 31 23:16 sicsdb_ora_19908.trc

-rw-r----- 1 oracle oinstall    113 Aug 31 23:16 sicsdb_ora_19908.trm

-rw-r----- 1 oracle oinstall   3224 Aug 31 23:16 sicsdb_ora_19923.trc

-rw-r----- 1 oracle oinstall    113 Aug 31 23:16 sicsdb_ora_19923.trm

-rw-r----- 1 oracle oinstall 899566 Aug 31 23:16 sicsdb_ora_19980.trc

-rw-r----- 1 oracle oinstall  86711 Aug 31 23:16 sicsdb_ora_19980.trm

 

 

同時,壓縮檔案hfiles.tar

 

 

-rw-r--r-- 1 oracle oinstall 1116160 Aug 31 23:16 hfiles.tar

 

 

4、結論

 

HangFG是一個快速進行hanganalyze的有用工具。藉助HangFG,可以最快的進行資料收集工作,並且將其提交到官方支援。


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

相關文章