UPDATE: Several script bugs brought to my attention by a comment posted below have been fixed. The script should now be compatible with Linux and Solaris. Please let me know if any additional bugs are identified.

Every running Oracle installation has several directories and files that need to be rotated and/or purged. Surprisingly, or not, Oracle has not included this basic maintenance in their software. I have come across the oraclean utility in the past, but the script does not do everything I need.

To achieve what I required, I recently hacked together a single script that does the following things:

Cleans audit_dump_dest.

Cleans background_dump_dest.

Cleans core_dump_dest.

Cleans user_dump_dest.

Cleans Oracle Clusterware log files.

Rotates and purges alert log files.

Rotates and purges listener log files.

The script has been tested on Solaris 9 and 10 with Oracle database versions 9i and 10g. It has also been tested with Oracle Clusterware and ASM 11g. The script can be scheduled on each server having one or more Oracle homes installed, and it will clean all of them up using the retention policy specified. The limitation is that log file retention is specified per server, not per instance. However, I find that placing a single crontab entry on each database server is easier than setting up separate log purge processes for each one.

The script finds all unique Oracle Homes listed in the oratab file and retrieves the list of running Oracle instances and listeners. Once the script knows that information, it rotates and cleans the trace, dump, and log files.

Usage: cleanhouse.sh -d DAYS [-a DAYS] [-b DAYS] [-c DAYS] [-n DAYS] [-r DAYS] [-u DAYS] [-t] [-h]
-d = Mandatory default number of days to keep log files that are not explicitly passed as parameters.
-a = Optional number of days to keep audit logs.
-b = Optional number of days to keep background dumps.
-c = Optional number of days to keep core dumps.
-n = Optional number of days to keep network log files.
-r = Optional number of days to keep clusterware log files.
-u = Optional number of days to keep user dumps.
-h = Optional help mode.
-t = Optional test mode. Does not delete any files.

23 Responses

thanks a lot for this little gem, this is exactly what I was looking for. How can Oracle ship a product without something equivalent is beyond me. I heard as a joke that the overall goal was to keep the DBAs busy and clear of risks of unemployment, but was it really a joke ?

I would suggest a few modifications on the current version of the script though. Some of the errors I got are probably due to discrepancies between Solaris and Linux bash.

1 – the command find $DIR/*.trc might fail in case there are a large number of files to clean, because the *.trc is processed by the shell and can end up in a ‘argument list too long’ error. The more correct syntax is

find $DIR -name ‘*.trc’

2 – The ‘ps -ef -o args’ bombs out on my Redhat distrib with a ‘bad syntax’ message (the -f “full” format clause conflicts with the -o args), I had to replace it by :

ps h -C oracle -o args | grep pmon
ps h -C tnslsnr -o args

which looks more correct and avoid to ‘grep -v ‘ etc.

3 – Also I had to add double quotes on many lines as such
if [ -z “$1″ ]
to avoid some ‘too many arguments’ errors when $1 contains spaces.

4 – I also to add spaces ro the expression members :
x = `expr $x + 1`
which could also be written
x = $(( x + 1))

5 – However you might want to entirely replace the f_getuniq function by something more concise like

Can you please modify the script with your recommendations and send it to me via email. I am using Oracle 10g on Solaris 5.10. I am not at all good in shell scripting but thats a lot to Shad for his great effort. It is great help if you can send me the script via email.

Script is working fine for ORACLE_HOME, ASM_HOME but is not working for CRS_ORACLE_HOME. Instead it is locating the CRS logs from RDBMS ORACLE_HOME. Please advise if I need to set the CRS_ORACLE_HOME any where.

very nice script.
what unix user privileges are required for the cleanup os user. Due to default oracle umask of 022 we get permission denied errors. then we also get the following error:
TNS-01190: The user is not authorized to execute the requested listener command

I believe the script available for download was written for systems running all Oracle instances under a single user. I do have a version that accounts for different “oracle” users, and I’ll try to upload it sometime this week.

In Oracle11g Rel1 onward, oracle interally manges this using ADRCI..Infact there is no parameter called background/user/core_dump_dest..Instead it has combined all these together into a new parameter called diagnostic_dest..which is set to ORACLE_BASE by default.

Downloaded your script some days ago and it runs like a charm on HP-UX 11.31 with oracle 11gR2.. Did need to make some changes however to get it running. Had to replace the part ” ps -e -o args ” into ” ps -ef | awk ‘{print substr($0,49,length($0))}’ “.
Here are the changes in your code:

Subscribe

About Rich Technologies

My name is Shad Rich. I currently live in Seattle and work as an Oracle Apps DBA consultant for Shadandy, LLC, a small company I co-own. I try to keep up with Oracle E-Business Suite topics as best I can. As I learn new or useful things, I will try to post them on this […]more →