0% found this document useful (0 votes)
632 views

Step to step guide on applying patches on Oracle 19C DB

Uploaded by

nbk2020
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
632 views

Step to step guide on applying patches on Oracle 19C DB

Uploaded by

nbk2020
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

In this document, we will go over the steps to apply the latest Oracle 19c Database Release Update

19.25.0.0.241015 (36912597) in a container database environment.

WHAT ARE PATCHES?


Patches are essential software or operating system (OS) updates that address security
vulnerabilities and enhance performance. Software vendors release these updates to fix bugs and
improve security features.

Oracle releases patches quarterly, known as Critical Patch Updates (CPU), addressing security
vulnerabilities across its products. Oracle strongly recommends applying the latest patches to
safeguard databases.

Why is patching important?


• Security: Patches fix vulnerabilities, preventing unauthorized access and safeguarding data
integrity.
• Stability: Patches resolve bugs, ensuring reliable performance and reducing downtime.
• Compliance: Patches help meet data protection and privacy regulations.

Using supported software versions with up-to-date patches ensures continuous support from
Oracle, enhancing both security and performance.

NOTE: Patching is resource-intensive. Ensure you allocate enough CPU and memory. Keep in mind
that patching time depends more on available resources than on the number or size of databases.

Step 1: Identify Patches (by checking the current patch level)


The OPatch utility, located in the ORACLE_HOME/OPatch directory, helps keep Oracle
software current and secure. It provides flexibility to analyze, troubleshoot, and apply
patches to individual Grid Infrastructure and Real Application Cluster (RAC) home
environments.

[root@oracle ~]# su - oracle


[oracle@oracle ~]$ . oraenv
ORACLE_SID = [oracle] ? orcl
[oracle@oracle ~]$
[oracle@oracle ~]$ cd $ORACLE_HOME/OPatch
[oracle@oracle OPatch]$
The opatch lspatches is used to list the summary of all installed patches.
[oracle@oracle OPatch]$ ./opatch lspatches
To see the current version of Opatch utility use ./opatch version or from querying the
dba_registry_sqlpatch
[oracle@oracle OPatch]$

Page | 1
[oracle@oracle OPatch]$ ./opatch version

[oracle@oracle OPatch]$ sqlplus / as sysdba


SQL> SELECT TO_CHAR(action_time, 'YYYY-MM-DD') AS action_time,
action,status,description,patch_id FROM dba_registry_sqlpatch ORDER by action_time;

The patch ID 29517242 was successfully applied to the root container on 2023-09-11. We can also
query the pluggable databases (PDBs) to confirm the patch status by switching to each PDB.
The DBA_REGISTRY view provides information about all components loaded into the component
registry. This registry tracks the status and version of each component in the database.

SQL>col comp_id for a10


col version for a11
col status for a10
col comp_name for a37
select comp_id,comp_name,version,status from dba_registry;

Page | 2
It is important to identify and fix any invalid object before patching. To identify invalid object,
query the dba_objects.
SQL> COLUMN object_name FORMAT A30
SELECT owner,
object_type,
object_name,
status
FROM dba_objects
WHERE status = 'INVALID'
ORDER BY owner, object_type, object_name;

Also check for the PDB

If it returns invalid objects, run this script to fix it.


SQL> @?/rdbms/admin/utlrp.sql

Page | 3
Step 2: Download patch

HOW TO DOWNLOAD PATCHES?


Log into https://support.oracle.com

From the tabs grouped above, select the tab Patches & Updates, select the Product or Family tab

Search for the desired patch. e.g for product – Oracle Database -Enterprise, Realease – Oracle
databases 19.0.0.0.0 and my platform – linux x86-64 – then select Search.

Page | 4
Click on the patch name link, 3692597 for the database release update, you will be redirected to a
new page for download

It is important to always review the README file that accompanies patches, as it contains detailed
instructions for proper installation. For example, the README for this patch states:
“You must use the OPatch utility version 12.2.0.1.43 or later to apply this patch. Oracle recommends
using the latest available OPatch version for 12.2, which can be downloaded from My Oracle Support
(Patch 6880880) by selecting the ARU link for the 12.2.0.1.0 OPatch release.”

