Oracle的Central Inventory和Local inventory詳解

羽化殘虹發表於2014-07-19
https://blogs.oracle.com/Database4CN/entry/oracle%E7%9A%84central_inventory%E5%92%8Clocal_inventory%E8%AF%A6%E8%A7%A3

很多朋友對Oracle的inventory資訊不太瞭解以至遇到相關的問題不知道如何處理,這篇文章我們將詳細講解Oracle的Central Inventory (oraInventory)和Local Inventory (Oracle Home inventory) 

首先我們通過檢視$ opatch lsinventory的輸出來丟擲幾個問題:
[oracle@dbnode1 OPatch]$ ./opatch lsinventory
Invoking OPatch 11.2.0.1.7 
Oracle Interim Patch Installer version 11.2.0.1.7
Copyright (c) 2011, Oracle Corporation.  All rights reserved.
Oracle Home       : /u01/app/oracle/product/11.2.0/db_1
Central Inventory : /u01/app/oraInventory  <<<<<=====什麼是Central Inventory?
   from           : /etc/oraInst.loc<<<<<=====oraInst.loc是什麼檔案,它有什麼作用?如果它被刪除掉了會怎麼樣?
OPatch version    : 11.2.0.1.7<<<<<=====這是OPatch版本?
OUI version       : 11.2.0.3.0<<<<<=====OUI version 這裡OUI 版本是指的什麼?  
Log file location : /u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2014-03-23_21-03-24PM.log
Lsinventory Output file location : /u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/lsinv/lsinventory2014-03-23_21-03-24PM.txt
--------------------------------------------------------------------------------
Installed Top-level Products (1): 
Oracle Database 11g                                                  11.2.0.3.0
There are 1 products installed in this Oracle Home. 
There are no Interim patches installed in this Oracle Home.
--------------------------------------------------------------------------------
OPatch succeeded.
這裡OPatch version 就是Opatch的版本,它是不同於資料庫版本的。
如果OPatch 版本過低那打patch時就會報錯,不過這個問題很快可以通過檢視patch的readme通過其指定的Note 下載最新的Opatch 來解決。
OUI version 就是安裝的ORACLE_HOME的版本
言歸正傳,什麼是Central Inventory (oraInventory)呢 ?
每一個安裝了Oracle產品的作業系統上都至少有一個Central Inventory (oraInventory),他通過一個叫做inventory.xml的檔案記錄了在此作業系統上安裝過的Oracle Homes等資訊。
實際上Oracle就是通過Central Inventory (oraInventory) 來確定Oracle Home的位置,名稱,是否是CRS_HOME及其他節點等資訊的。

我們可以具體看一下inventory.xml的內容:
inventory.xml位置就在< Central Inventory >/ContentsXML/inventory.xml
例如:
[oracle@dbnode1 OPatch]$ cd /u01/app/oraInventory/ContentsXML/
[oracle@dbnode1 ContentsXML]$ ls
comps.xml  inventory.xml  libs.xml
[oracle@dbnode1 ContentsXML]$ cat inventory.xml 

<!-- Copyright (c) 1999, 2011, Oracle. All rights reserved. --&gt
<!-- Do not modify the contents of this file by hand. --&gt


   11.2.0.3.0
   2.1.0.6.0







[oracle@dbnode1 ContentsXML]$ pwd
/u01/app/oraInventory/ContentsXML
這裡我們只安裝了一個ORACLE_HOME它的名字叫OraDb11g_home1,路徑在/u01/app/oracle/product/11.2.0/db_1。
請注意這裡TYPE="O" IDX="1"
TYPE="O"意思是這是一個ORACLE資料庫的HOME,如果它後面還有CRS="true"這樣的標記就表明這是一個CRS_HOME。
IDX="1" 意思就是該HOME是第一個安裝的產品。
我們再看一個安裝了CRS的inventory.xml輸出來對比一下
[oracle@ ContentsXML]$ cat inventory.xml 

<!-- Copyright (c) 1999, 2011, Oracle. All rights reserved. --&gt
<!-- Do not modify the contents of this file by hand. --&gt


   11.2.0.3.0
   2.1.0.6.0



  
     
     
  


  
     
     
  





