Thursday, May 23, 2013

Oracle: Understand OPatch


In this Document


Purpose

Questions and Answers
 Introduction to Opatch
  Getting and using Opatch utility
  Main functionality of Opatch    
  Set PATH environment variable
  Opatch prerequisite checks
 Architecture of Inventories
 Environment variables used by OPatch
 Most common commands available with OPatch
 Opatch –help
 Interim Patch Structure
  Patch metadata
  Custom Scripts (pre and post )
 Listing Installed Interim patches
 Different option used while applying patch
 Different Phase of applying the patch
  Different options used while rolling back the patch
 Different phase of rolling back the patch
  Backup Area used while Rollback
  Why .patch_storage is required
 Location of Log files
 Importance of opatch_histroy.txt file
  Logging & Tracing

References

Applies to:

Oracle Universal Installer - Version 1.0.0.0.62 to 11.2.0.3
Information in this document applies to any platform.

Purpose

 Frequently Asked Questions to understand OPatch tool and Patching

Questions and Answers

Introduction to Opatch

Opatch is Oracle supplied utility .
OPatch is used for patching Oracle software.
OPatch is a java based utility that allow the application and rolling back of interim patches to an Oracle product
The program has sub-commands that may take arguments.

 Getting and using Opatch utility

OPatch is PLATFORM specific.
Release is based on Oracle Universal Installer version
The latest opatch utility can be downloaded via patch number 6880880 from My Oracle Support .
Downloaded Patch to be unzipped in OH , which will create a directory $ORACLE_HOME/Opatch
Execute the following command  to verify the version
        $ORACLE_HOME/Opatch/opatch version

 Main functionality of Opatch    

Applying the patch
Rollback the patch
Conflict check
Report the installed components and patches

 Set PATH environment variable

Windows: set PATH=%ORACLE_HOME%/OPatch:%PATH%
Unix: export PATH=$ORACLE_HOME/OPatch:$PATH

 Opatch prerequisite checks

Check ORACLE_HOME  environment variable
Check for JRE / JDK
Check for Oracle Universal Installer and OPatch Version Compatibility
Checks for PERL( specific to 9i/10gR1 )
Check for Patch Applicable on Operating System
Check for System Space
Check for System Commands, which are used for system updates    e.g. fuser , ar , ld …etc..

Architecture of Inventories

Inventory Pointer file
Default Location : /etc/oraInst.loc or /var/opt/oracle/oraInst.loc ( for most UNIX systems )
Gives the location of central inventory

Central Inventory
Location given by Inventory pointer file.
As per OFA architecture, $ORACLE_BASE/oraInventory
Critical File : - <central-inventory>/ContentsXML/inventory.xml
Provides information about Oracle installations present on system
On Windows : C:\Program Files\Oracle\Inventory

Local Inventory( Oracle Home inventory )
Location : $ORACLE_HOME/inventory
Critical File : - $ORACLE_HOME/inventory/ContentsXML/comps.xml
Contains list of installed components/interim patches in this particular Oracle Home

Environment variables used by OPatch

ORACLE_HOME : This variable must point to a valid Oracle Home and matches the value when that Oracle Home was installed.
OPATCH_DEBUG: Setting this variable to "true" sets the log level to debug.
OPATCH_PLATFORM_ID : If this variable to set to some numeric value, then OPatch skips platform ID check and assumes the platform ID to be the one specified here.
OPATCH_NO_FUSER: Setting this variable to "true" informs the OPatch to skip the check for active executables.
PATH: This variable must have a valid Opatch utility location included in it.

Most common commands available with OPatch

$ 'opatch apply ...' is to apply a patch
$ 'opatch rollback ...' is to roll back a patch
$ 'opatch lsinventory' is to show inventory on an Oracle Home
$ 'opatch query ...' is to query a given patch from specific details
$ 'opatch version' is to show the version of the OPatch being used
$ 'opatch prereq ...' is to invoke some prerequiste checks
$ 'opatch util ...' is to invoke some independent utilities

Opatch –help

Opatch -help command  : Invoking OPatch without arguments or with the 'help' sub-command returns the list of valid sub-commands to the user:
Usage: opatch [ -help ] [ -r[eport] ] [ command ]
opatch –help apply
opatch –help lsinventory
opatch –help nappl
opatch –help nrollback
opatch –help rollback
opatch –help query
opatch –help version
opatch –help prereq
opatch –help util

Interim Patch Structure

Patch_Srructure

 Patch metadata

The patch metadata exist in the inventory.xml and action.xml files exists under <stage_area>/<patch_id>/etc/config/

inventory .xml file have the following information :

Bug number
Unique Patch ID
Date of  patch year
Required and Optional components
OS platforms ID
Instance shutdown is required or not
Patch can be applied online or not


actions.xml file have the following information :

File name and it location to which it need to be copied
Components need to be re-linked
Information about the optional and required components

 Custom Scripts (pre and post )