To download, the opatch utility,


Navigate to the Patch & Updates tab on My Oracle Support.
In the search field, enter the Patch Number or Bug Number.
Add the Patch Number 6880880.
Select the appropriate Platform for your environment.

Page | 5
Download the file.

Step 3: Transfer the Downloaded Patch to the Server


After downloading the patch, transfer it from your local machine to the server. You can use SCP
(Secure Copy Protocol) or WinSCP to accomplish this.
Example using SCP on Command Prompt:
scp C:\Users\USER\Desktop\patch\p6880880_190000_Linux-x86-64.zip [email protected]:

Page | 6
STEP 4: Upgrade the Opatch Tool.
Now, let’s upgrade the OPatch tool. We would make a directory for the downloaded software, Move
the downloaded patches to the new directory and grant ownership to the oracle user.
[root@oracle ~]# ls
anaconda-ks.cfg p36912597_190000_Linux-x86-64.zip p6880880_190000_Linux-x86-64.zip
[root@oracle ~]# mkdir /home/oracle/software
[root@oracle ~]# mv /root/p36912597_190000_Linux-x86-64.zip /home/oracle/software
[root@oracle ~]# mv /root/p6880880_190000_Linux-x86-64.zip /home/oracle/software
[root@oracle ~]# chown -R oracle:oinstall /home/oracle/software

[oracle@oracle ~]$ cd /u01/app/oracle/product/19.0.0/db_1


[oracle@oracle db_1]$ OPatch/opatch version
Note: the current Opatch tool is 12.2.0.1.7

We created a backup of the current OPatch directory using today’s date to ensure we can restore it
if needed.
[oracle@oracle db_1]$ mv OPatch/ OPatch_20241016
[oracle@oracle db_1]$ ls OPatch
[oracle@oracle db_1]$ mv OPatch/ OPatch_20241016
[oracle@oracle db_1]$ ls OPatch

To install the new opatch tool, Copy the downloaded OPatch zip file to the ORACLE_HOME
directory:
Make sure you are logged in as the oracle user and unzipped.

[oracle@oracle db_1]$ cp /home/oracle/software/p6880880_190000_Linux-x86-64.zip


/u01/app/oracle/product/19.0.0/db_1/
[oracle@oracle db_1]$ unzip p6880880_190000_Linux-x86-64.zip
Page | 7
To verify that the new OPatch tool has been successfully installed, check its version. You should
notice that the version has updated from 12.2.0.1.17 to 12.2.0.1.44.
[oracle@oracle db_1]$ OPatch/opatch version

Step 5: Shutdown Database and Listener


Before proceeding with the backup, it's essential to shut down the database and the listener.
[oracle@oracle ~]$ sqlplus / as sysdba
SQL> shutdown immediate;
[oracle@oracle ~]$ lsnrctl stop

Step 6: Backup of the oracle home


As per the README documentation, taking a full database backup is essential. It is highly
recommended to back up the ORACLE_HOME binaries and the central inventory before applying
any patches.
Reasons for Backup: In case the patching process encounters issues, restoring the previous Oracle
Home ensures minimal downtime and data integrity.
To backup, we use the Tar command;
[oracle@oracle ~]$ tar -pcvf /home/oracle/backup/oracle_home_bkup.tar $ORACLE_HOME

Page | 8
one can also take the back up; by creating the pfile from spfile and taking the backup of the control
file

Step 7: Applying Patches.


Before applying patches to the production environment, it’s a standard practice to first apply them
in a test environment to identify any potential issues.
To apply a patch, we need to do the following:
• Change directory to the folder with downloaded archive file
• Unzip downloaded archive file,
• Set the ORACLE_HOME Environment Variable
• Update the PATH Environment Variable:
• Add the OPatch folder to the PATH environment variable to ensure the OPatch utility can be
accessed from any directory.
• Change to the Unzipped Directory; Change the current directory to the directory created by
the unzip operation. This is where the OPatch utility will be run.

