Вы находитесь на странице: 1из 14

OPATCH Utility (Oracle RDBMS Patching)

Filed under: Oracle Database 10g,Oracle Database 11g,Oracle Database 9i Tags: database
patching, opatch, RDBMS patching advait @ 6:32 am
Introduction:
This post has been written on request of one of regular visitor of my blog (Altaaf). This post is
all about Oracle Patching Utility (OPATCH) and various options that can be used along with
Opatch.
We will begin the discussion by knowing what exactly is Opatch?
- 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. 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?
-bash-3.00$ ./opatch version
Invoking OPatch 10.2.0.3.0
OPatch Version: 10.2.0.3.0
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 ID 357221.1.
This note ID gives the copatibilities 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.
http://updates.oracle.com/download/6880880.html
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. When ever we install an RDBMS Oracle Home, a new inventory gets
created. Applying any new patch to Oracle Home will update the invnrtory 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 dont supply any path, the is file will be present at central
location /etc/oraInst.loc. Also we can have a central inventory if its 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.
-bash-3.00$ cd $ORACLE_HOME
-bash-3.00$ cat oraInst.loc
inventory_loc=/slot/ems2029/appmgr/apps/tech_st/10.1.2/oraInventory
inst_group=ems2029
-bash-3.00$
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 /slot/ems2029/appmgr/apps/tech_st/10.1.2/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.
Having know the above information about opatch, now we will move to details about using
opatch and various options available.
Opatch help
You can get all the options using opatch -help
-bash-3.00$ ./opatch -help
Invoking OPatch 11.1.0.6.0
Oracle Interim Patch Installer version 11.1.0.6.0
Copyright (c) 2007, Oracle Corporation. All rights reserved.

Usage: opatch [ -help ] [ -r[eport] ] [ command ]


command := apply
lsinventory
prereq
query
rollback
util
version
<global_arguments> := -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 <command> -help. Example
opatch apply -help.
Applying single patch using opatch
1. You MUST read the Readme.txt file included in opatch file, look for any prereq. steps/ post
installation steps or and DB related changes. Also, make sure that you have the correct opatch
version required by this patch.
2.Make sure you have a good backup of database.
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.
5. You MUST Backup your oracle Home and Inventory
tar cvf $ORACLE_HOME $ORACLE_HOME/oraInventory | gzip >
Backup_Software_Version.tar.gz
6. Unzip the patch in $ORACLE_HOME/patches
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

-bash-3.00$ cd 6972343
-bash-3.00$ pwd
/slot/ems2029/oracle/db/tech_st/11.1.0/patches/6972343
-bash-3.00$ ls
etc files README.txt
$ORACLE_HOME/OPatch/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_HOME/OPatch/opatch apply -invPtrLoc
/slot/ems2029/oracle/db/tech_st/11.1.0/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 <Patch Number>
Applying bundle patches
Some times if you have to apply bundle patch having many patches, example lets say you want
to a bundle patch 6778860 ( 11.1.0.6 BUNDLED PATCH FOR EBS 11I)) containing many
other patches to RDBMS home, OPatch provides a facility to apply many patches to RDBMS
home using a single comamnd. Following command should be used for applying bundle patches.
Download the patch and extract the same. You will see many directories (one for each patch)
inside the main patch directory. Execute following command to apply all patches.
$ORACLE_HOME/OPatch/opatch util NApply -invPtrLoc
/slot/ems2029/oracle/db/tech_st/11.1.0/oraInst.loc
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


/slot/ems2029/oracle/db/tech_st/11.1.0/patches/6778860 -invPtrLoc
/slot/ems2029/oracle/db/tech_st/11.1.0/oraInst.loc
You can also apply specific patches using NApply
opatch util napply <patch_location> -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 <patch_location> 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
We can query the inventory to check various components installed for database as well as to
check various patches applied to database. Use following command to get a minimum
information from inventory about patches applied and components installed.
$ORACLE_HOME/OPatch/opatch lsinventory -invPtrLoc
/slot/ems2029/oracle/db/tech_st/11.1.0/oraInst.loc
Patch 5763576
: applied on Wed May 28 03:20:53 PDT 2008
Created on 6 Feb 2008, 02:26:04 hrs PST8PDT
Bugs fixed:
5763576
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 -invPtrLoc
/slot/ems2029/oracle/db/tech_st/11.1.0/oraInst.loc
Patch 6318357
: applied on Wed May 28 03:33:27 PDT 2008
Created on 4 Dec 2007, 22:02:16 hrs PST8PDT
Bugs fixed:
6318357
Files Touched:
udjvmrm.sql > ORACLE_HOME/javavm/install/udjvmrm.sql
Patch Location in Inventory:
/slot/ems2029/oracle/db/tech_st/11.1.0/inventory/oneoffs/6318357