Pre-processing and post-processing scripts that need to be run before and after patching .
It  is under <stage_area><patch_id>/custom/scripts.
It is mainly to do some specific task before and after applying the patch.
 Example of Pre :
 Change the permission of the library file before applying the patch .
 Check existence of some files and remove it before copying the files.
 Remove some file or folder before applying the patch .

Example of Post :
Reverting back the permission changes made by pre
Correct the permission and ownership of the file shipped with the patch

Listing Installed Interim patches

lsinventory option reports what has been installed on the system for a particular Oracle home directory, or for all installations.
    
           Syntax : opatch lsinventory

   Commonly used lsinventory arguments

opatch lsinventory –invPtrLoc (Required when oraInst.loc is not at default  location )
opatch lsinventory -oh
opatch lsinventory -jre
opatch lsinventory -all
opatch lsinventory -detail

Different option used while applying patch

General Syntax
      % cd <patch_source>
      % opatch apply

   Commonly used  'opatch apply' command line arguments
opatch apply force
opatch apply no_inventory
 opatch apply no_sysmode
opatch apply report

Npply specific options
opatch napply
opatch napply -id 1,2,3
opatch napply -skip_subset -skip_duplicate
opatch napply -phBaseFile

Different Phase of applying the patch

Oracle Home discovery  : Configure and Validate Oracle Home info.
Prerequisite for apply  : Invoke prerequisites to see if patch can be applied.                           
Patch conflict detection for apply patch  : Check if any conflict with already installed patches in Oracle Home.
Prerequisite for auto rollback] : Check if the conflict patches are rollbackable.                           
Back up for restore : Back up  files for Oracle Home restore in case of patching error.                           
Patch conflict resolution for apply patch  : Rollback patch(es).                           
Back up for rollback : Back up  files for future patch rollback.                           
Patch Oracle Home for apply : Archive  library file(s) with  Object file(s);                                                                           
Do relink(s).                           
Update inventory for apply]  : Modify the inventory to record  patch.

 Different options used while rolling back the patch

Rollback option removes a specific interim patch from appropriate Home Directory
      Syntax : opatch rollback -id <patch-id>

      Common rollback arguments
opatch rollback -id <patch-id> -local
 opatch rollback -id <patch-id> no_sysmod
 opatch rollback -id <patch-id> no_relink
 opatch rollback -id <patch-id> report

Different phase of rolling back the patch

Oracle Home discovery : Configure and Validate Oracle Home info.
Prerequisite for rollback : Invoke prerequisites to see if patch can be rolled back.
Back up for restore : Back up files for Oracle Home restore in case of patching error.
Patch Oracle Home for rollback : Archive library file(s) with Object file(s)
Do relink(s).
Update inventory for rollback : Modify the inventory to record patch Patch_ID.
Deleting file and directories under .patch_storage

 Backup Area used while Rollback

$ORACLE_HOME/.patch_storage

<patchid_timestamp> folder gets created under this for any interim patch patching attempt

  Contains the following :

Backup of system ( inventory and system files) which can be used to restore back to  good known prepatched state
Restore and manual rollback scripts
Copy of original patch, list of “make” commands…..
       Architecture different for 10gR2/11g and 9i/10gR1

  patch_storage also contains file – patch_locked / patch_free

 Why .patch_storage is required

The .patch_storage directory is required to rollback the patch.
       Interim patch : To rollback interim patch using rollback –id  command
       subset patch : To rollback subset patch. CPU/PSU are cumulative patches
       conflicting patch : To rollback the conflicting patch

.patch_storage is also required to remove any changes made to the Oracle binaires by the failed patch application attempt.

Location of Log files

10.2.0.x /11.1.0.x6/11.2.0.x
Directory Location :$ORACLE_HOME/cfgtoollogs/opatch
The filenames present in this directory have a format like :
     opatch-<Time-stamp>.log


9.2.0.x/10.1.0.x
 Directory Location : $ORACLE_HOME/.patch_storage/<PATCHID>
 Fileformat: Apply_<PATCHID>_<Timestamp>.log

Importance of opatch_histroy.txt file

Maintains an index of the commands executed with OPatch.
It is helpful in finding the correct /required log file .

Sample Entry from opatch_history.txt

Date & Time : Wed Mar 28 12:44:19 GMT 2012
Oracle Home : /u01/app/oracle/product/11.2.0.1
OPatch Ver. : 11.2.0.3.0
Current Dir : /software/patches/9547706
Command   : apply –invPtrLoc /u01/app/oracle/product/11.2.0.1/oraInst.loc
Log File  : /u01/app/oracle/product/11.2.0.1/cfgtoollogs/opatch/9547706_Mar_28_2012_12_44_20/apply2012-03-28_12-44-19PM_1.log

 Logging & Tracing

Set env variable 'OPATCH_DEBUG=TRUE' before applying the patch
This is the maximum logging level supported by OPatch
Analyse the log files generated in respective locations to analyse the specific operation performed

No comments:

Post a Comment