Thursday 3 June 2010

OPATCH Utility (RDBMS Patching)


OPatch is a java based utility that allows the application and rolling back of interim patches to an Oracle product. The program requires Java(JVM) to be present on the current system. OPatch expects users to have commands such as fuser, jar, ar and make on Unix platforms and jar on Windows platforms to be available in their PATH.
Opatch Details
How to check the Opatch version?
Normally Opatch directory will not available with PATH variable, add
[oracle@visR12 ~]$ export PATH=$PATH:/app/oracle/ajidb/11.2.0/OPatch/
[oracle@visR12 ~]$ opatch version
Invoking OPatch 11.1.0.6.6
OPatch Version: 11.1.0.6.6
OPatch succeeded.
How to know which version is the correct version of Opatch for your RDBMS home?
You can verify whether the Opatch version for your RDBMS release is correct or not using metalink note:357221.1.
This note ID gives the compatibilities between OPatch version and RDBMS version.
How to get the latest version of OPatch?
You can download the latest version of OPatch from metalink using following URL.
From the above link, you will get the latest Opatch Universal Installer, download it.
To install this patch simply extract the file "zipped file" using unzip or winzip, depending upon the platform. You should extract the zip file directly under the ORACLE_HOME.
How to run the utility:
OPatch tool requires JDK to be present in the Oracle Home.
It requires JDK version of 1.5.0 or higher for proper functioning.
It can be invoked directly using
/opatch [] [options]
Patch commands are
Apply
napply
rollback
nrollback
lsinventory
lsinv
query
util
prereq
version
-help
-h
You can use the following command format to view help information:
/opatch [] –help
OPatch can be manually invoked using Perl:
/perl /opatch.pl [options]
You can use the following command format to view help information:
/perl /opatch.pl  [] -help
In the release dropdown you can select the OPatch release that you want to download based on your RDBMS version. Please read the README.txt before applying the patch.
What is Oracle Database Inventory and where it is located?
Oracle Inventory is the location or the place where all the information about an Oracle Home is stored and maintained. Whenever we install an RDBMS Oracle Home, a new inventory gets created. Applying any new patch to Oracle Home will update the inventory for that Oracle Home and record the details for the patch applied. This inventory is in the form of XML files.
The location of inventory is defined in a file called oraInst.loc. The path for this file is provided while installing Oracle Home. If we don’t supply any path, this file will be present at central location /etc/oraInst.loc. Also we can have a central inventory if it’s not used by any other oracle installation. If the central inventory is used by previous Oracle installation we can create local inventory. The content of oraInst.loc file is as shown below.
[oracle@visR12 ~]$ cd $ORACLE_BASE/oraInventory/
[oracle@visR12 oraInventory]$ cat oraInst.loc
inventory_loc=/app/oracle/oraInventory
inst_group=oinstall
Here “inventory_loc” gives the location of Inventory directory where as inst_group gives the name of the group which is the owner of this inventory.
How to create Local Inventory?
You can create local inventory at any location while installing Oracle Home. You need to use -invPtrLoc variable along with runInstaller command and give the location of oraInst.loc. Otherwise the default path assumed for oraInst.loc is /etc/oraInst.loc.
./runInstaller -invPtrLoc /app/oracle/oraInventory/oraInst.loc
After the installation starts it will ask for location of oraInventory directory and group which should own it. It will make entry of these into oraInst.loc file.
Various options available with opatch utility
You can get all the options using opatch –help
Usage: opatch [ -help ] [ -r[eport] ] [ command ]
            command := apply
                       lsinventory
                       napply
                       nrollback
                       rollback
                       query
                       version
                       prereq
                       util
:= -help       Displays the help message for the command.
-report     Print the actions without executing.
example:
‘opatch -help’
‘opatch apply -help’
‘opatch lsinventory -help’
‘opatch prereq -help’
‘opatch rollback -help’
‘opatch util -help’
OPatch succeeded.
You can get specific help for any command of opatch using opatch -help. 
Example 
[oracle@visR12 ~]opatch apply -help.
Applying single patch using opatch
1. You MUST read the Readme.txt file included in opatch file, look for any prerequisites steps/ post installation steps or and DB related changes. Also, make sure that you have the correct opatch version required by this patch.
2. All take a working backup of database along with Oracle Home and oraInventory
3. Make a note of all Invalid objects in the database prior to the patch.
4. Shutdown all the oracle processes running from that Oracle Home, including the Listener and Database instance, Management agent etc.
tar czvf /app/backup/oracle.tar.gz $ORACLE_HOME
Unzip the patch in $ORACLE_HOME/patches
5. If you are applying a single intrim patch to oracle home, then change the location to the directory of that patch and then invoke following command.
Example if I need to apply patch 6972343 to RDBMS Oracle Home
[oracle@visR12 ~]$ cd $ORACLE_HOME/patches/6972343
[oracle@visR12 ~]$opatch apply
If you have created local inventory then you need to give the correct path for local inventory stored in oraInst.loc. If you have updated /etc/oraInst.loc with correct location of your inventory, then above command will work, If not you can give the correct location by giving local oraInst.loc file.
[oracle@visR12 ~]$opatch apply -invPtrLoc /app/oracle/oraInst.loc
Remember that when we are applying patch, patch number is NOT provided as an input to opatch command. So we have to to be in the directory of patch since opatch will pick the patch files from current directory.

Rolling back a patch
In case if a patch did not fix the issue or if you has applied wrong patch to oracle home, you can always rollback the patch using following comamnd.
opatch rollback -id

