天天看點

如何利用oracle opatch打更新檔

本文主要介紹了如何利用ORACLE的OPATCH工具安裝更新檔,同時通過本文的描述,我們也應該了解确認BUG一般步驟:分析、排查相關錯誤資訊、對比環境、最終确認。

關鍵字: ORACLE、OPATCH、更新檔

1.      引言

       近幾年,随着我們ORACLE資料庫的應用越來越深入,使用者的環境越來越複雜,一些ORACLE常見的BUG也會偶爾的被觸發。是以,我們對技術人員要求不能再象以前一樣隻要求會安裝資料庫,還應該要求其掌握如何安裝更新檔才行,下面我們就結合一個案例,介紹下如何利用ORACLE OPATCH工具進行更新檔的安裝。

2.      案例描述

       前不久,某資料庫監聽在系統高峰期出現偶爾莫名宕掉的現象,導緻用戶端無法連接配接,但是重新啟動監聽又不報任何錯誤,及時重建監聽,現象依舊。聽到問題描述,我們首先檢查監聽停止時段的日志,發現有如下錯誤提示:

如何利用oracle opatch打更新檔

    查詢metalink後,發現有個類似案例《TNS Listener Crash with Core dump [ID 549932.1]》,适用于ORACLE10.2.0.3.0到11.1.0.6.0,平台是UNINX。該資料庫版本是10.2.0.4,但是平台是LINUX的,還是有點差別,需要進一步分析,但是看下面的現象,在系統日志(/var/log/messages)中,會出現如下提示:

如何利用oracle opatch打更新檔

文檔中還提到,在出現該錯誤的時間段,系統的虛拟記憶體會出現異常,于是我們通過配置跟蹤檔案,等待再次出現問題後,觀察下系統的虛拟記憶體觀察的情況如下:

如何利用oracle opatch打更新檔

  這些現象都同文檔的的錯誤現象一緻,是以,雖然個别條件有所差别,但是可以基本判斷為同一問題。接下來,我們就來看看解決問題的方法,該問題ORACLE官方提供的解決方法有2種:一種是加實體記憶體,一種是再目前平台打更新檔6139856。由于加實體記憶體涉及硬體投入,我們這裡考慮采用打更新檔的方式嘗試解決該問題。

3.      準備工作

       決定了采用打更新檔的解決思路,接下來就是做準備工作,首先,當然是下載下傳更新檔檔案(P6139856),然後把檔案上傳到伺服器的相關目錄,并進行解壓,當然在打更新檔前,對資料庫的備份是必不可少的,這些步驟我們就不再一一闡述,重點還是介紹下打更新檔的過程。

4.      操作過程

4.1.             閱讀說明

       在正式操作前,我們還是應該認真閱讀更新檔的說明,看看有什麼特别需要注意事情,這些在更新檔說明中都會有提示,如果你們沒有作特别的提示,我們就可以在正式環境中應用了,小更新檔的安裝其實比較簡單,主要利用ORACLE的OPATCH工具進行操作,OPATCH工具是ORACLE自帶的一個更新檔安裝程式,預設ORACLE安裝後就自帶該工具,是以無需我們再單獨安裝。

4.2.             檢查環境

       每個更新檔的應用都有一定的環境,包括資料庫版本、OPATCH版本等,首先應該對這些環境進行檢查,通過指令opatch lsinventory檢查,操作如下:

Last login: Fri Jul 30 10:08:59 2010

[oracle@wzy01 ~]$ cd 6139856/                  #進入更新檔檔案目錄           

[oracle@wzy01 6139856]$ ls

etc  files  README.txt

[oracle@wzy01 6139856]$ opatch lsinventory     #用opatch lsinventory檢查環境

Invoking OPatch 10.2.0.4.2

Oracle Interim Patch Installer version 10.2.0.4.2

Copyright (c) 2007, Oracle Corporation.  All rights reserved.

Oracle Home       : /u01/oracle/product/db10gr2

Central Inventory : /u01/oracle/oraInventory

   from           : /etc/oraInst.loc

OPatch version    : 10.2.0.4.2                                  #opatch版本

