When we 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.
Run OPatch Clean-Up
The OPatch utility has its own cleanup routine.
[oracle@oracle-db-19c OPatch]$ pwd
/u01/app/oracle/product/19.3.0/dbhome_1/OPatch
[oracle@oracle-db-19c OPatch]$ $ORACLE_HOME/OPatch/opatch util cleanup
Oracle Interim Patch Installer version 12.2.0.1.17
Copyright (c) 2023, Oracle Corporation. All rights reserved.
Oracle Home : /u01/app/oracle/product/19.3.0/dbhome_1
Central Inventory : /u01/app/oraInventory
from : /u01/app/oracle/product/19.3.0/dbhome_1/oraInst.loc
OPatch version : 12.2.0.1.17
OUI version : 12.2.0.7.0
Log file location : /u01/app/oracle/product/19.3.0/dbhome_1/cfgtoollogs/opatch/opatch2023-02-15_13-42-52PM_1.log
Invoking utility "cleanup"
OPatch will clean up 'restore.sh,make.txt' files and 'scratch,backup' directories.
You will be still able to rollback patches after this cleanup.
Do you want to proceed? [y|n]
y
User Responded with: Y
Backup area for restore has been cleaned up. For a complete list of files/directories
deleted, Please refer log file.
OPatch succeeded.
[oracle@oracle-db-19c OPatch]$
This will clean up some space, but from experience it rarely picks up all the patches that can be removed.
Manual Clean-Up
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@oracle-db-19c OPatch]$ $ORACLE_HOME/OPatch/opatch lsinventory | grep -E "(^Patch.*applied)|(^Sub-patch)"
Patch 29585399 : applied on Fri Apr 19 05:21:33 HKT 2019
Patch 29517242 : applied on Fri Apr 19 05:21:17 HKT 2019
[oracle@oracle-db-19c OPatch]$
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.
[oracle@oracle-db-19c OPatch]$
[oracle@oracle-db-19c OPatch]$ cd $ORACLE_HOME/.patch_storage
[oracle@oracle-db-19c .patch_storage]$ ls -al
total 24
drwxr-xr-x. 5 oracle oinstall 188 Feb 15 13:49 .
drwxrwxr-x. 71 oracle oinstall 4096 Nov 2 15:39 ..
drwxr-xr-x. 3 oracle oinstall 74 Apr 18 2019 29517242_Apr_17_2019_23_27_10
drwxr-xr-x. 3 oracle oinstall 74 Apr 18 2019 29585399_Apr_9_2019_19_12_47
-rw-r--r--. 1 oracle oinstall 6307 Apr 18 2019 interim_inventory.txt
-rw-r--r--. 1 oracle oinstall 92 Apr 18 2019 LatestOPatchSession.properties
drwxr-xr-x. 6 oracle oinstall 122 Apr 18 2019 NApply
-rw-r--r--. 1 oracle oinstall 4975 Apr 18 2019 record_inventory.txt
[oracle@oracle-db-19c .patch_storage]$
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.
/u01/app/oracle/product/19.3.0/dbhome_1/.patch_storage
[oracle@oracle-db-19c .patch_storage]$ rm -Rf 29517242_Apr_17_2019_23_27_10
[oracle@oracle-db-19c .patch_storage]$ rm -Rf 29585399_Apr_9_2019_19_12_47
[oracle@oracle-db-19c .patch_storage]$