[oracle@oracle ~]$ cd /home/oracle/software


[oracle@oracle software]$ unzip p36912597_190000_Linux-x86-64.zip
[oracle@oracle software]$ ls
36912597 p36912597_190000_Linux-x86-64.zip p6880880_190000_Linux-x86-64.zip
PatchSearch.xml
[oracle@oracle software]$ cd 36912597/
[oracle@oracle 36912597]$ echo $ORACLE_HOME
/u01/app/oracle/product/19.0.0/db_1
[oracle@oracle 36912597]$ export PATH=/u01/app/oracle/product/19.0.0/db_1/OPatch:$PATH
[oracle@oracle 36912597]$ opatch apply

Page | 9
Subsequently, in another tab, you can use the tail command to monitor the log for progress.

Respond with ‘y’ where appropriate as shown below.

Page | 10
The patch has been successfully applied.

Step 8: Perform Post patch activities


Start the database and the listener
[oracle@oracle 36912597]$ lsnrctl start
[oracle@oracle 36912597]$ sqlplus / as sysdba
SQL> startup

Page | 11
The Datapatch utility must be run to complete the post-install SQL deployment for the applied
patch. Since my environment is a container database, I will open my PDBs and execute the
command. If any PDB is in a mounted state, the Datapatch utility will not apply to it.

SQL> ALTER PLUGGABLE DATABASE ALL OPEN;


SQL> show pdbs;

[oracle@oracle 36912597]$ cd $ORACLE_HOME/OPatch


[oracle@oracle OPatch]$ ./datapatch -verbose

Page | 12
We can confirm that the patch status is successful. The Datapatch utility executes the necessary
apply script to load the modified SQL files into the database. It is clear that the patch has been
applied successfully for the container CDB.

[oracle@oracle OPatch]$ sqlplus / as sysdba


SQL> set markup csv on;
SQL> SELECT TO_CHAR(action_time,'YYYY-MM-DD') AS action_time,action,status,
description,patch_id FROM sys.dba_registry_sqlpatch ORDER by action_time;

Page | 13
We can see that the pdbs are in restricted status. No one can work in restricted status. We need to
restart the database to fix it. Then open the pluggable database.
You can query CDB_REGISTRY_SQLPATCH to make sure that all containers have "Database Release
Update : 19.25.0.0.241015 (36912597)",36912597 installed.

SQL> show con_name;


“CON_NAME"
"CDB$ROOT"
SQL>
SQL> set markup csv on;
SQL> select CON_ID,
TO_CHAR(action_time, 'YYYY-MM-DD') AS action_time,
PATCH_ID,
PATCH_TYPE,
ACTION,
DESCRIPTION,
SOURCE_VERSION,
TARGET_VERSION
from CDB_REGISTRY_SQLPATCH order by CON_ID, action_time, patch_id;

Page | 14
Now, let's identify and recompile any invalid objects in each container. To check for invalid objects,
we can query the ALL_OBJECTS or DBA_OBJECTS views. To recompile these invalid objects, we
will use the UTL_RECOMP script (utlrp.sql).

Check for INVALID OBJECT


SQL> select owner, count(*) count from all_objects where status = 'INVALID' group by owner;

How to fix invalid object


SQL> @?/rdbms/admin/utlrp.sql

Page | 15
Connect to sql: Check Patches status to confirm the patch
SET LINESIZE 500
SET PAGESIZE 1000
SET SERVEROUT ON
SET LONG 2000000
COLUMN action_time FORMAT A12
COLUMN action FORMAT A10
COLUMN comments FORMAT A30
COLUMN description FORMAT A60
COLUMN namespace FORMAT A20
COLUMN status FORMAT A10

SELECT TO_CHAR(action_time,'YYYY-MM-DD') AS action_time,action,status,


description,patch_id FROM sys.dba_registry_sqlpatch ORDER by action_time;

Page | 16
We successfully applied the Oracle 19c patch, enhancing security and performance.

Page | 17

You might also like