Cloning ORACLE_HOME

Oracle patching secrets with $ORACLE_HOME cloning

Oracle Database Tips by Burleson Consulting
Use Oracle home Gold copy Cloning to Make Patches/Upgrades Easy, Quicker, Safer, and With Less Downtime
By John Adolph Palinski
This article describes benefits and techniques of using Oracle home gold copies and clones of these homes.  A gold copy Oracle Home is a master Oracle home whose function is to be copied and deployed to other places for use as an Oracle home.  Patching is done on the gold copy rather than in-place production Oracle homes.  Using a gold Oracle home and cloning of the gold home can reduce the amount of time DBA's spend applying quarterly critical patch updates (CPU's) and bug patches.  Most importantly cloning helps the DBA by reducing database downtime, easing the task of scheduling outages, and eliminating the effect of problems that occur when applying patches in-place.
A common DBA task is to patch Oracle homes and databases.  These patches can be one of the many bug fixes or the quarterly CPU.  Regardless of the reason, the following must be done for every database the DBA is responsible for:

1.     The DBA must move the patch software to the server and unzip the file.
2.     Make sure the environment is setup properly to run Opatch.
3.     Shutdown the listener and database.
4.     Patch the Oracle home.
5.     Restart the database and listener
6.     Run Catcpu.sql.
7.     Run Utlrp.sql to compile PL/SQL.
Step 4 is often a time consuming and risky task.  There are many possibilities that can cause the Oracle home patch to fail.  Some reasons are: incorrect patch versions, the environment is not set up properly for Opatch, or a failure to stop some processes using the Oracle home.  Step 4 is performed when the database is down and unavailable for the users.  Thus, it is very important to the DBA that this step NOT FAIL.  If any problems occur in this step, the database outage is increased and the DBA's stress and anxiety begin to grow geometrically.  The DBA has to try to identify the problem/solution or decide whether the patch should be rolled back.  This is where gold copy Oracle home cloning becomes the tool of choice since the step is eliminated by cloning. 
Gold copy Oracle home cloning allows the DBA to patch a cloned Oracle home that is NOT USED by a running database.  If problems occur, the running database is not affected.  Only AFTER the cloned gold copy Oracle home is patched is it moved to the proper location and the database brought down and pointed to the new Oracle home.  If any problems occur, the original Oracle home is still available allowing the DBA to retreat and point the database back to the original home and if necessary restore the database from backup.
In addition, Oracle home cloning offers you the possibly of eliminating Steps 1, 2, and 4.  This can be a time saver, reduce outage time, and eliminate scheduling problems.  It is possible to create an Oracle home gold copy on a server in a compressed state and move the gold copy to a target server.  Patching a gold copy and moving this copy to a target server can be a very effective tool.  Let's look at some scenarios.
In the first scenario, four Oracle homes exist on different servers, each containing a single database.  The DBA must perform all of the seven steps listed above.  Four outages need to be planned and the DBA has to take the risk of patching an Oracle home in-place four times.  Scheduling is easy since each Oracle home patch is independent of the others.  If the DBA uses a cloned gold copy and moves the gold copy to each server, time can be saved.  FTPing a compressed gold copy to the target server and uncompressing the gold copy usually takes less time than performing steps 1, 2, 3, and 4 on each home.  More important, once the gold copy is uncompressed, you have a valid Oracle home.  You do not have to patch the Oracle home during the outage.  You don't have to run Opatch since it was done on the gold copy.  All that is necessary is to shut down the database, register the Oracle home with the Oracle inventory, run Catcpu.sql, change the environment to point to the new Oracle home, and start the database and listener.  This will positively result in less risk and shorter outages.  
Scenario 2 is a common Oracle home that supports a number of databases.  This type of installation is often used on data servers that support remote applications.  A single Oracle home is used in order to save disk space since one Oracle home takes far less disk space that multiple Oracle homes.
Having a single Oracle home makes patches/upgrades easier since only a single home must be modified.  The arrangement is prone to scheduling problems.  It is often difficult to gain an outage on a single database let alone four databases.  Cloning makes this type of environment effective by easing scheduling processes.  If the DBA only has to point the database toward the new cloned Oracle home and run Catcpu.sql against the database, each database can be scheduled separately.  Cloning makes this possible.  In addition, the cloning has the benefits discussed earlier.  Figure 3 depicts the pointing of databases to the new cloned Oracle home while an existing Oracle home still supports databases. 
Now that you have seen the benefits and reasons for using cloned gold Oracle homes for patches and upgrades, how do you create an Oracle home gold copy and clone an Oracle home?  Actually it is very easy.  If you have Oracle Enterprise Manager Grid Control there is an option on the Deployments page.  However, this function is disabled unless you purchase one of the add-on packages.  If you don't have OEM Grid Control, take heart, it is very easy to clone an Oracle home from the command line.  The next section describes how this can be done. 

Creating, Cloning, and Deploying an Oracle home Gold Copy

