Oracle的Central Inventory和Local inventory

每次我们安装Oracle的时候,oracle安装目录都会记录了软件安装的相关信息,oracle就是通过这些信息来确定这台主机上安装了哪些东西。

这些目录就被分为以下两种

  • Central Inventory (oraInventory)
  • Local Inventory (Oracle Home inventory)

Central Inventory

那什么是Central Inventory?

  • Central Inventory 包含了所有这台主机上安装的oracle产品信息
  • Central Inventory 包含一个文件inventory.xml, 这个xml文件记录了所有这个节点上安装的oracle home.
  • 对于每个Oracle Home,它同时列出了Oracle Home name, home index, 和oracle home所属的节点信息.
  • 它同时也提到了这个home是一个Clusterware home还是已删除的Oracle Home.

我们查看补丁信息的时候会有一个central inventory信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[oracle@xb ~]$ opatch lsinventory
Oracle Interim Patch Installer version 11.2.0.3.16
Copyright (c) 2018, Oracle Corporation. All rights reserved.


Oracle Home : /u01/app/oracle/product/11.2.0/dbhome_1
Central Inventory : /u01/app/oraInventory
from : /u01/app/oracle/product/11.2.0/dbhome_1/oraInst.loc
OPatch version : 11.2.0.3.16
OUI version : 11.2.0.4.0
Log file location : /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/opatch2018-10-20_00-46-40AM_1.log

Lsinventory Output file location : /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/lsinv/lsinventory2018-10-20_00-46-40AM.txt

--------------------------------------------------------------------------------
Local Machine Information::
Hostname: xb
ARU platform id: 226
ARU platform description:: Linux x86-64

Installed Top-level Products (1):

Oracle Database 11g 11.2.0.4.0
There are 1 products installed in this Oracle Home.

通过上面的结果可以看到本机的Central Inventory为/u01/app/oraInventory,我们先看看xml文件写了一些什么

默认路径为/ContentsXML/inventory.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
>?xml version="1.0" standalone="yes" ?>
>!-- Copyright (c) 1999, 2013, Oracle and/or its affiliates.
All rights reserved. -->
>!-- Do not modify the contents of this file by hand. -->
>INVENTORY>
>VERSION_INFO>
>SAVED_WITH>11.2.0.4.0>/SAVED_WITH>
>MINIMUM_VER>2.1.0.6.0>/MINIMUM_VER>
>/VERSION_INFO>
>HOME_LIST>
>HOME NAME="OraDb11g_home1" LOC="/u01/app/oracle/product/11.2.0/dbhome_1" TYPE="O" IDX="1"/>
>/HOME_LIST>
>COMPOSITEHOME_LIST>
>/COMPOSITEHOME_LIST>
>/INVENTORY>

这里我只安装了一个数据库,名字叫OraDb11g_home1,oracle home目录为/u01/app/oracle/product/11.2.0/dbhome_1。

请注意这里TYPE=”O” IDX=”1”. TYPE=”O”意思是这是一个ORACLE数据库的HOME,如果它后面还有CRS=”true”这样的标记就表明这是一个CRS_HOME。IDX=”1”意思就是该HOME是第一个安装的产品。

找一个rac版本的看一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
>?xml version="1.0" standalone="yes" ?>
>!-- Copyright (c) 1999, 2018, Oracle and/or its affiliates.
All rights reserved. -->
>!-- Do not modify the contents of this file by hand. -->
>INVENTORY>
>VERSION_INFO>
>SAVED_WITH>12.2.0.1.4>/SAVED_WITH>
>MINIMUM_VER>2.1.0.6.0>/MINIMUM_VER>
>/VERSION_INFO>
>HOME_LIST>
>HOME NAME="OraGI12Home1" LOC="/u01/app/12.2.0/grid" TYPE="O" IDX="1" CRS="true"/>
>HOME NAME="OraDB12Home1" LOC="/u01/app/oracle/product/12.2.0/dbhome_1" TYPE="O" IDX="2"/>
>/HOME_LIST>
>COMPOSITEHOME_LIST>
>/COMPOSITEHOME_LIST>
>/INVENTORY>

