*****************************************************************
* Description: Oracle Windows Platform Bundle Patching Procedure
* Compatiablity: RDBMS 10g, 11g, 12c
* Date: 10:31 AM EST, 01/23/2017
*****************************************************************



<1> Oracle Patching Terminology:
    |
    |__ Bundle Patch: A bundle patch is a cumulative collection of fixes for a specific product or component.
    |                 A patch of this type is released as needed depending on the product's requirements. 
    |                 You may also know a bundle patch as: maintenance pack, service pack, MLRs, cumulative patch, or update release.
    |
    |__ [CPU] Critical Patch Update: Critical Patch Updates (CPUs) are the primary means of releasing security fixes for Oracle products. 
    |                                CPUs are cumulative with respect to prior CPUs and generally contain only security fixes.
    |
    |__ [PSU] Patch Set Update: A collection of proactive, stabilizing cumulative patches for a particular product version (base release or patch set). 
    |                           PSUs are cummulative and include all of the security fixes from SPU patches (formerly known as CPU),plus additional fixes.
    |
    |__ [SPU] Security Patch Update: A security patch update is a cumulative collection of security-related bug fixes. Generally, security patch updates are release regularly. 
    |                                The security patch update was previously known as Critical Patch Update or CPU.
    |
    |__ Summary: PSU = Bundle[Patch for production] + SPU[Previous name is CPU]
        |
        |__ Patch Conflict: If a patch makes different changes to the same section of code that another OPatch modifies, then these two patches conflict, 
                            and only one of them can be installed (unless a merge or overlay patch is available).
	
	
	
<2> Link regarding My Oracle Support pathing information:
    |
    |__ https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=208426663367944&id=1454618.1&_adf.ctrl-state=2n05p3rxy_57#aref_section23	
	
	
	
<3> According to the link, find the target Windows bundle patch number:
    |
    |__ Select associated platform [Operating System]
    |
    |__ Review "READ ME" => Patching Step, Post-Patching running script, Opatch utility version.


<5> Fetching invalid objects before patching:	
    |
    |__ SQL> select owner, object_name, object_type, status from dba_objects where status='INVALID';
	
	
<6> Fetching current Opatch version:
    |
    |__ CMD> C:\Oracle\Product\11.2.0\dbhome_2\OPatch\opatch lsinventory
	

<7> If current OPatch version is lower then requirement within READ_ME, follow below procedure:
    |
    |__ Link for downloading [MOS Patch 6880880]: https://updates.oracle.com/download/6880880.html
    |
    |__ Backup old opatch folder: $ORACLE_HOME/Opatch or $GRID_HOME/OPatch
    |
    |__ Unzip the new Opatch package, and place at $ORACLE_HOME or $GRID_HOME/OPatch
	
	
<8> Pre-pathing:
    |
    |__ Caution: This doc is fit for Single Node RAC environment/Oracle Restart/Stand Alone Database on Micoresoft Windows Platform.
    | 	
    |__ Shutdown Database:
    |   	CMD> set ORACLE_HOME=
    |   	SQL> shutdown immediate;
    |
    |__ Shutdown ASM:	
    |		CMD> set ORACLE_HOME=
    |		CMD> set ORACLE_SID=+ASM
    |		CMD> sqlplus / as sysasm
    |		SQL> shutdown immediate
    |
    |__ Shutdown Cluster:
    |		CMD> crsctl stat res -t
    |		CMD> crsctl stop has -f
    |
    |__ Shutdown Oracle Associated Windows Services [Snapshot is suggested]:
	        Oracle Related Services
	        Comm Vault HSM Recaller
	        Comm Vault Communications Services
	        Comm Vault Client Event Manager
	        Distribute Transaction Coordinator
	        Windows Management Instrumentation	
	
	
	
<9> Patching GRID_HOME first: ***CAUTION***
    |
    |__ Move to unzipped patch folder, exp: 
    |
    |       CMD> cd E:\patch_apply_03132015\p20233168_112030_MSWIN-x86-64\20233168
    |
    |__ Move to unzipped patch folder, exp: 
    |
    |       CMD> cd E:\patch_apply_03132015\p20233168_112030_MSWIN-x86-64\20233168
    |
    |__ Patching GRID_HOME via Opatch within GRID_HOME, exp: 
	
            CMD> set ORACLE_HOME=
            CMD> C:\oracle\product\11.2.0\grid_home\opatch\opatch apply
            CMD> C:\oracle\product\11.2.0\grid_home\opatch\opatch rollback -id 26194138

			
			
