Wednesday, June 20, 2018

Datapatch: Database 12c Post Patch SQL Automation (Doc ID 1585822.1)

In this Document
Purpose
Scope
Details
 Enterprise Manager:
 OPatchAuto :
 OPatch :
 Datapatch :
 Datapatch usage :
 Datapatch in a Multitenant Environment:
 Changes for DB release 12.1.0.2
 Miscellaneous
 Prerequisite Checks
 Known Issues:
References

APPLIES TO:

Oracle Database - Standard Edition - Version 12.1.0.1 and later
Oracle Database - Enterprise Edition - Version 12.1.0.1 and later
Oracle Database - Personal Edition - Version 12.1.0.1 and later
Information in this document applies to any platform.

PURPOSE

 Explain Database 12c Post Patch SQL Automation

SCOPE

Database release 12c extends patch install automation for patches that contain post-patch SQL instructions.
Prior to Oracle 12c such patches required manual intervention to complete the post-patch SQL instructions after restarting the database.
Datapatch is the new tool that enables automation of post-patch SQL actions for RDBMS patches.
Datapatch resides in the opatch directory i.e $ORACLE_HOME/OPatch folder (On Windows platforms : %ORACLE_HOME%\OPatch).

Datapatch can be executed to complete post-patch SQL actions after the database is restarted following patch application.
For patches that do not have post-patch SQL actions to be performed, calling datapatch is a no-op.
For patches that do have post-patch SQL instructions to be invoked on the database instance, datapatch will automatically detect ALL pending actions (from one installed patch or multiple installed patches) and complete the actions as appropriate.

Further details on datapatch are provided towards the end of this document.
Enterprise Manager and OPatchAuto provide further automation of database patches by calling datapatch automatically after applying the binary patch.


Following section describes how various patching tools implement this automation flow.

DETAILS

Enterprise Manager:

Starting version 12.1 Enterprise Manager now calls datapatch to complete post patch actions upon any 12c or later database restart.
As noted above, datapatch contains the logic to identify if any post-patch SQL actions are pending.

OPatchAuto :

OPatchAuto calls datapatch to complete post patch actions upon installation of the binary patch and restart of the database.
As noted earlier, datapatch identifies the post install instructions which are necessary and automatically completes the same.
Post patch activity include both the application and the removal or rollback of SQL changes in the database.

OPatch :


Datapatch integration with OPatch is not possible as OPatch is executed when the database is down and
datapatch requires the database to be opened to complete its activity.
When patches are installed or rollbacked using OPatch then datapatch needs to be explicitly invoked if instructed to do so in the patch readme.
Datapatch is designed to be idempotent and can be run for all patches and
it is recommended that datapatch be run post any patch apply or rollback activity when OPatch is used.
(In computing, an idempotent operation is one that has no additional effect if it is called more than once with the same input parameters.)

Datapatch :

Datapatch is the patching tool to complete the post-patch SQL actions for RDBMS patches.
Windows specific : On Windows platforms the script name is datapatch.bat.
RAC specific: For a RAC environment, after the binary patch has been applied on all nodes run Datapatch to complete the post-install SQL deployment for the PSU only from one node. Datapatch need not be run on all the nodes.
Datapatch determines the requisite apply/rollback actions by matching an internal repository with the patch inventory.
Datapatch should be invoked when the database is restarted after a patching session.
Enterprise Manager and OPatchAuto call datapatch automatically during every patching session.
If OPatch is used to install RDBMS patches then datapatch has to be explictly called to complete any patching actions after database restart.
Datapatch will automatically determine the set of patches that need to be installed and a set of patches that need to be rolled back.
Datapatch ensures that a patch has been installed/rolled back in all RAC instances before to initiate any post-patch SQL actions on the database.
In Oracle Multitenant environment datapatch will patch the root and any pluggable databases that are opened.
In order to patch all pluggable databases, it should be ensured that before to invoke datapatch all pluggable databases are opened.
If an unpatched pluggable database is opened in Oracle Multitenant then calling datapatch will complete the pending patch actions.

Datapatch usage :

All arguments are optional, if there are no arguments then datapatch will automatically determine which SQL scripts need to
be run in order to complete the installation of any patches that contain post-patch SQL instructions.

Optional arguments:

-db <sid>
Use the specified database's SID rather than $ORACLE_SID

-apply <patch1,patch2,...,patchn>
Only consider the specified patch list for apply operations

-rollback <patch1,patch2,...,patchn>
Only consider the specified patch list for rollback operations

-force
Run the apply and/or rollback scripts even if not necessary per the SQL registry

-prereq
Run prerequisite checks only, do not actually run any scripts

-oh <oracle_home value>
Use the specified directory to determine what patches are installed

-verbose
Output additional information used for debugging

-help
Output usage information and exit

-version
Output build information and exit

Datapatch in a Multitenant Environment:

When datapatch is run to invoke any SQL actions in a Multitenant environment, datapatch only applies the changes to the ROOT, SEED and any open PDBs based on the pending actions.  For any PDB that is not currently open, the SQL patch will not be applied.  When such a PDB is reopened, it will be opened in restricted mode as there will be a patch level mismatch between the PDB and the ROOT.

Call DBMS_PDB.CHECK_PLUG_COMPATIBILITY on 12.1.0.1. PDB xml file will return these two violations, which are expected.
  SQL Patch              ERROR
 
SQL patch bug # mismatch: Installed in the PDB but not in the CDB.   Install the SQL patch in the PDB or the CDB

This error can be cleared by running datapatch again and closing and reopening the affected PDB(s)
1)    Invoke datapatch:
% cd $ORACLE_HOME/OPatch
% datapatch
2)    Close and reopen the affected PDB
Connect as SYS
alter pluggable database <PDB Name> close instances =all;
alter pluggable database <PDB Name> open read write instances =all;
3) Check again for plugin violations (by querying pdb_plug_in_violations in cdb$root), there should be none and the pluggable database should be opened in normal mode

Changes for DB release 12.1.0.2

Miscellaneous

  1. Catbundle Integration:  Datapatch now assumes the role of catbundle when applying bundles/PSU.  As a result of this change catbundle.sql has been deprecated and patch registry is maintained only in registry$sqlpatch.  Application of the PSU does not update registry$history table anymore.  The status for patch application is now entirely maintained in registry$sqlpatch
  2. Support for patch UID:  Datapatch now uses patch-ID and patch-UID to uniquely identify a patch. With this change, datapatch now distinguishes between different versions of a single patch.  This allows datapatch to handle the case of re-issued patches correctly.
  3. Support for –force –rollback all:  Datapatch now provides the option to rollback all patches from a given container DB using the –force option.  This is useful for unplug/plug of container databases
  4. Integration with upgrade/downgrade scripts
  5. Improved error checking for PLS errors and warnings.

Prerequisite Checks

In 12.1.0.2 Datapatch now has pre-req checks for a number of conditions.  These pre-req checks prevent patching and have the following reasons and potential issues:

  1. Upgrade mode check:

    If a patch requires upgrade mode startup, datapatch enforces that via a pre-req check.  To overcome this error, DB/PDB needs to be re-started in Upgrade/Migrate mode to complete patching.  Please note that when there are a number of simultaneous patch applications pending, datapatch will fail the upgrade mode pre-req check if any of the pending patches requires upgrade mode startup. The database being started in Upgrade mode will have no impact on other patches being applied which do not require Upgrade mode.

    Alternatively, any patches not requiring upgrade mode can be installed by invoking datapatch with the –apply < bug # > option
     
  2. Check for existence of Apply/Rollback scripts:

    Datapatch now ensures that apply/rollback scripts are present for any pending patch apply/rollback.  If the files are not available datapatch will fail with a pre-req error.  For out of place rollback please copy any sqlpatch files to the $OH in order to overcome this check and allow rollback to proceed
     
  3. Queryable Inventory connectivity :

    Datapatch flags a Queryable inventory error if for some reason Queryable Inventory returns an error status.  Further details can be derived by calling select dbms_qopatch.get_pending_activity from dual and noting the error message.  Further details on resolving Queryable Inventory issues can be found at Note 1530108.1, "Oracle Database 12.1 : FAQ on Queryable Patch Inventory"
     
  4. DB connectivity:  datapatch has a pre-req check to ensure DB connectivity.
     
  5. Pre-req to ensure we can create directories under cfgtoollogs dir.

No comments:

Post a Comment