Applying bundle patches
Sometimes if you have to apply bundle patch having many patches, Execute following command to apply all patches.
[oracle@visR12 ~]$opatch util NApply
NApply -> Will apply all patches to RDBMS home.
You can also use -phBaseDir to point to the directory where bundle patch is installed. So you can run opatch command from any location
$ORACLE_HOME/OPatch/opatch util NApply -phBaseDir /app/oracle/patches/6778860 -invPtrLoc /app/oracle/oraInventory/oraInst.loc
You can also apply specific patches using NApply
opatch util napply -id 1,2,3 -skip_subset -skip_duplicate
This will apply patches 1, 2, and 3 which are under < the patch_location> directory. OPatch will skip duplicate patches and subset patches (patches under that are subsets of patches installed in the ORACLE_HOME)
You can see all the options for NApply using following help command.
$ORACLE_HOME/OPatch/opatch util NApply -help
Query the inventory for patches applied

$ORACLE_HOME/OPatch/opatch lsinventory
[oracle@visR12 ~]$ opatch lsinventory
Invoking OPatch 11.1.0.6.6
Oracle Interim Patch Installer version 11.1.0.6.6
Copyright (c) 2009, Oracle Corporation.  All rights reserved.
Oracle Home       : /app/oracle/ajidb/11.2.0
Central Inventory : /app/oracle/oraInventory
from           : /etc/oraInst.loc
OPatch version    : 11.1.0.6.6
OUI version       : 11.2.0.1.0
OUI location      : /app/oracle/ajidb/11.2.0/oui
If you are using central inventory then -invPtrLoc variable is not required.
You can also get the detailed view of inventory using following command. In case of detail information it gives which are the files that this patch have touched.
$ORACLE_HOME/OPatch/opatch lsinventory -detail
Patch  8796511      : applied on Sat May 29 15:59:45 GST 2010
Unique Patch ID:  11817080
Created on 25 Sep 2009, 10:27:46 hrs PST8PDT
Bugs fixed:
8796511
Files Touched:
/kzu.o --> ORACLE_HOME/lib/libserver11.a
/ktt.o --> ORACLE_HOME/lib/libserver11.a
ins_rdbms.mk --> ORACLE_HOME/rdbms/lib/ioracle
Patch Location in Inventory:
/app/oracle/ajidb/11.2.0/inventory/oneoffs/8796511
Patch Location in Storage area:
/app/oracle/ajidb/11.2.0/.patch_storage/8796511_Sep_25_2009_10_27_46


$opatch util [COMMAND]
This operation invokes the chosen utilities on an ORACLE_HOME.
SYNTAX
opatch util [ -help ] [ COMMAND ]
Use opatch util [ COMMAND ] -help to get help on a particular command.
COMMANDS
  • ApplySql - Apply sql, sql procedure related actions for patches, which are already applied using Apply or NApply operation.
  • CleanupBackupArea - Remove the backup for restores area of the given patch or for all the patches.
  • CopyListedDirs - Recursively copy all directories listed in ORACLE_HOME/.patch_storage/< ID>/rac/copy_dirs.txt to remote nodes.
  • CopyListedDirsTest - Recursively copy a single directory to remote nodes.
  • CopyListedFiles - Copy all files listed in ORACLE_HOME/.patch_storage/< ID>/rac/copy_files.txt to remote nodes.
  • CopyListedFilesTest - Copy a single file to remote nodes.
  • DisableOnlinePatch - Disable and remove the specified online patch(es)  on the given database instances.
  • EnableOnlinePatch - 
  • Install and enable the specified online patch(es)  on the given database instances.
  • installOCM -  Install and configure OCM.
  • LoadXML - Prompt for path/name of the XML file, then check if the XML is correct.
  • RemoveListedDirs - Recursively remote directories listed in  ORACLE_HOME/.patch_storage/< ID>/rac/remove_dirs.txt  on remote nodes.
  • RemoveListedDirsTest - Recursively remove a directory on remote nodes.
  • RemoveListedFiles - Remove files listed in  ORACLE_HOME/.patch_storage/< ID>/rac/remove_files.txt  on remote nodes.
  • RemoveListedFilesTest - Remove a single file on remote nodes.
  • RestoreOH - Restore the OracleHome to the previous state.
  • RollbackSql - Rollback sql, sql procedure related actions for patches, which are already rolled back using Rollback or NRollback operation.
  • RunAnyCommand - Run any command on remote nodes.
  • RunLocalMake - Invoke re-link on the local node. Commands are stored in ORACLE_HOME/.patch_storage/< ID>/make.txt.
  • RunRemoteMake - Invoke re-link on remote nodes. Commands are stored in  ORACLE_HOME/.patch_storage/< ID>/rac/make_cmds.txt.
  • UpdateRemoteNodes - Propagate/Remove files/directories to/on remote nodes using files under ORACLE_HOME/.patch_storage/< ID>/rac/*.
        UpdateOPatchVersion
             Update the version of OPatch in the inventory of Oracle Home.
        Verify
             Using the defined ORACLE_HOME and given patch location via
             -ph, the program will check to make sure the patch was
             applied to the ORACLE_HOME.
             Example: 'opatch util verify -ph /tmp/patchLoc'
Hope this post will helps !

Related Posts by Categories



1 comment:

khalil said...

I am new to Oracle Apps, i found this site very very helpful for me to understand different commands and components related to Oracle Apps. I really appreciate Mr. Mjikumar G for sparing time for his posts to help the new learner like me.