<10> Patching ORACLE_HOME afterwards: ***CAUTION***
    |
    |__ Verfiy patch got applied:
    |
    |       CMD> c:\app\oracle\product\11.2.0\dbhome_1\OPatch\opatch lsinventory
    |
    |__ Move to unzipped patch folder, exp: 
    |
    |       CMD> cd E:\patch_apply_03132015\p20233168_112030_MSWIN-x86-64\20233168
    |
    |__ Patching ORACLE_HOME via Opatch within ORACLE_HOME, exp:
	
            CMD> set ORACLE_HOME=	
            CMD> C:\oracle\product\11.2.0\oracle_home\opatch\opatch apply	
            CMD> C:\oracle\product\11.2.0\oracle_home\opatch\opatch rollback -id 26194138	
	
	
	
<11> Start services, and cluster:



<12> Post-Patching:
    |
    |__ According to READ_ME, please execute marked SQL script afterwards:
    |
    |      SQL> @C:\oracle\product\11.2.0\dbhome_1\Bundle\Patch36\catwinbundle.sql - Database only
    |      SQL> @C:\oracle\product\11.2.0\dbhome_1\rdbms\admin\utlrp.sql - Database only
    |
    |__ Verify and Compare invalid objects before and afterwards:
	
           SQL> select owner, object_name, object_type, status from dba_objects where status='INVALID';
	

<13> ***CAUTION***
    |
    |__	Generally, patching is copying and overwriting old code piece. If Windows process still holding the file, following errors may come up:	
    |
    |		Following files are active :
    |		C:\oracle\product\112~1.0\dbhome_1\bin\oracommon11.dll
    |		C:\oracle\product\112~1.0\dbhome_1\bin\oraclient11.dll
    |		C:\oracle\product\112~1.0\dbhome_1\bin\oraasmclnt11.dll
    |		Log file location: C:\oracle\product\112~1.0\dbhome_1\cfgtoollogs\opatch\20233168_Mar_19_2015_22_26_41\apply2015-03-19_22-26-41PM_1.log
    |		Recommended actions: OPatch needs to modify files which are being used by some processes.
    |		OPatch failed with error code = 41
    |
    |
    |__ Solutions:
        |
        |__ Method 1: Using ProcessExplor seaching .DLL file name, and kill the process by PID.
        |
        |__ Method 2: Rename "BIN" to "BIN_BKP" 
                      => Reboot server to keep zombia processes 
                      => When system up, whole Oracle processes will not be started up, since BIN folder is missing.
                      => Rename "BIN_BKP" back to "BIN", and then start patching.
	

	
<14> Run script CATBUNDLE.sql:
     |
     |__ o. A database bundle series is a sequence of patches where each patch in the series includes the contents of the previous patch in the series. 
            That is, the patches are cumulative. Database patches can consist of both code changes (.o files) that are linked into the Oracle Database binary file, 
            and/or database changes (.sql or .plb files) that are loaded into the database after the binary has been patched. Code changes are applied through the OPatch utility, 
            which takes care of archiving the provided .o files into the correct library, and relinking Oracle.

            Installation of the database changes is done by catbundle.sql, which takes input from an XML file named bundledata_.xml. 
            This file specifies the particular scripts that need to run for installation or rollback of each patch in the bundle series.
            The catbundle.sql script is executed as part of the application of a database bundle patch. It loads the script files (.sql, .plb) that are a part of 
            the patch into a database. To minimize the amount of change when applying a bundle patch, the minimum list of scripts are executed. catbundle.sql determines the 
            last bundle applied to the database and executes only the scripts in the patch that have changed since the last bundle patch was applied.	 

			
			
<15> Ignore "security update notice" before patching:
     |
     |__ o. Provide your email address to be informed of security issues, install and
            initiate Oracle Configuration Manager. Easier for you if you use your My
            Oracle Support Email address/User Name.
            Visit http://www.oracle.com/support/policies.html for details.
            Email address/User Name:
            
            You have not provided an email address for notification of security issues.
            Do you wish to remain uninformed of security issues ([Y]es, [N]o) [N]:  y