Note that the steps and commands in this section pertain to Oracle10g homes only.

  1. Make the initial Oracle home gold copy.  Download the appropriate Oracle database product, launch the Oracle Universal Installer, and create an Oracle home.  Do not create a database.  This Oracle home is the original gold copy version. It is only used for patching and upgrading.

  1. Apply all appropriate patches to initial Oracle home gold copy.

To clone or make a new variation of the Oracle home gold copy, perform the following:

1.  Create another gold copy Oracle home.

a)   Navigate to the gold copy Oracle home parent directory.  In our case we will call this directory /u01/app/oracle/clones.  This directory contains the gold Oracle homes.  The example gold Oracle home is called 10.2.0.2.jan07.

      cd /u01/app/oracle/clones

b)   Make a CPIO archive of the target gold Oracle home.  Again, the target is a directory called 10.2.0.2.jan07.  Replace this gold Oracle home directory reference with yours.  The below CPIO command makes a CPIO file of the 10.2.0.2.jan07 Oracle home.
      find ./10.2.0.2.jan07 -depth | cpio -voB > ./10.2.0.2.jan07.cpio
c)   Make a directory in the /u01/app/oracle/clones directory to unpack the 10.2.0.2.jan07.cpio file created in step b.
      mkdir /u01/app/oracle/clones/tmp
d)   Unpack the 10.2.0.2.jan07.cpio file into the /u01/app/oracle/clones/tmp directory.  First navigate into the tmp directory and issue a Cpio command.  The commands are:
      cd /tmp   or cd /u01/app/oracle/clones/tmp
      cpio  -invd < ../10.2.0.2.jan07
e)   Step D created a /u01/app/oracle/clones/tmp/10.2.0.2.jan07 directory.  You need to rename the 10.2.0.2.jan07 and move it down a directory.  Use this command:
      mv /u01/app/oracle/clones/tmp/10.2.0.2.jan07 /u01/app/oracle/clones/10.2.0.2.jan07b
f)   Step E creates an unregistered Oracle home locate in /u01/app/oracle/clones/10.2.0.2.jan07b.  This step registers the new home with Oracle inventory.  Run these commands:

      export ORACLE_HOME=/u01/app/oracle/clones/10.2.0.2.jan07b
      export PATH=${ORACLE_HOME}:${PATH}
      perl $ORACLE_HOME/clone/bin/prepare_clone.pl
      perl $ORACLE_HOME/clone/bin/clone.pl   \
            ORACLE_HOME=/u01/app/oracle/clones/10.2.0.2.jan07b  \
            ORACLE_HOME_NAME=10_2_0_2_jan07b

g)   Run /u01/app/oracle/clones/10.2.0.2.jan07b/root.sh. 

You now have a cloned, renamed replica of the original Oracle gold copy home (10.2.0.2.jan07).  If you run Oracle Universal Installer, you will see that the clone is registered.  You can now add patches to this home without affecting the original gold home.  After patching, you may want to create a CPIO archive, compress the archive, and delete the actual Oracle home.  This will save space.  The CPIO?d gold copy can be restored at any point for further cloning and moved to other servers for use.  You might note that all of the work was done remotely and does not affect an operating database.

To move a gold copy Oracle home to another location, perform the following: 
1.   Create a compressed CPIO archive of the Oracle home gold copy (Steps A and B above)
2.  FTP the compressed CPIO archive to the new server.  Place the file in the Oracle homes parent directory (i.e. /u01/app/oracle/product). 
3.   Uncompress and unpack the CPIO gold copy version:
      Uncompress 10.2.0.2.jan07b.cpio.Z
             cpio -imvd < 10.2.0.2.jan07b.cpio

4.   Register the database with Oracle Inventory.  Perform Step e.   If this is the first Oracle Home on the server, you must install an Oracle home with Universal Installer before trying to register the cloned Oracle home.  This will create the inventory.  You can delete the home after creation and use the clone.

5.   At this point, the cloned Oracle home is ready to support a database.  You can install a new database for the Oracle home by running Oracle Database Configuration Agent or point an existing database to the new Oracle home.  The following steps can be used to point an existing database to the new Oracle home.

a.  Modify the environment file (inst.ksh) so that the environment will point to the new Oracle home.

b.  Modify the listener file (listener.ora) to point to the new Oracle home.

c.  Modify the Etc/oratab file

d.  Shutdown the database.  Change the environment to the new Oracle home and reload the listener.

e.  Move the old database's pfile/spfile to the location used by the new Oracle home.

f.  Start the database

g.  If this Oracle home is a patched version run Catcpu.sql.

h.  Create a new password file

i.   Check out the upgraded database.
In this article I discussed the benefits of using a gold copy Oracle home and cloning in place of patching an Oracle home in place.  You will find that this practice reduces the patching complexities, risk, and time.  Using a cloned gold copy will also result in less outage time.  Cloning can be done through Oracle Enterprise Manager Grid Control.  If this tool is unavailable, the article describes a set of simple commands that will enable you to create and deploy cloned Oracle homes.  I believe that employment of the techniques discussed in this article will make you life as a DBA easier.


No comments: