Wednesday, March 16, 2016

Opatch util Cleanup and .patch_storage

During a recent PSU apply it was noticed that grid home has grown to a considerable size.
du -sh grid4
16G     grid4
Out of the 16GB majority of space was consumed by the .patch_storage directory
du -sh grid4/.patch_storage
9.4G    grid4/.patch_storage
.patch_storage could be described loosely as the directory where opatch copies backup files during patch application. In case of rollback backup files from .patch_storage are copied to their original location.
In earlier versions (10g, 11gR1) optach util cleanup would remove older backup that are not needed for rollback and reduce the size of the .patch_storage. However in this case running this command didn't result in any reduction of the .patch_storage.
opatch util cleanup
Oracle Interim Patch Installer version 11.2.0.3.6
Copyright (c) 2013, Oracle Corporation.  All rights reserved.


Oracle Home       : /opt/app/11.2.0/grid4
Central Inventory : /opt/app/oraInventory
   from           : /opt/app/11.2.0/grid4/oraInst.loc
OPatch version    : 11.2.0.3.6
OUI version       : 11.2.0.4.0
Log file location : /opt/app/11.2.0/grid4/cfgtoollogs/opatch/opatch2016-03-09_15-20-16PM_1.log

Invoking utility "cleanup"
OPatch will clean up 'restore.sh,make.txt' files and 'rac,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
Size of directory "/opt/app/11.2.0/grid4/.patch_storage" before cleanup is 10031648985 bytes.
Size of directory "/opt/app/11.2.0/grid4/.patch_storage" after cleanup is 10031648985 bytes.

UtilSession: Backup area for restore has been cleaned up. For a complete list of files/directories
deleted, Please refer log file.

OPatch succeeded.
Looking inside the .patch_storage it could be seen that some of the directories and files were created as a result of earlier PSU application far back as two years ago. The list below shows the size of the sub directories inside .patch_storage and the patch that resulted in creating this backup directory. Read 1641136.1 for GI PSU supplemental read which has all the patches released for GI 11.2.0.4
14M     17478514_Dec_6_2013_04_22_19  -  Sub-patch  17478514; "Database Patch Set Update : 11.2.0.4.1 (17478514)"
33M     18031668_Feb_20_2014_05_15_58 -  Sub-patch  18031668; "Database Patch Set Update : 11.2.0.4.2 (18031668)"
791M    18031731_Mar_17_2014_06_35_22 -  Patch description:  "ACFS Patch Set Update : 11.2.0.4.2 (18031731)"
555M    18031740_Mar_19_2014_09_06_37 -  Patch description:  "OCW Patch Set Update : 11.2.0.4.2 (18031740)"
28M     18522509_Jun_30_2014_08_14_42 -  Sub-patch  18522509; "Database Patch Set Update : 11.2.0.4.3 (18522509)"
791M    18522514_May_6_2014_01_05_19  -  Patch description:  "ACFS Patch Set Update : 11.2.0.4.3 (18522514)"
555M    18522515_Jun_16_2014_08_05_14 -  Patch description:  "OCW Patch Set Update : 11.2.0.4.3 (18522515)"
555M    19121549_Oct_6_2014_03_27_01  -  Patch description:  "OCW Patch Set Update : 11.2.0.4.4 (19121549)"
30M     19121551_Oct_6_2014_10_07_57  -  Sub-patch  19121551; "Database Patch Set Update : 11.2.0.4.4 (19121551)"
791M    19121552_Oct_6_2014_03_48_39  -  Patch description:  "ACFS Patch Set Update : 11.2.0.4.4 (19121552)"
791M    19769469_Nov_13_2014_04_37_23 -  Patch description:  "ACFS Patch Set Update : 11.2.0.4.5 (19769469)"
555M    19769476_Dec_3_2014_02_08_05  -  Patch description:  "OCW Patch Set Update : 11.2.0.4.5 (19769476)"
33M     19769489_Dec_28_2014_21_22_44 -  Sub-patch  19769489; "Database Patch Set Update : 11.2.0.4.5 (19769489)"
1.7M    19852360_Oct_20_2014_08_17_43 -  Patch  19852360     : applied on Thu Jan 22 17:08:25 GMT 2015
40M     20299013_Mar_4_2015_02_27_44  -  Sub-patch  20299013; "Database Patch Set Update : 11.2.0.4.6 (20299013)"
791M    20299019_Mar_27_2015_15_26_30 -  Patch description:  "ACFS Patch Set Update : 11.2.0.4.6/7 (20299019)"
4.0M    20760982_Jun_4_2015_00_23_20  -  Sub-patch  20760982; "Database Patch Set Update : 11.2.0.4.7 (20760982)"
548M    20831122_Jul_1_2015_06_26_45  -  Patch description:  "OCW Patch Set Update : 11.2.0.4.7 (20831122)"
796K    21352635_Sep_1_2015_07_49_44  -  Patch description:  "Database Patch Set Update : 11.2.0.4.8 (21352635)"
791M    21352642_Sep_3_2015_00_03_11  -  Patch description:  "ACFS Patch Set Update : 11.2.0.4.8 (21352642)"
548M    21352649_Sep_2_2015_23_43_49  -  Patch description:  "OCW Patch Set Update : 11.2.0.4.8 (21352649)"
17M     21948347_Dec_14_2015_03_31_48 -  Patch description:  "Database Patch Set Update : 11.2.0.4.160119 (21948347)" 
548M    21948348_Dec_13_2015_23_42_28 -  Patch description:  "OCW Patch Set Update : 11.2.0.4.160119 (21948348)"
791M    21948355_Nov_18_2015_00_55_35 -  Patch description:  "ACFS Patch Set Update : 11.2.0.4.160119 (21948355)"
From this it seems .patch_storage always accumulate new backups and never expire any. When asked Oracle via a SR it was confirmed that due to new composite patching mechanism introduced in 11.2, .patch_storage will keep on growing as some of the rollback files would have to come from earlier backups. Therefore it is not possible to delete any files in .patch_storage unless rollback is not expected (and even then it's not advised. read 403218.1).


It seems only time that opatch util Cleanup does any cleaning is during patch application itself. Following from the opatch log
[Mar 9, 2016 3:02:35 PM]     OPatch will clean up 'restore.sh,make.txt' files and 'rac,scratch,backup' directories.
                             You will be still able to rollback patches after this cleanup.
                             Do you want to proceed? [y|n]
[Mar 9, 2016 3:02:38 PM]     Y (auto-answered by -silent)
[Mar 9, 2016 3:02:38 PM]     User Responded with: Y
[Mar 9, 2016 3:02:39 PM]     Size of directory "/opt/app/11.2.0/grid4/.patch_storage" before cleanup is 10243859708 bytes.
[Mar 9, 2016 3:02:39 PM]     Deleting the directory "/opt/app/11.2.0/grid4/.patch_storage/21948348_Dec_13_2015_23_42_28/backup"
...
[Mar 9, 2016 3:02:39 PM]     Deleted the file "/opt/app/11.2.0/grid4/.patch_storage/21948348_Dec_13_2015_23_42_28/rac/mode.txt"
[Mar 9, 2016 3:02:39 PM]     Deleted the file "/opt/app/11.2.0/grid4/.patch_storage/21948348_Dec_13_2015_23_42_28/rac/make_cmds.txt"
[Mar 9, 2016 3:02:39 PM]     Deleted the file "/opt/app/11.2.0/grid4/.patch_storage/21948348_Dec_13_2015_23_42_28/rac/remote_cmds_21948348.txt"
...
[Mar 9, 2016 3:02:40 PM]     Size of directory "/opt/app/11.2.0/grid4/.patch_storage" after cleanup is 9203930259 bytes.
[Mar 9, 2016 3:02:40 PM]     UtilSession: Backup area for restore has been cleaned up. For a complete list of files/directories
                             deleted, Please refer log file.
In this case where the GI home has all the 11.2.0.4 PSU applied over a 2 year period has resulted in .patch_storage size of 10GB, on a 12.1.0.2 single instance environment applying GI PSU 12.1.0.2.2 - 12.1.0.2.160119 has resulted in a .patch_storage of 6.1G. So it's expected that throughout the life span of the database the .patch_storage (for both GI home and Oracle home) could grow larger than the minimum storage requirement listed for GI and Oracle home and installation locations must be sized with this growth in mind.

Useful metalink notes
Can You Delete $ORACLE_HOME/.patch_storage Directory ? [ID 403218.1]
How To Avoid Disk Full Issues Because OPatch Backups Take Big Amount Of Disk Space. [ID 550522.1]
Oracle Grid Infrastructure 11.2.0.4.x Patch Set Update SUPPLEMENTAL README [ID 1641136.1]