通過對比我們已經非常明顯的看到inventory.xml 裡記錄了詳細ORACLE_HOME資訊。
問題是Oracle是如何知道< Central Inventory >在哪裡的呢?
答案很多人可能已經猜到了就是opatch lsinventory裡列出來的
from           : /etc/oraInst.loc 
這個/etc/oraInst.loc是有專業名稱的,它的名字就叫Central Inventory Pointer File。
這個指向檔案在不同的作業系統上有不同的預設位置,例如:
Linux And AIX — /etc/oraInst.loc 
Other Unix Platforms — /var/opt/oracle/oraInst.loc 
Windows — The pointer is located in the registry key:
\\HKEY_LOCAL_MACHINE\\Software\Oracle\inst.loc
Opatch就是通過Central Inventory Pointer File找到< Central Inventory >的路徑,然後讀取ORACLE_HOME的詳細資訊的。
現在又有新的問題了?
1.我們是否可以刪除Central Inventory Pointer File?或者如果Central Inventory Pointer File丟失了會怎麼樣?
2. Central Inventory丟失或者損壞了會怎麼樣?
3. 我們能否手工修改Central Inventory的內容?
我先回答這幾個問題,然後通過幾個實驗來看一下具體的情況。
答案:
1.不能刪除Central Inventory Pointer File,如果Central Inventory Pointer File丟失了可以手工重建該檔案。如果Central Inventory Pointer File丟失或者損壞那麼opatch的所有命令都將失敗。
2.也不能刪除Central Inventory的檔案,如果Central Inventory的檔案是損壞的,比如內容不完整,或者內容是錯誤的,都將導致opatch失敗。Central Inventory在ORACLE_HOME完好的情況下可以通過重建的方式解決以上問題。
3.Oracle官方不support手工修改Central Inventory的內容。

請注意以下所有的實驗都不要在生產環境操作,以免導致Inventory錯誤.
實驗1: 模擬Central Inventory Pointer File丟失的場景
[root@dbnode1]# mv /etc/oraInst.loc /etc/oraInst.loc.bak  <<<<<<=====這裡手工mv了oraInst.loc檔案,實驗結束後需要手工再mv 回來
[root@dbnode1]# exit
exit
[oracle@dbnode1]$ cd /u01/app/oracle/product/11.2.0/db_1/OPatch/
[oracle@dbnode1 OPatch]$ ./opatch lsinventory
Invoking OPatch 11.2.0.1.7
Oracle Interim Patch Installer version 11.2.0.1.7
Copyright (c) 2011, Oracle Corporation.  All rights reserved.
Oracle Home       : /u01/app/oracle/product/11.2.0/db_1
Central Inventory : n/a
   from           : 
OPatch version    : 11.2.0.1.7
OUI version       : 11.2.0.3.0
Log file location : n/a<<<<<<=========
OPatch cannot find a valid oraInst.loc file to locate Central Inventory. <<<<<<=========
OPatch failed with error code 104<<<<<<=========
[oracle@dbnode1 OPatch]$
通過這個實驗我們看到當Oracle不能找到一個有效的Central Inventory Pointer File時Opatch以失敗告終。
這個時候如果我們確定Central Inventory是完好無損的情況下,可以在不同平臺對應的預設路徑下手工建立或者編輯oraInst.loc 檔案
例如在linux平臺,正常的內容如下
$ cat /etc/oraInst.loc 
inventory_loc=/u01/app/oraInventory
inst_group=oinstall
實驗2: 模擬Central Inventory丟失的場景
[oracle@dbnode1 app]$ mv oraInventory oraInventory.bak<<<<<<=====這裡手工刪除了oraInventory
[oracle@dbnode1 app]$ ls
oracle  oraInventory.bak
[oracle@dbnode1 app]$ cd /u01/app/oracle/product/11.2.0/db_1/OPatch/
[oracle@dbnode1 OPatch]$ ./opatch lsinventory
Invoking OPatch 11.2.0.1.7
Oracle Interim Patch Installer version 11.2.0.1.7
Copyright (c) 2011, Oracle Corporation.  All rights reserved.
Oracle Home       : /u01/app/oracle/product/11.2.0/db_1
Central Inventory : /u01/app/oraInventory
   from           : /etc/oraInst.loc
OPatch version    : 11.2.0.1.7
OUI version       : 11.2.0.3.0
Log file location : /u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2014-03-24_12-15-04PM.log
OPatch failed to locate Central Inventory.  <<<<<<=====報錯無法載入Central Inventory.
Possible causes are: 
    The Central Inventory is corrupted
    The oraInst.loc file specified is not valid.
