8i | 9i | 10g | 11g | 12c | 13c | 18c | 19c | 21c | 23c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux
Clean-Up the '.patch_storage' Directory
When we inline patch the database using the OPatch utility, patches are stored in the "$ORACLE_HOME/.patch_storage" directory. Over time old patches can represent a large amount of wasted space. This article demonstrates how to clean up wasted storage associated with old database patches.
Delete Inactive Patches (OPatch 12.2.0.1.37+)
From version 12.2.0.1.37 (April 2023) onward, OPatch includes a proper clean up for inactive patches.
We check we are on a suitable version of OPatch.
$ cd $ORACLE_HOME/OPatch $ ./opatch version redinactivepatches OPatch Version: 12.2.0.1.37 OPatch succeeded. $
We list inactive patches using the following command.
$ cd $ORACLE_HOME/OPatch $ ./opatch util listorderedinactivepatches
We delete all but the latest inactive patches using the following command. One inactive patch remains, to allow the current patch to be rolled back.
$ cd $ORACLE_HOME/OPatch $ ./opatch util deleteinactivepatches
The full documentation for this features is available from this MOS note.
Run OPatch Clean-Up
The OPatch utility has its own cleanup routine.
$ORACLE_HOME/OPatch/opatch util cleanup
This will clean up some space, but from experience it rarely picks up all the patches that can be removed.
Manual Clean-Up
Only use this method if you can't use the Delete Inactive Patches (OPatch 12.2.0.1.37+) method.
If you need to clean up more space, then consider doing the following.
We need to make sure we don't delete any patches that are currently applied to the database. We can do this by checking the output of the opatch lsinventory
command as follows.
$ORACLE_HOME/OPatch/opatch lsinventory | grep -E "(^Patch.*applied)|(^Sub-patch)" Patch 33561310 : applied on Fri Jan 28 05:21:35 GMT 2022 Patch 33515361 : applied on Fri Jan 28 05:15:00 GMT 2022 Patch 29585399 : applied on Thu Apr 18 08:21:33 BST 2019 $
We can see we have three patches applied. Now let's check the contents of the ".patch_storage" directory. We can see we have 14 patches stored there.
cd $ORACLE_HOME/.patch_storage $ ls -al total 212 drwxr-xr-x. 17 oracle oinstall 4096 Mar 2 07:20 . drwxr-xr-x. 72 oracle oinstall 4096 Mar 1 16:00 .. drwxr-xr-x. 3 oracle oinstall 4096 Apr 18 2019 29517242_Apr_17_2019_23_27_10 drwxr-xr-x. 3 oracle oinstall 4096 Apr 18 2019 29585399_Apr_9_2019_19_12_47 drwxr-xr-x. 4 oracle oinstall 4096 Dec 11 2020 31668882_Sep_14_2020_06_32_18 drwxr-xr-x. 4 oracle oinstall 4096 Dec 11 2020 31771877_Oct_7_2020_21_34_19 drwxr-xr-x. 4 oracle oinstall 4096 Jan 25 2021 32067171_Dec_2_2020_09_24_57 drwxr-xr-x. 4 oracle oinstall 4096 Jan 25 2021 32218454_Jan_14_2021_16_24_38 drwxr-xr-x. 4 oracle oinstall 4096 Apr 27 2021 32399816_Mar_9_2021_06_16_02 drwxr-xr-x. 4 oracle oinstall 4096 Apr 27 2021 32545013_Apr_16_2021_07_40_05 drwxr-xr-x. 4 oracle oinstall 4096 Aug 2 2021 32876380_Jul_5_2021_04_53_50 drwxr-xr-x. 4 oracle oinstall 4096 Aug 2 2021 32904851_Jul_20_2021_09_21_24 drwxr-xr-x. 4 oracle oinstall 4096 Oct 26 12:50 33192694_Sep_14_2021_16_48_27 drwxr-xr-x. 4 oracle oinstall 4096 Oct 26 12:45 33192793_Oct_15_2021_07_09_52 drwxr-xr-x. 4 oracle oinstall 4096 Jan 28 05:16 33515361_Jan_13_2022_06_14_07 drwxr-xr-x. 4 oracle oinstall 4096 Jan 28 05:22 33561310_Jan_5_2022_08_13_10 -rw-r--r--. 1 oracle oinstall 65515 Jan 28 05:21 interim_inventory.txt -rw-r--r--. 1 oracle oinstall 92 Jan 28 05:21 LatestOPatchSession.properties drwxr-xr-x. 18 oracle oinstall 4096 Jan 28 05:21 NApply -rw-r--r--. 1 oracle oinstall 9666 Jan 28 05:16 newdirs.txt -rw-r--r--. 1 oracle oinstall 65103 Jan 28 05:21 record_inventory.txt $
It is safe to remove any patch directories that are not part of the initial list from OPatch. In this case that would be the following directories.
rm -Rf 29517242_Apr_17_2019_23_27_10 rm -Rf 31668882_Sep_14_2020_06_32_18 rm -Rf 31771877_Oct_7_2020_21_34_19 rm -Rf 32067171_Dec_2_2020_09_24_57 rm -Rf 32218454_Jan_14_2021_16_24_38 rm -Rf 32399816_Mar_9_2021_06_16_02 rm -Rf 32545013_Apr_16_2021_07_40_05 rm -Rf 32876380_Jul_5_2021_04_53_50 rm -Rf 32904851_Jul_20_2021_09_21_24 rm -Rf 33192694_Sep_14_2021_16_48_27 rm -Rf 33192793_Oct_15_2021_07_09_52
The amount of space saved will vary, but in this case it was 13G.
Hope this helps. Regards Tim...