17 May 2019

.patch_storage growing in Oracle Home

Starting with Oracle 18, the Oracle Home is growing more than expected. It appears that the .patch_storage folder is taking up quite some storage. There are notes on this on MOS and one of them is mentioning that you can also check if there are subfolders, which are of patches that are not installed (anymore). (Doc ID 550522.1)

You will see under section 3) of that note a description.

The regular opatch util cleanup does not clean all that you want it seems.

I have written the following script, which you may use at your OWN RISK.

#!/bin/sh
# cleanup the patch storage for Opatch
# not all things are cleaned, so you may want to delete old patch directories that are backed up but not installed

# parameter: $ORACLE_HOME

if [ $# -ne 1 ];then
  echo "Usage: clean_opatch_storage.sh "
  exit
else
  OH=$1
fi

# where to put the rm commands
rmscript=/tmp/rmdirs.sh
echo > $rmscript

# show size before
du -s $OH/.patch_storage

# list contents
ls -l $OH/.patch_storage

# save inventory
$OH/OPatch/opatch lsinventory > /tmp/lsinv.log
export LOG=/tmp/lsinv.log

# list folders that are of patches:
cd $OH/.patch_storage

# make a list of the patch numbers in this directory
mylist=$(find .  -mindepth 1 -maxdepth 1 -type d -name '*[0-9]*_*' -printf '%P\n' | awk '{split($0,a,"_"); print a[1]}' )

# check if those patches are in inventory log, if not remove the directory
for var1 in $mylist
do
  FOUND=$(cat $LOG | grep -w $var1  | wc -l)
  if [ $FOUND -eq 0 ]; then
    echo $var1  Not found in inventory, so this directory should go
    mydel=$(find .  -mindepth 1 -maxdepth 1 -type d -name $var1'_*' -printf '%P\n' )
    echo rm -rf $mydel >> $rmscript
  else
    echo $var1  Found in inventory, so this directory should be kept
  fi;
done

# cat the script
echo This will be done:
cat $rmscript

read -r -p "Are you sure? [y/N] " response
case "$response" in
    [yY][eE][sS]|[yY])
        chmod 740 $rmscript
        $rmscript
        ;;
    *)
        echo "Cancelled deletion!"
        ;;
esac