LsInventorySession failed: OPatch failed to locate Central Inventory.
Possible causes are: 
    The Central Inventory is corrupted
    The oraInst.loc file specified is not valid.
OPatch failed with error code 73<<<<<<=====
這個實驗可以說明當Central Inventory 丟失時Opatch也是失敗的。
實驗3 模擬Central Inventory內容損壞
為實驗目的我們手工修改ORACLE_HOME LOC成/u01/app/oracle/product/11.2.0/db_100 實際上這個目錄是不存在的。但請注意手工修改inventory.xml的任何內容都是不support的。

[oracle@dbnode1 OPatch]$ cd /u01/app/oraInventory/ContentsXML/
[oracle@dbnode1 ContentsXML]$ cp inventory.xml inventory.xml.bak
[oracle@dbnode1 ContentsXML]$ ls
comps.xml  inventory.xml  inventory.xml.bak  libs.xml
[oracle@dbnode1 ContentsXML]$ vi inventory.xml
[oracle@dbnode1 ContentsXML]$ cat inventory.xml

<!-- Copyright (c) 1999, 2011, Oracle. All rights reserved. --&gt
<!-- Do not modify the contents of this file by hand. --&gt


   11.2.0.3.0
   2.1.0.6.0







[oracle@dbnode1 ContentsXML]$ /u01/app/oracle/product/11.2.0/db_1/OPatch/opatch lsinventory
Invoking OPatch 11.2.0.1.7
Oracle Interim Patch Installer version 11.2.0.1.7
Copyright (c) 2011, Oracle Corporation.  All rights reserved.

Oracle Home       : /u01/app/oracle/product/11.2.0/db_1
Central Inventory : /u01/app/oraInventory
   from           : /etc/oraInst.loc
OPatch version    : 11.2.0.1.7
OUI version       : 11.2.0.3.0
Log file location : /u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2014-03-24_12-25-43PM.log
List of Homes on this system:
  Home name= OraDb11g_home1, Location= "/u01/app/oracle/product/11.2.0/db_100"
Inventory load failed... OPatch cannot load inventory for the given Oracle Home.<<<=========
Possible causes are:
   Oracle Home dir. path does not exist in Central Inventory
   Oracle Home is a symbolic link
   Oracle Home inventory is corrupted
LsInventorySession failed: OracleHomeInventory gets null oracleHomeInfo
OPatch failed with error code 73
Central Inventory 如果損壞或者丟失是可以重建的。
重建過程非常簡單,也不需要停機。我們來看下面的實驗
實驗4 重建Central Inventory
[oracle@dbnode1 ~]$ cd /u01/app
[oracle@dbnode1 app]$ ls
oracle  oraInventory
[oracle@dbnode1 app]$ mv oraInventory oraInventory.bak
[oracle@dbnode1 app]$ opatch lsinventory
Oracle Interim Patch Installer version 11.2.0.3.6
Copyright (c) 2013, Oracle Corporation.  All rights reserved.
Oracle Home       : /u01/app/oracle/product/11.2.0/db_1
Central Inventory : /u01/app/oraInventory
   from           : /u01/app/oracle/product/11.2.0/db_1/oraInst.loc
OPatch version    : 11.2.0.3.6
OUI version       : 11.2.0.3.0
Log file location : /u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2014-03-25_17-13-48PM_1.log
OPatch failed to locate Central Inventory.
Possible causes are: 
    The Central Inventory is corrupted
    The oraInst.loc file specified is not valid.
LsInventorySession failed: OPatch failed to locate Central Inventory.<<<==== Central Inventory 被刪除了,這個報錯就是期待的報錯。
Possible causes are: 
    The Central Inventory is corrupted
    The oraInst.loc file specified is not valid.
OPatch failed with error code 73<<<<<<<<<<<<<=================
[oracle@dbnode1 app]$ cd $ORACLE_HOME/oui/bin
[oracle@dbnode1 bin]$ pwd
/u01/app/oracle/product/11.2.0/db_1/oui/bin
[oracle@dbnode1 bin]$ ./runInstaller -silent -ignoreSysPrereqs -attachHome ORACLE_HOME="/u01/app/oracle/product/11.2.0/db_1" ORACLE_HOME_NAME="OraDb11g_home1"
Starting Oracle Universal Installer...
Checking swap space: must be greater than 500 MB.   Actual 2996 MB    Passed
The inventory pointer is located at /etc/oraInst.loc
The inventory is located at /u01/app/oraInventory
'AttachHome' was successful.
[oracle@dbnode1 bin]$ opatch lsinventory
Oracle Interim Patch Installer version 11.2.0.3.6
Copyright (c) 2013, Oracle Corporation.  All rights reserved.
Oracle Home       : /u01/app/oracle/product/11.2.0/db_1
Central Inventory : /u01/app/oraInventory
   from           : /u01/app/oracle/product/11.2.0/db_1/oraInst.loc