这里很明显看到这台主机安装了两个oracle软件,一个是OraGI12Home1,后面的CRS=”true”;表示这是一个crs home,IDX表明了先安装的crs home

那oracle是如何知道Central Inventory目录是在哪的呢,注意from : /u01/app/oracle/product/11.2.0/dbhome_1/oraInst.loc

就很容易猜到是通过oraInst.loc文件找到的。

先看看这个文件又写的什么

1
2
inventory_loc=/u01/app/oraInventory
inst_group=oinstall

这个oraInst.loc文件的官方术语为Central Inventory Pointer File,顾名思义,它就是指向Central Inventory的指针文件,它的默认路径为

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官方不支持手工修改Central Inventory的内容。

模拟Central Inventory Pointer File丢失

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[oracle@xb dbhome_1]$ mv oraInst.loc oraInst.loc.bak
[oracle@xb dbhome_1]$ opatch lsinventory
Oracle Interim Patch Installer version 11.2.0.3.16
Copyright (c) 2018, Oracle Corporation. All rights reserved.


Oracle Home : /u01/app/oracle/product/11.2.0/dbhome_1
Central Inventory : /u01/app/oraInventory
from : /etc/oraInst.loc 《《 本机有多个oraInst.loc
OPatch version : 11.2.0.3.16
OUI version : 11.2.0.4.0
Log file location : /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/opatch2018-10-20_01-37-15AM_1.log


[root@xb ContentsXML]# mv /etc/oraInst.loc /etc/oraInst.loc.bak
[root@xb ContentsXML]# su - oracle
[oracle@xb ~]$ opatch lsinventory
Oracle Interim Patch Installer version 11.2.0.3.16
Copyright (c) 2018, Oracle Corporation. All rights reserved.


Oracle Home : /u01/app/oracle/product/11.2.0/dbhome_1
Central Inventory : n/a
from :
OPatch version : 11.2.0.3.16
OUI version : 11.2.0.4.0
Log file location : n/a

OPatch cannot find a valid oraInst.loc file to locate Central Inventory.

OPatch failed with error code 104

会发现现在就识别不到Central Inventory了,如果我们确定Central Inventory是完好无损的情况下,恢复的方法很简单,只要手动创建这个文件就可以了

edit /etc/oraInst.loc 加上下面内容就可以了

inventory_loc=/u01/app/oraInventory

inst_group=oinstall

模拟Central Inventory丢失

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[oracle@xb app]$ mv oraInventory/ oraInventory.bak
[oracle@xb app]$ opatch lsinventory
Oracle Interim Patch Installer version 11.2.0.3.16
Copyright (c) 2018, Oracle Corporation. All rights reserved.


Oracle Home : /u01/app/oracle/product/11.2.0/dbhome_1
Central Inventory : /u01/app/oraInventory
from : /etc/oraInst.loc
OPatch version : 11.2.0.3.16
OUI version : 11.2.0.4.0
Log file location : /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/opatch2018-10-20_11-01-50AM_1.log

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

说明目录不存在时opatch也是会失败的

模拟Central Inventory内容损坏

修改db_home目录为一个不存在的目录,这里要注意到一个问题,oracle是不支持手动编辑inventory.xml,否则会影响到install和patch操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[oracle@xb ContentsXML]$ vim inventory.xml 
[oracle@xb ContentsXML]$ opatch lsinventory
Oracle Interim Patch Installer version 11.2.0.3.16
Copyright (c) 2018, Oracle Corporation. All rights reserved.


Oracle Home : /u01/app/oracle/product/11.2.0/dbhome_1
Central Inventory : /u01/app/oraInventory
from : /etc/oraInst.loc
OPatch version : 11.2.0.3.16
OUI version : 11.2.0.4.0
Log file location : /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/opatch2018-10-20_11-08-43AM_1.log

