Saturday, November 13, 2010

Unable to lock Central Inventory. OPatch will attempt to re-lock

Sometimes while applying a patch on the database (opatch) i come across the following error->
Unable to lock Central Inventory. OPatch will attempt to re-lock.
Do you want to proceed? [y|n]
n
User Responded with: N
Unable to lock Central Inventory. Stop trying per user-request?
OPatchSession cannot load inventory for the given Oracle Home /u01/XXXXDB/product/10.2.0. Possible causes are:
No read or write permission to ORACLE_HOME/.patch_storage
Central Inventory is locked by another OUI instance
No read permission to Central Inventory
The lock file exists in ORACLE_HOME/.patch_storage
The Oracle Home does not exist in Central Inventory

ApplySession failed: ApplySession failed to prepare the system. Unable to lock Central Inventory. Stop trying per user-request?
System intact, OPatch will not attempt to restore the system
OPatch failed with error code 73

Here's the Solution
/var/opt/oracle/oraInventory/ContentsXML/comps.xml was owner by applmgr and oracle was not having write permissions on it. Changed the owner to "oracle" & changed the permissions to "777" which resolved the issue.
Sometimes the above permissions are already there and patch failed because of other issues. You might want to do the following in these cases
Remove the directory /var/opt/oracle/oraInventory/locks if it exists
Remove the file under $ORACLE_HOME/.patch_storage if it exists
Change the permissions of /var/opt/oracle/oraInventory to "777" and owner to oracle.
Please note that "/var/opt/oracle/oraInventory" is the central inventory as mentioned in /var/opt/oracle/oraInst.loc