Patch Location in Storage area:


/slot/ems2029/oracle/db/tech_st/11.1.0/.patch_storage/6318357_Dec_4_2007_22_02_16
Which options are installed in Oracle Home?
You can check the options installed in RDBMS home using above command. The options
installed will be listed at the start of output.
Example: $ORACLE_HOME/OPatch/opatch lsinventory -detail -invPtrLoc
/slot/ems2029/oracle/db/tech_st/11.1.0/oraInst.loc
The complete output of this command can be seen at this location.
Opatch Log files
Log file for Opatch utility can be found at $ORACLE_HOME/cfgtoollogs/opatch
Advanced Option for OPatch
Here are some of the advanced options of OPatch utility.
UpdateRemoteNodes
It is used to propagate/remove files/directories to/from remote nodes using files under
ORACLE_HOME/.patch_storage/<ID>/rac/*.
The directories listed in copy_dirs.txt will be copied to remote nodes.
The files listed in copy_files.txt wil be copied to remote nodes.
The directories listed in remove_dirs.txt will be deleted from remote nodes.
The files listed in remove_files.txt will be deleted from remote nodes.
This is used where RAC setup is present.
Cleanup
It is used to clean up restore.sh, make.txt files and rac, scratch, backup directories in the
ORACLE_HOME/.patch_storage directory. If -ps option is used, then it cleans the above
specified areas only for that patch, else for all patches under ORACLE_HOME/.patch_storage.
You will be still able to rollback patches after this cleanup.
Example: opatch util cleanup -ps 6121183_Ju _21_2007_04_19_42
CopyListedFiles
It is used to copy all files listed in ORACLE_HOME/.patch_storage/<ID>/rac/copy_files.txt to
remote nodes. If -fp option is used, then one can specify the path of the file containing the list of
files to be copied. The files mentioned in this file will be copied to the remote nodes.
Example: opatch util copylistedfiles -fp a -remote_nodes ceintcb-a5
This is used where RAC setup is present.

CopyListedFilesTest
It is used to copy a single file to remote nodes. The usage remains the same as CopyListedFiles.
Example: opatch util copylistedfilestest -fp /home/oracle/a -remote_nodes ceintcb-a5
This is used where RAC setup is present.
CopyListedDirs
It is used to recursively copy all directories listed in
ORACLE_HOME/.patch_storage/<ID>/rac/copy_dirs.txt to remote nodes. If -dp option is used,
then one can specify the path of the file containing the list of directories to be copied. The
directories mentioned in this file will be copied to the remote nodes.
This is used where RAC setup is present.
CopyListedDirsTest
It is used to copy a single file to remote nodes. The usage remains the same as CopyListedDirs.
This is used where RAC setup is present.
RemoveListedFiles
It is used to remove files listed in ORACLE_HOME/.patch_storage/<ID>/rac/remove_files.txt
on remote nodes. If -fr option is used, then one can specify the path of the file containing the list
of files to be removed. The files mentioned in this file will be removed from the remote nodes.
This is used where RAC setup is present.
RemoveListedFilesTest
It is used to remove a single file from remote nodes. The usage remains the same as
RemoveListedFiles.
This is used where RAC setup is present.
RemoveListedDirs
It is used to recursively remove directories listed in
ORACLE_HOME/.patch_storage/<ID>/rac/remove_dirs.txt from remote nodes. If -dr option is
used, then one can specify the path of the file containing the list of directories to be removed.
The directories mentioned in this file will be removed from the remote nodes.
This is used where RAC setup is present.
RemoveListedDirsTest
It is used to remove a single directory from remote nodes. The usage remains the same as
RemoveListedDirs.
This is used where RAC setup is present.

RunLocalMake
It is used to invoke re-link on the local node. The make commands are stored in
ORACLE_HOME/.patch_storage/<ID>/make.txt. You need to use the -ps option to specify the
Patch ID with timestamp. A directory by this name will be present under
ORACLE_HOME/.patch_storage. The make.txt file present under
ORACLE_HOME/.patch_storage/<Patch ID with timestamp>/ will be used to perform the local
make operation. This command cannot be run if you have already run Cleanup as it would have
removed these make.txt files.
Example: opatch util runlocalmake -ps 6121250_ un_21_2007_04_16_11
RunRemoteMake
It is used to invoke re-link on remote nodes. The make commands are stored in
ORACLE_HOME/.patch_storage/<ID>/rac/makes_cmd.txt. The usage remains the same as
RunLocalMake.
This is used where RAC setup is present.
RunAnyCommand
It is used to run any command on remote nodes. The command should be specified using the
-cmd option.
Example: opatch util runanycommand -remote_nodes ceintcb-a5 -cmd ls
This is used where RAC setup is present.
LoadXML
It is used to check the validity of an XML file. The -xmlInput option can be used to specify the
path of the xml file.
@ Support can use this utility to verify the integrity of XML files contained in the local and
central inventory.
Example: opatch util loadxml -xmlInput
$ORACLE_HOME/inventory/ContentsXML/comps.xml
Verify
It is used to run the patch verification process to ensure that the patch was applied to the
ORACLE_HOME. It uses the defined ORACLE_HOME and the given patch location via -ph, to
run the check.
@ Support can use this utility to re-run the OPatch verification stage, if required for patch
diagnosis. The patch staging area has to be present or created.
Example: opatch util verify -ph ~/6646853/6121183

Troubleshooting
Some times the inventory get corrupted because of some issues. In that case you need to repair
the inventory. Following are the two methods which I know can be used to repair the inventory.
1) Development has released a utility (checkinv) which can be use to repair the inventory if it
becomes corrupted for some reason.
Please note that this version of checkinv works only for 9.2 and 10.1 releases of oracle database.
This doesnt work for 10.2 releases of oracle database.
You can download the checkinv utility from Patch 4121946.
To cleanup the components, you should determine the unwanted or dangling components, then
specify those using the option -remcomp, to cleanup the component list.
The utility detects and asks users permission to repair a bad inventory. In case you want to
repair the inventory, the utility will first back up the files before any modification.
However, it is better that you backup the inventory before running the tool.
For more details, check metalink note ID 298906.1
2) Creating a new inventory using Oracle Universal Installer (OUI).
Check my older post http://advait.wordpress.com/2008/03/21/creating-oracle-home-inventoryoracle-database-10g/ for the same.
Hope this helps !!
References:
Metalink note ID : 298906.1
Metalink note ID : 554417.1
Metalink note ID : 374092.1
Metalink note ID : 357221.1

What is the OPatch?


The OPatch is the Oracle Interim Patching Tool. You need to install the "OPatch" utility. OPatch
is used for patching
Oracle software. If you have an older version of opatch it is strongly recommended to back it up.
The OPatch tool is Oracle's only supported method of installing Interim patches.
How can I install the OPatch utility?

To install this patch simply extract the most uptodate OPatch zip file. Unzip it the file directly
under the ORACLE_HOME. Then check the version by typing "opatch version" command.
How to run the OPatch utility?
OPatch tool works with Perl. You need to have JDK to be in your Oracle Home.
How to invoke the OPatch process?
Go to the patch directory that you want to apply the patch.
For example:
# cd 5225799
# opatch apply -the run the opatch tool.
For Oracle 8i and lower version use the following steps:
The instructions for installing Oracle patch set in general and it will assume a minimal
familiarity with the Oracle Universal Installer and version of upgrade is in the forth level of
release x.x.x.?.0.0, for example 8.1.7.?.? up.
You must remember that applying a patch for each release could be different and the following
instruction are not applicable to any specific patch. Please read and study the patch instruction
before applying them to your system.
As with any maintenance operation, Oracle Corporation recommends that you back up your
Oracle software before making any changes to it.
Notes
On UNIX systems, if you require /usr/ucb in your search path, make
sure that it comes after /usr/bin and/or /usr/ccs/bin in the $PATH
setting.
If an inadvertent attempt is made to apply Patch Sets that applies to
8.1.7 release or up, then if it is not applicable a warning dialog box
entitled Dependencies is displayed like the following message:
There are no patches that need to be applied from the patch set
Oracle8i Patchset 8.1.7.4.0.

1.
2.
3.

4.

5.

Log in to the oracle account and make sure the environment is set to the correct
ORACLE_HOME and ORACLE_SID.
Uncompress and un-tar the downloaded patch set file into a new directory.
Shut down the existing Oracle Server instance with normal or immediate priority. I.e.:
Shutdown all instances (cleanly) if running Parallel Server. Stop all listener, agent and
other processes running in or against the ORACLE_HOME to be installed into.
Start the installer:
o If the Installer was installed during the installation, then run the installer from
within the $ORACLE_HOME/bin directory.
o If the Installer was not installed during the installation, then run the installer from
within the top-level directory on the original Oracle version.
You may install the Patch Set through either an interactive or a silent installation.

To perform an interactive installation using the Oracle Universal Installer


graphical interface:
1. Start the installer from whichever of the above directories is appropriate
on your installation:
% ./runInstaller

2.

Follow the steps given below within the installer:


1. On the Welcome screen, click the Next button. This will display
the File Locations screen.
2. Click the Browse button for the Source... entry field and navigate
to the stage directory where you unpacked the Patch Set tar file.
3. Select the products.jar file. Click the Next button
The products file will be read and the installer will load the product
definitions. The products to be loaded will be displayed.

Verify the products listed and then click on the Install button.
5. Once the installation has completed successfully, it will display
End of Installation. Click on Exit and confirm to exit the installer.
To perform a silent installation requiring no user intervention:
Copy the response file template provided in the response directory where
you unpacked the Patch Set tar file.
Edit the values for all fields labeled as "<Value Required>" according to
the comments and examples in the template.
Start the installer from whichever of the directories described in Step 4
applies to your situation passing as the last argument the full path of the
response file template you have edited locally with your own value of
ORACLE_HOME and FROM_LOCATION:
4.

o
2.
3.
4.

% ./runInstaller -silent -responseFile


<full_path_to_your_response_file>
6.

7.

8.

If you have previously installed Oracle Label Security then add object files to library.
This step is necessary because the installation of this patch set removes Oracle Label
Security object files from RDBMS library.
Link in ols .o files using the following steps:
cd $ORACLE_HOME/lbac/lib
make -f lbac.mk xkzl
make -f lbac.mk ilbac
cd $ORACLE_HOME/rdbms/lib
make -f ins_rdbms.mk ioracle
Disabling system triggers.
Before performing the next step, you must first set _SYSTEM_TRIG_ENABLED =
FALSE in the initialization parameter file. To do this add the following line to your
init<sid>.ora file and restart the database (see Note 149948.1 in Metalink for more
information on this issue).
_system_trig_enabled=false
Invoke SQL*Plus (sqlplus), connect as internal and run the following:
select * from duc$ where PACK='JIS$INTERCEPTOR$' ;

If no rows were returned go to the next step. If a row was returned delete it using the following:

delete from duc$ where PACK='JIS$INTERCEPTOR$' ;


commit;
9.

Invoke SQL*Plus (sqlplus), connect as internal (/ as sysdba) and run the following SQL
scripts with event 10520 set. NOTE: This event is not intended for regular database
operation and when turned on below by the 'ALTER SESSION' command will
automatically be turned off by the subsequent 'CONNECT' command.
ALTER SESSION SET EVENTS '10520 TRACE NAME CONTEXT FOREVER, LEVEL 10';
?/rdbms/admin/catalog.sql
?/rdbms/admin/catproc.sql
?/rdbms/admin/catrep.sql (This only needs to be run if you are using
symmetric/advanced replication. This is not necessary for sites using dblinks and read-only
snapshots if symmetric/advanced replication is not installed)

CONNECT / AS SYSDBA;
update obj$ set status=5 where type#=29 and owner#!=0;
commit;
10.

You can ignore this step if you have already executed it as part of a previous patch set
install.

If Java has previously been loaded into the database, invoke SQL*Plus (sqlplus), connect as
internal and run the following SQL DDL command(* Note:If Java has not previously been
loaded into the database, skip this step).:
SQL> create or replace java system
2 /
(Note that the / (slash) is important to ensure the execution of the command).
To ensure the correct installation of the XDK in the database run the following 2 scripts (Bug
2115227):

$ORACLE_HOME/oracore/admin/initxml.sql
$ORACLE_HOME/rdbms/admin/catxsu.sql

* To determine whether Java has previously been loaded into the


database:
invoke SQL*Plus (sqlplus), connect as internal and run the following:
SQL> select count(*) from all_objects where object_type like 'JAVA%';

Java is installed if you get a non zero result returned from the query.
11.
12.

You can ignore this step if you have already executed it as part of a previous patch set
install:
If Java has previously been loaded into the database, invoke SQL*Plus (sqlplus), connect as
internal and run the following scripts which are located in $ORACLE_HOME/javavm/install (
Note: If Java has not previously been loaded into the database, you can skip this
step):

load_jis.sql
jisja.sql
initjsp.sql
jspja.sql
Notes:
When running the $ORACLE_HOME/javavm/install/jisja.sql script the following error may be
reported and can be ignored:

call jis_exit_java_session(0)
ERROR at line 1:
ORA-29515: exit called from Java code with status 0
Bug 1459233 was filed against this problem which is fixed in 9i.

13.

If you deleted a row from duc$ in step 8 then reinsert it again. Invoke SQL*Plus
(sqlplus), connect as internal and run the following SQL:
insert into duc$ (OWNER, PACK, PROC, FIELD1, OPERATION#, SEQ) values
('SYS', 'JIS$INTERCEPTOR$', 'USER_DROPPED', 0, 1, 1);
commit;

14.

15.

Enabling system triggers.


You must either remove _SYSTEM_TRIG_ENABLED from the initialization parameter
file or explicitly set it to TRUE before attempting any other patch set post-install steps.
Restart the database.
This step is optional - it will recompile all invalid PL/SQL packages now rather than
when accessed for the first time - you can also use utlrcmp.sql to parallelize this. Invoke
SQL*Plus (sqlplus), connect as internal and run the following SQL script:

?/rdbms/admin/utlrp.sql

16. Execute the following steps only if you have installed Oracle

interMedia Text in the database you are attempting to modify:


o If you have not previously unlocked the ctxsys account and
supplied a password for that account, you need to do so. (If you
have needed to use Oracle Text in any way prior to applying the
patchset, you will have already performed this step, and you can
skip this.) Do so by issuing the following statement:
ALTER USER ctxsys IDENTIFIED BY <passwd> ACCOUNT UNLOCK;
1. If you have already installed 8.1.7.2 or 8.1.7.3, go directly to
step 7 below.
2. If you have already installed 8.1.7.1, go directly to step 5
below.
3. CONNECT ctxsys/<passwd>;
4. @?/ctx/admin/upgrade/u0801071.sql
5. CONNECT ctxsys/<passwd>;
6. @?/ctx/admin/upgrade/u0801072.sql
7. CONNECT / AS SYSDBA;
8. @?/ctx/admin/upgrade/s0801074.sql
9. CONNECT ctxsys/<passwd>
10. @?/ctx/admin/dr0pkh.sql
11. @?/ctx/admin/dr0plb.sql
12. @?/ctx/admin/dr0type.plb
13. @?/ctx/admin/dr0typec.plb

17.

You can ignore this step if you have already executed it as part of a previous patch set
install:

The installation of this patch set fixes a potential security hole in the XSQL Servletl. The
patchset installation does not, however, modify any of the Oracle HTTP Server configuration
files to reflect changes to the XSQL Servlet installation. If you have previously installed the
Oracle HTTP Server, you will need to update one of the configuration files manually after the
patchset installation is complete. If you do not do so, the XSQL Servlet may not work in the
context of the Oracle HTTP Server after the patchset is installed. To update your Oracle HTTP
Server configuration, perform the following steps:
1) Edit the file: $ORACLE_HOME/Apache/Jserv/conf/jserv.properties
2) Search for the string: "XSQLConfig.xml File location"
3) Modify the parameter wrapper.classpath on the line immediately following the above string
to read: $ORACLE_HOME/oracore/admin
4) Save the file.
18.

You can ignore this step if you have already executed it as part of a previous patch set
install:
The installation of this patch set fixes a potential security hole in the PL/SQL XML parserl. To

load the new XML parser in to the database, run the following script as user SYS:
? /xdk/plsql/parser/bin/load.sql
19.

If you are using the RMAN catalog then upgrade it as follows:


o
o
o

rman catalog <user/passwd@alias>


upgrade catalog;
upgrade catalog;

The post install actions are now complet.

Вам также может понравиться