OUI version       : 10.2.0.4.0

OUI location      : /u01/oracle/product/db10gr2/oui

Log file location : /u01/oracle/product/db10gr2/cfgtoollogs/opatch/opatch2010-07-30_11-16-12AM.log

Lsinventory Output file location : /u01/oracle/product/db10gr2/cfgtoollogs/opatch/lsinv/lsinventory2010-07-30_11-16-12AM.txt

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

Installed Top-level Products (2):

Oracle Database 10g                                                  10.2.0.1.0

Oracle Database 10g Release 2 Patch Set 3                            10.2.0.4.0                                                                    #oracle大版本

There are 2 products installed in this Oracle Home.

There are no Interim patches installed in this Oracle Home.

OPatch succeeded.

4.3.             停資料庫

       在打更新檔的時候,會有檔案的覆寫替換,是以,大部分時候,在打更新檔的時候是要求資料庫處于關閉狀态,是以,我們需要把資料庫執行個體關閉。

SQL> conn / as sysdba

已連接配接。

SQL> shutdown immediate

資料庫已經關閉。

已經解除安裝資料庫。

ORACLE 例程已經關閉。

SQL>

4.4.             應用更新檔

       更新檔的安裝也非簡單,如果前面的環境都沒有問題,直接運作下opatch apply就行了,OPATCH工具會自動應用更新檔,完成更新檔的安裝,如下:

[oracle@wzy01 6139856]$ opatch apply     #在更新檔檔案目錄中用opatch apply應用更新檔

OPatch version    : 10.2.0.4.2

Log file location : /u01/oracle/product/db10gr2/cfgtoollogs/opatch/opatch2010-07-30_11-16-16AM.log

ApplySession applying interim patch '6139856' to OH '/u01/oracle/product/db10gr2'

Running prerequisite checks...

OPatch detected non-cluster Oracle Home from the inventory and will patch the local system only.

Please shutdown Oracle instances running out of this ORACLE_HOME on the local system.

(Oracle Home = '/u01/oracle/product/db10gr2')

Is the local system ready for patching? [y|n]        #詢問是否更新檔案,輸入Y更新

y

User Responded with: Y

Backing up files and inventory (not for auto-rollback) for the Oracle Home

Backing up files affected by the patch '6139856' for restore. This might take a while...

Backing up files affected by the patch '6139856' for rollback. This might take a while...

Patching component oracle.rdbms, 10.2.0.4.0...

Updating archive file "/u01/oracle/product/db10gr2/lib/libn10.a"  with "lib/libn10.a/nsev.o"

Updating archive file "/u01/oracle/product/db10gr2/lib32/libn10.a"  with "lib32/libn10.a/nsev.o"

Patching component oracle.rdbms.rsf, 10.2.0.4.0...

Running make for target client_sharedlib

Running make for target ioracle

ApplySession adding interim patch '6139856' to inventory

Verifying the update...

Inventory check OK: Patch ID 6139856 is registered in Oracle Home inventory with proper meta-data.

Files check OK: Files from Patch ID 6139856 are present in Oracle Home.

The local system has been patched and can be restarted.

OPatch succeeded.                                 #更新檔更新成功

4.5.             檢查核實

       最後,我們要看一下,更新檔安裝情況,同樣我們通過opatch lsinventory指令進行檢視,如下:

[oracle@wzy01 6139856]$ opatch lsinventory

Log file location : /u01/oracle/product/db10gr2/cfgtoollogs/opatch/opatch2010-07-30_11-23-32AM.log

Lsinventory Output file location : /u01/oracle/product/db10gr2/cfgtoollogs/opatch/lsinv/lsinventory2010-07-30_11-23-32AM.txt

Oracle Database 10g Release 2 Patch Set 3                            10.2.0.4.0

Interim patches (1) :

Patch  6139856      : applied on Fri Jul 30 11:21:01 CST 2010

   Created on 28 Jul 2008, 01:14:03 hrs PST8PDT

   Bugs fixed:

     6139856                                                                 #這裡可以看到,更新檔已經安裝成功