List of Homes on this system:

Home name= OraDb11g_home1, Location= "/u01/app/oracle/product/11.2.0/dbtest" >>>>==== 这里dbtest目录不存在
LsInventorySession failed: RawInventory gets null OracleHomeInfo

OPatch failed with error code 73

可以看到 如果内容异常,opatch同样也会报错。 如何修复这样的central inventory呢?

重建Central Inventory

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[oracle@xb app]$ mv oraInventory/ oraInventory.bak
[oracle@xb app]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/oui/bin
[oracle@xb bin]$ ./runInstaller -silent -ignoreSysPrereqs -attachHome ORACLE_HOME="/u01/app/oracle/product/11.2.0/dbhome_1" ORACLE_HOME_NAME="OraDb11g_home1"
Starting Oracle Universal Installer...

Checking swap space: must be greater than 500 MB. Actual 4031 MB Passed
The inventory pointer is located at /etc/oraInst.loc
The inventory is located at /u01/app/oraInventory
'AttachHome' was successful.


[oracle@xb bin]$ opatch lsinventory
Oracle Interim Patch Installer version 11.2.0.3.16
Copyright (c) 2018, Oracle Corporation. All rights reserved.


Oracle Home : /u01/app/oracle/product/11.2.0/dbhome_1
Central Inventory : /u01/app/oraInventory
from : /u01/app/oracle/product/11.2.0/dbhome_1/oraInst.loc
OPatch version : 11.2.0.3.16
OUI version : 11.2.0.4.0
Log file location : /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/opatch2018-10-20_11-18-04AM_1.log

Lsinventory Output file location : /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/lsinv/lsinventory2018-10-20_11-18-04AM.txt

--------------------------------------------------------------------------------
Local Machine Information::
Hostname: xb
ARU platform id: 226
ARU platform description:: Linux x86-64

Installed Top-level Products (1):

Oracle Database 11g 11.2.0.4.0
There are 1 products installed in this Oracle Home.

恢复正常。

1
2
3
4
5
[oracle@xb app]$ ll
total 12
drwxr-xr-x. 10 oracle oinstall 4096 Aug 24 18:13 oracle
drwxrwx---. 4 oracle oinstall 4096 Oct 20 11:17 oraInventory >>>>==== 重新建的新目录
drwxrwx---. 5 oracle oinstall 4096 Aug 24 10:46 oraInventory.bak

现在有一个想法,上面看到了inventory.xml文件里列出了home list,那如果我不想本机安装的所有oracle product home都列在一个文件里可以做到吗?

答案是可以的,通过建立多个oraInst.loc文件来指向多个Central Inventory目录,不过只适用UNIX / Linux,windows则不支持。

那既然这样,就会涉及到这样一个情形:如果我想启动opatch,但是主机上有多个oraInst.loc,而我又不想用默认的那个

1
2
3
4
The syntax is as follows: 

./runInstaller -invPtrLoc >Location_of_oraInst.loc>
./opatch -invPtrLoc >Location_of_oraInst.loc>

LOCAL INVENTORY

什么是LOCAL INVENTORY?

  • LOCAL INVENTORY只呈现在每个oracle home本身
  • 只存放每个特定的oracle home自己的信息,一般为$ORACLE_HOME/inventory

Components File

  • 主要包含了需要哪些第三方应用的detail信息,例如jre等
  • 另外包含了一些oracle home安装的补丁信息等

同样Local Inventory (Oracle Home inventory)里的任何文件都是不允许手工修改的。

一个重要的信息是Oracle的Local Inventory (Oracle Home inventory)如果丢失或者损坏时无法重建的,只能通过重新安装ORACLE软件的方式解决。

所以建议当你安装完oracle或patch完毕后,要记得备份local inventory!


Oracle的Central Inventory和Local inventory
https://www.xbdba.com/2018/10/20/oracle-central-inventory-local-inventory/
作者
xbdba
发布于
2018年10月20日
许可协议