OPatch version    : 11.2.0.3.6
OUI version       : 11.2.0.3.0
Log file location : /u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2014-03-25_17-16-37PM_1.log
Lsinventory Output file location : /u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/lsinv/lsinventory2014-03-25_17-16-37PM.txt
--------------------------------------------------------------------------------
Installed Top-level Products (1): 
Oracle Database 11g                                                  11.2.0.3.0
There are 1 product(s) installed in this Oracle Home.
Interim patches (1) :
Patch  17540582     : applied on Mon Mar 24 17:08:31 CST 2014
Unique Patch ID:  16985511
Patch description:  "Database Patch Set Update : 11.2.0.3.9 (17540582)"
   Created on 7 Jan 2014, 03:01:22 hrs PST8PDT
Sub-patch  16902043; "Database Patch Set Update : 11.2.0.3.8 (16902043)"
Sub-patch  16619892; "Database Patch Set Update : 11.2.0.3.7 (16619892)"
Sub-patch  16056266; "Database Patch Set Update : 11.2.0.3.6 (16056266)"
Sub-patch  14727310; "Database Patch Set Update : 11.2.0.3.5 (14727310)"
Sub-patch  14275605; "Database Patch Set Update : 11.2.0.3.4 (14275605)"
Sub-patch  13923374; "Database Patch Set Update : 11.2.0.3.3 (13923374)"
Sub-patch  13696216; "Database Patch Set Update : 11.2.0.3.2 (13696216)"
Sub-patch  13343438; "Database Patch Set Update : 11.2.0.3.1 (13343438)"
   Bugs fixed:
     13593999, 10350832, 14138130, 12919564, 13561951, 14198511, 13588248
     13080778, 13804294, 16710324, 12873183, 14472647, 12880299, 13369579
   ...............
     13059165, 14062797, 12959852, 12345082, 16703112, 13890080, 17333198
     16450169, 12658411, 13780035, 14062793, 13038684, 16742095, 13742464
     14052474, 13060271, 13911821, 13457582, 7509451, 13791364, 12821418
     13502183, 13705338, 16794239, 15862024, 13554409, 13645917, 13103913, 12772404
--------------------------------------------------------------------------------
OPatch succeeded.
[oracle@dbnode1 bin]$ cd /u01/app
[oracle@dbnode1 app]$ ls -l
total 12
drwxrwxr-x 9 oracle oinstall 4096 Nov 24 23:25 oracle
drwxrwx--- 4 oracle oinstall 4096 Mar 25 17:16 oraInventory<<<<<<<==新建立的Central Inventory
drwxrwx--- 5 oracle oinstall 4096 Mar 24 17:12 oraInventory.bak
Central Inventory裡只記錄了Oracle的HOME資訊,但是在這個HOME下打了哪些patch Oracle是怎麼知道的呢?
答案就是Local Inventory (Oracle Home inventory)。
Local Inventory (Oracle Home inventory) 存在於每一個ORACLE_HOME中,它記錄了這個HOME中的相關資訊,比如這個HOME中包含的元件,打過的補丁集(patchset 資訊),打過的小補丁和PSU等資訊。這些資訊被記錄在Local Inventory 中的comps.xml檔案。
ORACLE_HOME/inventory/ContentsXML/comps.xml
同樣Local Inventory (Oracle Home inventory)裡的任何檔案都是不允許手工修改的。
一個重要的資訊是Oracle的Local Inventory (Oracle Home inventory)如果丟失或者損壞時無法重建的,只能通過重新安裝ORACLE軟體的方式解決。

參考文章:
FAQs on Central Inventory and Oracle Home Inventory (Local Inventory) in Oracle RDBMS (Doc ID 564192.1)
Steps To Recreate Central Inventory(oraInventory) In RDBMS Homes (Doc ID 556834.1)
Steps to Recreate Central Inventory in Real Applications Clusters (Doc ID 413939.1)

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

相關文章