New “OPatch util DeleteInactivePatches” tool for reducing the $ORACLE_HOME size


When you are a sensible person, you patch regularly your Oracle database. After a few years, maybe you noticed that the $ORACLE_HOME increased size from new ~7 GB to …. 26 GB!

$ du -hs /u00/app/oracle/product/19.18.0
26G     /u00/app/oracle/product/19.18.0

Looking better, you find the culprit is the hidden directory $ORACLE_HOME/.patch_storage :

$ du -hs /u00/app/oracle/product/19.18.0/.patch_storage
17G     /u00/app/oracle/product/19.18.0/.patch_storage

Today I show how a new option from OPatch allowed me to regain 11 GB of disk space in a couple of minutes. In a supported way.

Last year I had already presented other options to recover space from Oracle Patching. Below I remind them, but todays post is about the latest and improved way that OPatch tool has to keep only the usual needed patch backups.

The .patch_storage directory inside an Oracle Home has the backup of every changed files when we patch the database software. And this just increases. Check this example of .patch_storage in a a regularly patched DB at my customer, ordered by folder size:

$ du -hs /u00/app/oracle/product/19.18.0/.patch_storage/* | sort -h

4.0K    /u00/app/oracle/product/19.18.0/.patch_storage/LatestOPatchSession.properties
68K     /u00/app/oracle/product/19.18.0/.patch_storage/newdirs.txt
76K     /u00/app/oracle/product/19.18.0/.patch_storage/29585399_Apr_9_2019_19_12_47
88K     /u00/app/oracle/product/19.18.0/.patch_storage/record_inventory.txt
164K    /u00/app/oracle/product/19.18.0/.patch_storage/NApply
188K    /u00/app/oracle/product/19.18.0/.patch_storage/interim_inventory.txt
248K    /u00/app/oracle/product/19.18.0/.patch_storage/29517242_Apr_17_2019_23_27_10
216M    /u00/app/oracle/product/19.18.0/.patch_storage/33529556_Jan_9_2022_21_15_36
217M    /u00/app/oracle/product/19.18.0/.patch_storage/32916816_Jul_19_2021_01_56_39
217M    /u00/app/oracle/product/19.18.0/.patch_storage/34768559_Jan_14_2023_07_39_49
218M    /u00/app/oracle/product/19.18.0/.patch_storage/29850993_Jul_5_2019_05_08_35
220M    /u00/app/oracle/product/19.18.0/.patch_storage/34160635_Jul_10_2022_21_27_08
223M    /u00/app/oracle/product/19.18.0/.patch_storage/32222571_Jan_15_2021_01_49_46
227M    /u00/app/oracle/product/19.18.0/.patch_storage/30489227_Jan_7_2020_03_37_45
228M    /u00/app/oracle/product/19.18.0/.patch_storage/31305087_Jun_25_2020_11_36_08
425M    /u00/app/oracle/product/19.18.0/.patch_storage/30484981_Dec_5_2019_05_10_10
426M    /u00/app/oracle/product/19.18.0/.patch_storage/31219897_Jul_8_2020_01_57_16
427M    /u00/app/oracle/product/19.18.0/.patch_storage/32067171_Dec_2_2020_09_24_57
432M    /u00/app/oracle/product/19.18.0/.patch_storage/32876380_Jul_5_2021_04_53_50
432M    /u00/app/oracle/product/19.18.0/.patch_storage/33561310_Jan_5_2022_08_13_10
432M    /u00/app/oracle/product/19.18.0/.patch_storage/34086870_May_31_2022_05_49_37
432M    /u00/app/oracle/product/19.18.0/.patch_storage/34786990_Dec_6_2022_13_24_50
725M    /u00/app/oracle/product/19.18.0/.patch_storage/29834717_Jul_10_2019_02_09_26
1.2G    /u00/app/oracle/product/19.18.0/.patch_storage/30557433_Jan_6_2020_19_07_34
1.4G    /u00/app/oracle/product/19.18.0/.patch_storage/31281355_Jul_6_2020_11_18_02
1.7G    /u00/app/oracle/product/19.18.0/.patch_storage/32218454_Jan_14_2021_16_24_38
1.7G    /u00/app/oracle/product/19.18.0/.patch_storage/33515361_Jan_13_2022_06_14_07
1.9G    /u00/app/oracle/product/19.18.0/.patch_storage/32904851_Jul_20_2021_09_21_24
1.9G    /u00/app/oracle/product/19.18.0/.patch_storage/34765931_Jan_27_2023_11_25_14
2.0G    /u00/app/oracle/product/19.18.0/.patch_storage/34133642_Jul_14_2022_16_09_56

These backups allow to rollback the $ORACLE_HOME to all previous point in time. However we are very unlikely to do it. While it is possible just delete the contents of the $ORACLE_HOME/.patch_storage and usually there is no issue, this is not supported.

But did you already hit the problem that you don’t have enough space for patching? Oracle recommends a 100 GB partition for the $ORACLE_HOME, but is it really needed?

This post is not about patching, but how to clean-up the .patch_storage directory in a supported way. And mostly about my experience about the recent new feature of OPatch to delete inactive patches from the ORACLE_HOME.

Several years ago, the following option was added to Opatch:

$ORACLE_HOME/OPatch/opatch until cleanup

which “cleans up ‘restore.sh,make.txt’ files and ‘scratch,backup’ directories of the.patch_storage directory of Oracle Home.”

Later, there was the possibility to “archive” the .patch_storage elsewhere:

$ORACLE_HOME/OPatch/opatch archive

which “helps to archive the patches stored under ORACLE_HOME/.patch_storage to custom storage location”. And adds to the help:

RECOMMENDATION :
  To archive patches, opatch recommends the following
    1. Archiving inactive patches :
        Run the following command to get inactive patches :  "OPatch/opatch lsinv -inactive"

Example
        opatch util archive -patches 123456,1122334 -archive_dir /dir1/dir2/

In 2023, since OPatch version 12.2.0.1.37 (current is 12.2.0.1.39), there is a merge of the two tools, which finally allows to use OPatch to delete old inactive patches, keeping only the last one that is not active:

$ORACLE_HOME/OPatch/opatch util DeleteInactivePatches

which “helps to clean up inactive patches stored under ORACLE_HOME/inventory & ORACLE_HOME/.patch_storage”

More over it says:

By default OPatch util deleteinactivepatches retains only 1 latest inactive patch(RU\CPU\BP)
Note: If user needs to retain more than 1 inactive patch, then update the value of RETAIN_INACTIVE_PATCHES in
ORACLE_HOME/OPatch/config/opatch.properties

There is also a list only function:

$ORACLE_HOME/OPatch/opatch util ListOrderedInactivePatches

which is the same as calling the delete function with -report switch:

$ORACLE_HOME/OPatch/opatch util DeleteInactivePatches -report

In my case, here the huge list of patches that comes from its run:

$ORACLE_HOME/OPatch/opatch util DeleteInactivePatches -report

Oracle Interim Patch Installer version 12.2.0.1.39
Copyright (c) 2023, Oracle Corporation.  All rights reserved.

Oracle Home       : /u00/app/oracle/product/19.18.0
Central Inventory : /u00/app/OraInventory
   from           : /u00/app/oracle/product/19.18.0/oraInst.loc
OPatch version    : 12.2.0.1.39
OUI version       : 12.2.0.7.0
Log file location : /u00/app/oracle/product/19.18.0/cfgtoollogs/opatch/opatch2023-08-08_17-09-04PM_1.log

Invoking utility "deleteinactivepatches"
Inactive Patches Cleanup option provided
Delete Inactive Patches .......

***** There are 8 inactive RU patches in chain 1

***** 7 inactive patches will be deleted
-To be deleted inactive RU/BP 29585399:OCW RELEASE UPDATE 19.3.0.0.0 (29585399), installed on: Thu Apr 18 09:21:33 CEST 2019, with no overlays
-To be deleted inactive RU/BP 29850993:OCW RELEASE UPDATE 19.4.0.0.0 (29850993), installed on: Mon Jul 29 15:14:19 CEST 2019, with no overlays
-To be deleted inactive RU/BP 30489227:OCW RELEASE UPDATE 19.6.0.0.0 (30489227), installed on: Mon Feb 03 09:37:21 CET 2020, with no overlays
-To be deleted inactive RU/BP 31305087:OCW RELEASE UPDATE 19.8.0.0.0 (31305087), installed on: Tue Oct 13 13:27:46 CEST 2020, with no overlays
-To be deleted inactive RU/BP 32222571:OCW Interim patch for 32222571, installed on: Tue Mar 09 12:50:27 CET 2021, with no overlays
-To be deleted inactive RU/BP 32916816:OCW RELEASE UPDATE 19.12.0.0.0 (32916816), installed on: Fri Sep 24 11:26:21 CEST 2021, with no overlays
-To be deleted inactive RU/BP 33529556:OCW RELEASE UPDATE 19.14.0.0.0 (33529556), installed on: Thu Feb 10 14:09:40 CET 2022, with no overlays
-To be retained inactive RU/BP 34160635:OCW RELEASE UPDATE 19.16.0.0.0 (34160635), installed on: Thu Dec 15 15:13:06 CET 2022, with no overlays
-Active RU/BP 34768559:OCW RELEASE UPDATE 19.18.0.0.0 (34768559), installed on: Tue Mar 14 10:18:46 CET 2023, with no overlays

***** There are 8 inactive RU patches in chain 2

***** 7 inactive patches will be deleted
-To be deleted inactive RU/BP 29517242:Database Release Update : 19.3.0.0.190416 (29517242), installed on: Thu Apr 18 09:21:17 CEST 2019, with no overlays
-To be deleted inactive RU/BP 29834717:Database Release Update : 19.4.0.0.190716 (29834717), installed on: Mon Jul 29 15:12:44 CEST 2019, with no overlays
-To be deleted inactive RU/BP 30557433:Database Release Update : 19.6.0.0.200114 (30557433), installed on: Mon Feb 03 09:39:40 CET 2020, with no overlays
-To be deleted inactive RU/BP 31281355:Database Release Update : 19.8.0.0.200714 (31281355), installed on: Tue Oct 13 13:23:33 CEST 2020, with no overlays
-To be deleted inactive RU/BP 32218454:Database Release Update : 19.10.0.0.210119 (32218454), installed on: Tue Mar 09 12:42:54 CET 2021, with no overlays
-To be deleted inactive RU/BP 32904851:Database Release Update : 19.12.0.0.210720 (32904851), installed on: Fri Sep 24 11:17:00 CEST 2021, with no overlays
-To be deleted inactive RU/BP 33515361:Database Release Update : 19.14.0.0.220118 (33515361), installed on: Thu Feb 10 14:02:39 CET 2022, with no overlays
-To be retained inactive RU/BP 34133642:Database Release Update : 19.16.0.0.220719 (34133642), installed on: Thu Dec 15 15:07:21 CET 2022, with no overlays
-Active RU/BP 34765931:DATABASE RELEASE UPDATE : 19.18.0.0.230117 (REL-JAN230131) (34765931), installed on: Tue Mar 14 10:12:42 CET 2023, with no overlays

***** There are 6 inactive RU patches in chain 3

***** 5 inactive patches will be deleted
-To be deleted inactive RU/BP 30484981:OJVM RELEASE UPDATE: 19.6.0.0.200114 (30484981), installed on: Mon Feb 03 09:26:39 CET 2020, with no overlays
-To be deleted inactive RU/BP 31219897:OJVM RELEASE UPDATE: 19.8.0.0.200714 (31219897), installed on: Tue Oct 13 13:20:35 CEST 2020, with no overlays
-To be deleted inactive RU/BP 32067171:OJVM RELEASE UPDATE: 19.10.0.0.210119 (32067171), installed on: Tue Mar 09 12:38:35 CET 2021, with no overlays
-To be deleted inactive RU/BP 32876380:OJVM RELEASE UPDATE: 19.12.0.0.210720 (32876380), installed on: Fri Sep 24 11:10:35 CEST 2021, with no overlays
-To be deleted inactive RU/BP 33561310:OJVM RELEASE UPDATE: 19.14.0.0.220118 (33561310), installed on: Thu Feb 10 14:12:21 CET 2022, with no overlays
-To be retained inactive RU/BP 34086870:OJVM RELEASE UPDATE: 19.16.0.0.220719 (34086870), installed on: Thu Dec 15 15:05:34 CET 2022, with no overlays
-Active RU/BP 34786990:OJVM RELEASE UPDATE: 19.18.0.0.230117 (34786990), installed on: Tue Mar 14 10:19:19 CET 2023, with no overlays

OPatch is in report mode. No actual deletion happened. Reporting is done.

OPatch succeeded.

Just to write this report, it took about 2 minutes. I could not find why it took so long.

$ time $ORACLE_HOME/OPatch/opatch util ListOrderedInactivePatches
...
real    2m46.644s
user    2m48.534s
sys     0m2.317s

These are the contents of my .patch_storage folder:

$ ls -altr $ORACLE_HOME/.patch_storage

total 360
drwxr-xr-x.  3 oracle dba     74 Apr 18  2019 29517242_Apr_17_2019_23_27_10
drwxr-xr-x.  3 oracle dba     74 Apr 18  2019 29585399_Apr_9_2019_19_12_47
drwxr-xr-x.  4 oracle dba     87 Jul 29  2019 29834717_Jul_10_2019_02_09_26
drwxr-xr-x.  4 oracle dba     87 Jul 29  2019 29850993_Jul_5_2019_05_08_35
drwxr-xr-x.  4 oracle dba     87 Feb  3  2020 30484981_Dec_5_2019_05_10_10
drwxr-xr-x.  4 oracle dba     87 Feb  3  2020 30489227_Jan_7_2020_03_37_45
drwxr-xr-x.  4 oracle dba     87 Feb  3  2020 30557433_Jan_6_2020_19_07_34
drwxr-xr-x.  4 oracle dba     87 Oct 13  2020 31219897_Jul_8_2020_01_57_16
drwxr-xr-x.  4 oracle dba     87 Oct 13  2020 31281355_Jul_6_2020_11_18_02
drwxr-xr-x.  4 oracle dba     87 Oct 13  2020 31305087_Jun_25_2020_11_36_08
drwxr-xr-x.  4 oracle dba     87 Mar  9  2021 32067171_Dec_2_2020_09_24_57
drwxr-xr-x.  4 oracle dba     87 Mar  9  2021 32218454_Jan_14_2021_16_24_38
drwxr-xr-x.  4 oracle dba     87 Mar  9  2021 32222571_Jan_15_2021_01_49_46
drwxr-xr-x.  4 oracle dba     87 Sep 24  2021 32876380_Jul_5_2021_04_53_50
drwxr-xr-x.  4 oracle dba     87 Sep 24  2021 32904851_Jul_20_2021_09_21_24
drwxr-xr-x.  4 oracle dba     87 Sep 24  2021 32916816_Jul_19_2021_01_56_39
drwxr-xr-x.  4 oracle dba     87 Feb 10  2022 33515361_Jan_13_2022_06_14_07
drwxr-xr-x.  4 oracle dba     87 Feb 10  2022 33529556_Jan_9_2022_21_15_36
drwxr-xr-x.  4 oracle dba     87 Feb 10  2022 33561310_Jan_5_2022_08_13_10
drwxr-xr-x.  4 oracle dba     87 Dec 15  2022 34086870_May_31_2022_05_49_37
drwxr-xr-x.  4 oracle dba     87 Dec 15  2022 34133642_Jul_14_2022_16_09_56
drwxr-xr-x.  4 oracle dba     87 Dec 15  2022 34160635_Jul_10_2022_21_27_08
drwxr-xr-x. 42 oracle dba   4096 Mar 14 10:10 NApply
-rw-r--r--.  1 oracle dba  87836 Mar 14 10:10 record_inventory.txt
-rw-r--r--.  1 oracle dba 190461 Mar 14 10:10 interim_inventory.txt
-rw-r--r--.  1 oracle dba  67011 Mar 14 10:18 newdirs.txt
-rw-r--r--.  1 oracle dba     92 Mar 14 10:19 LatestOPatchSession.properties
drwxr-xr-x.  4 oracle dba     87 Mar 14 10:20 34765931_Jan_27_2023_11_25_14
drwxr-xr-x.  4 oracle dba     87 Mar 14 10:20 34768559_Jan_14_2023_07_39_49
drwxr-xr-x.  4 oracle dba     87 Mar 14 10:20 34786990_Dec_6_2022_13_24_50
drwxr-xr-x. 74 oracle dba   4096 Jul 25 23:58 ..
drwx------. 28 oracle dba   4096 Aug 11 11:26 .

We see there are patches from before Covid, 4-years old. Will I ever rollback to that point? I don’t think so, everything is running well.

So I decide to give a try to the new opatch util DeleteInactivePatches option:

$ $ORACLE_HOME/OPatch/opatch util DeleteInactivePatches -silent
Oracle Interim Patch Installer version 12.2.0.1.39
Copyright (c) 2023, Oracle Corporation.  All rights reserved.


Oracle Home       : /u00/app/oracle/product/19.18.0
Central Inventory : /u00/app/OraInventory
   from           : /u00/app/oracle/product/19.18.0/oraInst.loc
OPatch version    : 12.2.0.1.39
OUI version       : 12.2.0.7.0
Log file location : /u00/app/oracle/product/19.18.0/cfgtoollogs/opatch/opatch2023-08-13_12-31-39PM_1.log

Invoking utility "deleteinactivepatches"
Inactive Patches Cleanup option provided
Delete Inactive Patches .......

***** There are 8 inactive RU patches in chain 1

***** 7 inactive patches will be deleted
-To be deleted inactive RU/BP 29585399:OCW RELEASE UPDATE 19.3.0.0.0 (29585399), installed on: Thu Apr 18 09:21:33 CEST 2019, with no overlays
-To be deleted inactive RU/BP 29850993:OCW RELEASE UPDATE 19.4.0.0.0 (29850993), installed on: Mon Jul 29 15:14:19 CEST 2019, with no overlays
-To be deleted inactive RU/BP 30489227:OCW RELEASE UPDATE 19.6.0.0.0 (30489227), installed on: Mon Feb 03 09:37:21 CET 2020, with no overlays
-To be deleted inactive RU/BP 31305087:OCW RELEASE UPDATE 19.8.0.0.0 (31305087), installed on: Tue Oct 13 13:27:46 CEST 2020, with no overlays
-To be deleted inactive RU/BP 32222571:OCW Interim patch for 32222571, installed on: Tue Mar 09 12:50:27 CET 2021, with no overlays
-To be deleted inactive RU/BP 32916816:OCW RELEASE UPDATE 19.12.0.0.0 (32916816), installed on: Fri Sep 24 11:26:21 CEST 2021, with no overlays
-To be deleted inactive RU/BP 33529556:OCW RELEASE UPDATE 19.14.0.0.0 (33529556), installed on: Thu Feb 10 14:09:40 CET 2022, with no overlays
-To be retained inactive RU/BP 34160635:OCW RELEASE UPDATE 19.16.0.0.0 (34160635), installed on: Thu Dec 15 15:13:06 CET 2022, with no overlays
-Active RU/BP 34768559:OCW RELEASE UPDATE 19.18.0.0.0 (34768559), installed on: Tue Mar 14 10:18:46 CET 2023, with no overlays

***** There are 8 inactive RU patches in chain 2

***** 7 inactive patches will be deleted
-To be deleted inactive RU/BP 29517242:Database Release Update : 19.3.0.0.190416 (29517242), installed on: Thu Apr 18 09:21:17 CEST 2019, with no overlays
-To be deleted inactive RU/BP 29834717:Database Release Update : 19.4.0.0.190716 (29834717), installed on: Mon Jul 29 15:12:44 CEST 2019, with no overlays
-To be deleted inactive RU/BP 30557433:Database Release Update : 19.6.0.0.200114 (30557433), installed on: Mon Feb 03 09:39:40 CET 2020, with no overlays
-To be deleted inactive RU/BP 31281355:Database Release Update : 19.8.0.0.200714 (31281355), installed on: Tue Oct 13 13:23:33 CEST 2020, with no overlays
-To be deleted inactive RU/BP 32218454:Database Release Update : 19.10.0.0.210119 (32218454), installed on: Tue Mar 09 12:42:54 CET 2021, with no overlays
-To be deleted inactive RU/BP 32904851:Database Release Update : 19.12.0.0.210720 (32904851), installed on: Fri Sep 24 11:17:00 CEST 2021, with no overlays
-To be deleted inactive RU/BP 33515361:Database Release Update : 19.14.0.0.220118 (33515361), installed on: Thu Feb 10 14:02:39 CET 2022, with no overlays
-To be retained inactive RU/BP 34133642:Database Release Update : 19.16.0.0.220719 (34133642), installed on: Thu Dec 15 15:07:21 CET 2022, with no overlays
-Active RU/BP 34765931:DATABASE RELEASE UPDATE : 19.18.0.0.230117 (REL-JAN230131) (34765931), installed on: Tue Mar 14 10:12:42 CET 2023, with no overlays

***** There are 6 inactive RU patches in chain 3

***** 5 inactive patches will be deleted
-To be deleted inactive RU/BP 30484981:OJVM RELEASE UPDATE: 19.6.0.0.200114 (30484981), installed on: Mon Feb 03 09:26:39 CET 2020, with no overlays
-To be deleted inactive RU/BP 31219897:OJVM RELEASE UPDATE: 19.8.0.0.200714 (31219897), installed on: Tue Oct 13 13:20:35 CEST 2020, with no overlays
-To be deleted inactive RU/BP 32067171:OJVM RELEASE UPDATE: 19.10.0.0.210119 (32067171), installed on: Tue Mar 09 12:38:35 CET 2021, with no overlays
-To be deleted inactive RU/BP 32876380:OJVM RELEASE UPDATE: 19.12.0.0.210720 (32876380), installed on: Fri Sep 24 11:10:35 CEST 2021, with no overlays
-To be deleted inactive RU/BP 33561310:OJVM RELEASE UPDATE: 19.14.0.0.220118 (33561310), installed on: Thu Feb 10 14:12:21 CET 2022, with no overlays
-To be retained inactive RU/BP 34086870:OJVM RELEASE UPDATE: 19.16.0.0.220719 (34086870), installed on: Thu Dec 15 15:05:34 CET 2022, with no overlays
-Active RU/BP 34786990:OJVM RELEASE UPDATE: 19.18.0.0.230117 (34786990), installed on: Tue Mar 14 10:19:19 CET 2023, with no overlays

Do you want to proceed? [y|n]
Y (auto-answered by -silent)
User Responded with: Y
Deleted RU/BP patch: 29585399
Deleted RU/BP patch: 29850993
Deleted RU/BP patch: 30489227
Deleted RU/BP patch: 31305087
Deleted RU/BP patch: 32222571
Deleted RU/BP patch: 32916816
Deleted RU/BP patch: 33529556
Deleted RU/BP patch: 29517242
Deleted RU/BP patch: 29834717
Deleted RU/BP patch: 30557433
Deleted RU/BP patch: 31281355
Deleted RU/BP patch: 32218454
Deleted RU/BP patch: 32904851
Deleted RU/BP patch: 33515361
Deleted RU/BP patch: 30484981
Deleted RU/BP patch: 31219897
Deleted RU/BP patch: 32067171
Deleted RU/BP patch: 32876380
Deleted RU/BP patch: 33561310

OPatch succeeded.

It took around 8 minutes to run. The main points from the log file are the follows:

[Aug 13, 2023 12:31:40 PM] [INFO]   OPatch invoked as follows: 'util DeleteInactivePatches -silent -invPtrLoc /u00/app/oracle/product/19.18.0/oraInst.loc '
...
[Aug 13, 2023 12:34:30 PM] [INFO]   Built sorted map of inactive patches in oracle home
...
[Aug 13, 2023 12:34:30 PM] [INFO]   File /u00/app/oracle/product/19.18.0/inventory/ContentsXML/comps.xml has been backed up.
[Aug 13, 2023 12:34:30 PM] [INFO]   File /u00/app/oracle/product/19.18.0/inventory/ContentsXML/oui-patch.xml has been backed up.
[Aug 13, 2023 12:34:30 PM] [INFO]   Directory /u00/app/oracle/product/19.18.0/inventory/oneoffs has been backed up.
...
[Aug 13, 2023 12:34:30 PM] [INFO]   Deleting patch 29585399 from inventory.
[Aug 13, 2023 12:34:34 PM] [INFO]   Is batchMode enable? false
[Aug 13, 2023 12:34:34 PM] [INFO]   Saving inventory after applying each patch
[Aug 13, 2023 12:34:39 PM] [INFO]   [OPSR-TIME] Loading raw inventory
[Aug 13, 2023 12:34:39 PM] [INFO]   [OPSR-MEMORY] Loaded all components from inventory. Heap memory in use: 937 (MB)
[Aug 13, 2023 12:34:39 PM] [INFO]   [OPSR-MEMORY] Loaded all one offs from inventory. Heap memory in use: 937 (MB)
[Aug 13, 2023 12:34:39 PM] [INFO]   [OPSR-TIME] Raw inventory loaded successfully
[Aug 13, 2023 12:34:39 PM] [INFO]   [OPSR-TIME] Loading cooked inventory
[Aug 13, 2023 12:34:39 PM] [INFO]   [OPSR-MEMORY] : Loading cooked one offs. Heap memory used 937 (MB)
[Aug 13, 2023 12:34:50 PM] [INFO]   [OPSR-MEMORY] : Loaded cooked oneoffs. Heap memory used : 564 (MB)
[Aug 13, 2023 12:34:50 PM] [INFO]   [OPSR-TIME] Cooked inventory loaded successfully
[Aug 13, 2023 12:34:50 PM] [INFO]   Deleting patch 29585399 from inventory is done.
[Aug 13, 2023 12:34:50 PM] [INFO]   Deleting patch /u00/app/oracle/product/19.18.0/inventory/oneoffs/29585399 in inventory/oneoffs.
[Aug 13, 2023 12:34:50 PM] [INFO]   Cannot delete as either pathToBeDeleted is empty or it does not contain .patch_storage :/u00/app/oracle/product/19.18.0/inventory/oneoffs/29585399
[Aug 13, 2023 12:34:50 PM] [INFO]   Deleting patch /u00/app/oracle/product/19.18.0/inventory/oneoffs/29585399 in inventory/oneoffs is done.
[Aug 13, 2023 12:34:50 PM] [INFO]   Deleting patch /u00/app/oracle/product/19.18.0/.patch_storage/29585399_Apr_9_2019_19_12_47 in patch storage.
[Aug 13, 2023 12:34:50 PM] [INFO]   Deleted the file "/u00/app/oracle/product/19.18.0/.patch_storage/29585399_Apr_9_2019_19_12_47/original_patch/custom/scripts/postpatch.sh"
[Aug 13, 2023 12:34:50 PM] [INFO]   Deleted the file "/u00/app/oracle/product/19.18.0/.patch_storage/29585399_Apr_9_2019_19_12_47/original_patch/custom/scripts/prepatch.sh"
[Aug 13, 2023 12:34:50 PM] [INFO]   Deleted the file "/u00/app/oracle/product/19.18.0/.patch_storage/29585399_Apr_9_2019_19_12_47/original_patch/etc/config/actions.xml"
[Aug 13, 2023 12:34:50 PM] [INFO]   Deleted the file "/u00/app/oracle/product/19.18.0/.patch_storage/29585399_Apr_9_2019_19_12_47/original_patch/etc/config/inventory.xml"
[Aug 13, 2023 12:34:50 PM] [INFO]   Deleted the file "/u00/app/oracle/product/19.18.0/.patch_storage/29585399_Apr_9_2019_19_12_47/original_patch/README.txt"
[Aug 13, 2023 12:34:50 PM] [INFO]   Deleted the file "/u00/app/oracle/product/19.18.0/.patch_storage/29585399_Apr_9_2019_19_12_47/rollback.sh"
[Aug 13, 2023 12:34:50 PM] [INFO]   Deleted the file "/u00/app/oracle/product/19.18.0/.patch_storage/29585399_Apr_9_2019_19_12_47/unchanged_files.txt"
[Aug 13, 2023 12:34:50 PM] [INFO]   Deleting patch /u00/app/oracle/product/19.18.0/.patch_storage/29585399_Apr_9_2019_19_12_47 in patch storage done.
[Aug 13, 2023 12:34:50 PM] [INFO]   Deleted RU/BP patch: 29585399
....
[Aug 13, 2023 12:39:47 PM] [INFO]   Start verifying if inactive patches got deleted successfully..
...
[Aug 13, 2023 12:39:53 PM] [INFO]   list of inactive patches after delete:34160635,34133642,34086870,
[Aug 13, 2023 12:39:53 PM] [INFO]   Verifying of delete inactive patches in DB CUP env was completed.
[Aug 13, 2023 12:39:53 PM] [INFO]   Finished verifying. The inactive patches got deleted successfully..
[Aug 13, 2023 12:39:53 PM] [INFO]   Finishing UtilSession at Sun Aug 13 12:39:53 CEST 2023

It starts by redoing the list of patches then backups up inventory files. For each patch it does the following: loads the info, deletes the patch from inventory, gives a warning about a oneoff directory not existing and deletes the patch backup files. At the end checks that all was correctly deleted and show the list of preserved inactive patches.

As result, in my example I gained 11 GB of space in this $ORACLE_HOME:

$ du -hs /u00/app/oracle/product/19.18.0
15G     /u00/app/oracle/product/19.18.0

$ du -hs /u00/app/oracle/product/19.18.0/.patch_storage
5.2G    /u00/app/oracle/product/19.18.0/.patch_storage

Running a new report takes now only 12 seconds, which finds there are no patches to be deleted:

$ time $ORACLE_HOME/OPatch/opatch util DeleteInactivePatches -report
Oracle Interim Patch Installer version 12.2.0.1.39
Copyright (c) 2023, Oracle Corporation.  All rights reserved.


Oracle Home       : /u00/app/oracle/product/19.18.0
Central Inventory : /u00/app/OraInventory
   from           : /u00/app/oracle/product/19.18.0/oraInst.loc
OPatch version    : 12.2.0.1.39
OUI version       : 12.2.0.7.0
Log file location : /u00/app/oracle/product/19.18.0/cfgtoollogs/opatch/opatch2023-08-13_12-47-39PM_1.log

Invoking utility "deleteinactivepatches"
Inactive Patches Cleanup option provided
Delete Inactive Patches .......
Warning: No inactive RU is eligible for delete. See log file for more details

OPatch succeeded.

real    0m11.304s
user    0m12.135s
sys     0m1.484s

And the contents of .patch_storage show now only the backups of the current active version (19.18 – RU Jan 2023 installed on 14.Mar) and backups of last inactive version (19.16 – RU Jul 2022 installed on 15.Dec):

$ ls -ltr /u00/app/oracle/product/19.18.0/.patch_storage

drwxr-xr-x.  4 oracle dba     87 Dec 15  2022 34086870_May_31_2022_05_49_37
drwxr-xr-x.  4 oracle dba     87 Dec 15  2022 34133642_Jul_14_2022_16_09_56
drwxr-xr-x.  4 oracle dba     87 Dec 15  2022 34160635_Jul_10_2022_21_27_08
drwxr-xr-x. 42 oracle dba   4096 Mar 14 10:10 NApply
-rw-r--r--.  1 oracle dba  87836 Mar 14 10:10 record_inventory.txt
-rw-r--r--.  1 oracle dba 190461 Mar 14 10:10 interim_inventory.txt
-rw-r--r--.  1 oracle dba  67011 Mar 14 10:18 newdirs.txt
-rw-r--r--.  1 oracle dba     92 Mar 14 10:19 LatestOPatchSession.properties
drwxr-xr-x.  4 oracle dba     87 Mar 14 10:20 34765931_Jan_27_2023_11_25_14
drwxr-xr-x.  4 oracle dba     87 Mar 14 10:20 34768559_Jan_14_2023_07_39_49
drwxr-xr-x.  4 oracle dba     87 Mar 14 10:20 34786990_Dec_6_2022_13_24_50
drwxr-xr-x.  3 oracle dba     33 Aug 13 12:34 backup_delete_inactive

My recommendation is to use this new feature opatch util DeleteInactivePatches every time after patching an Oracle Home. This means that if today I install Oracle 19.20 (Jul 2023), I will afterwards delete the backups of 19.16 files. Don’t forget to do the same on the GRID_HOME. It would even be great that it would be an option of opatch apply and opatchauto .

Leave a comment

Your email address will not be published. Required fields are marked *