Oracle DBA – A lifelong learning experience

Purging ADR log and trace files automatically

Posted by John Hallas on May 13, 2009

The following script was put together by a colleague, David Sutton, and shows a way to create a script to tidy up the logs and trace files generated in 11G. Note that the purge time is in seconds and this keep s 30 days online. This is probably too many on some of our systems and this is likely to be reduced to 14 days although we will keep incident history for longer

This is called each day from cron (or it could be run from dbms_scheduler, either directly or via an OEM job) 

#!/usr/bin/ksh
#
#
#
# Description
# Shell script to interact with the ADR through ADRCI and purge ADR contents
#
# Tunables
###
LOCKFILE=/tmp/mor_adrci_purge_.lck

###

######
# Start Of Functions
#
# tidyup – common fuction called if error has occured
tidyup () {
        rm -f ${LOCKFILE}
        echo “ERROR: Purge aborted at `date` with exit code ${ERR}”
        exit ${ERR}
}

######
# End Of Functions

### Main Program

# Check user is oracle
USERID=`/usr/bin/id -u -nr`
if [ $? -ne 0 ]
then
        echo “ERROR: unable to determine uid”
        exit 99
fi
if [ “${USERID}” != “oracle” ]
then
        echo “ERROR: This script must be run as oracle”
        exit 98
fi

echo “INFO: Purge started at `date`”

# Check if lockfile exists
if [ -f ${LOCKFILE} ]
then
        echo “ERROR: Lock file already exists”
        echo ”       Purge already active or incorrectly terminated”
        echo ”       If you are sure tidy isn’t active, please remove ”
        echo ”       ${LOCKFILE}”
        exit 97
fi

# Create lock file
touch ${LOCKFILE} 2>/dev/null
if [ $? -ne 0 ]
then
        echo “ERROR: Unable to create lock file”
        exit 96
fi

# Purge ADR contents
echo “INFO: adrci purge started at `date`”
/app/oracle/product/11.1.0/db_1/bin/adrci exec=”show homes”|grep -v : | while read file_line
do
  echo “INFO: adrci purging diagnostic destination ” $file_line
  echo “INFO: purging ALERT older than 90 days ….”
  /app/oracle/product/11.1.0/db_1/bin/adrci exec=”set homepath $file_line;purge -age 129600 -type ALERT”
  echo “INFO: purging INCIDENT older than 30 days ….”
  /app/oracle/product/11.1.0/db_1/bin/adrci exec=”set homepath $file_line;purge -age 43200 -type INCIDENT”
  echo “INFO: purging TRACE older than 30 days ….”
  /app/oracle/product/11.1.0/db_1/bin/adrci exec=”set homepath $file_line;purge -age 43200 -type TRACE”
  echo “INFO: purging CDUMP older than 30 days ….”
  /app/oracle/product/11.1.0/db_1/bin/adrci exec=”set homepath $file_line;purge -age 43200 -type CDUMP”
  echo “INFO: purging HM older than 30 days ….”
  /app/oracle/product/11.1.0/db_1/bin/adrci exec=”set homepath $file_line;purge -age 43200 -type HM”
  echo “”
  echo “”
done

echo
echo “INFO: adrci purge finished at `date`”

# All completed
rm -f ${LOCKFILE}
echo “SUCC: Purge completed successfully at `date`”

exit 0

12 Responses to “Purging ADR log and trace files automatically”

  1. coskan said

    not tried yet but looks very nice to solve an upcoming common problem for ones who upgraded to 11g.

    Thank you for sharing

  2. KCee said

    11g R2: new: -type UTSCDMP, for removing cdmp_* directories

  3. Ingrid Zhu said

    the adrci purge does not purge the text format log files, such as listener.log and alert.log, do we have to manually take care of that?

  4. Rob Ford said

    Hi there,

    I love the script was wondering how your colleague handled the
    metadata, lck, stage and core files ?

    I have just upgraded to 11gr2 so am keen for any help witrh this …

    cheers, rob

  5. Murali said

    Hi,

    I am bit curious as to why the auto-purge feature of adrci was not used and the purge has to happen thru a script. Is it because of some bug / shortcomings in the auto-purge feature?

    According to the docs, set control (SHORTP_POLICY = 360) should purge the short term files like trace files older than 360hrs.

    • John Hallas said

      Thank you for that Murali,
      The short answer is that I did not mention it because I was not aware of it.
      I implemented it today on a system and will see what happens and I will update my post as necessary

      Thanks

      John

  6. Fadil Maliqi said

    Hi,
    I’m having problem to run it thorugh crontab.

    When I execute it through script, it runs without problems.

    But when it runs on crontab it shows errors below.

    Can you help?

    Content-Type: text/plain; charset=UTF-8
    Auto-Submitted: auto-generated
    X-Cron-Env:
    X-Cron-Env:
    X-Cron-Env:
    X-Cron-Env:
    X-Cron-Env:

    INFO: Purge started at Mon Dec 6 20:01:01 CET 2010
    INFO: adrci purge started at Mon Dec 6 20:01:01 CET 2010
    INFO: adrci purging diagnostic destination No ADR homes are set
    INFO: purging ALERT older than 7 days
    DIA-48447: Message 48447 not found; No message file for product=RDBMS, facility=DIA; arguments: [No]

    DIA-48494: Message 48494 not found; No message file for product=RDBMS, facility=DIA

    INFO: purging INCIDENT older than 7 days
    DIA-48447: Message 48447 not found; No message file for product=RDBMS, facility=DIA; arguments: [No]

    DIA-48494: Message 48494 not found; No message file for product=RDBMS, facility=DIA

    INFO: purging TRACE older than 7 days
    DIA-48447: Message 48447 not found; No message file for product=RDBMS, facility=DIA; arguments: [No]

    DIA-48494: Message 48494 not found; No message file for product=RDBMS, facility=DIA

    INFO: purging CDUMP older than 7 days
    DIA-48447: Message 48447 not found; No message file for product=RDBMS, facility=DIA; arguments: [No]

    DIA-48494: Message 48494 not found; No message file for product=RDBMS, facility=DIA

    INFO: purging HM older than 7 days
    DIA-48447: Message 48447 not found; No message file for product=RDBMS, facility=DIA; arguments: [No]

    DIA-48494: Message 48494 not found; No message file for product=RDBMS, facility=DIA

    • John Hallas said

      Fadil, almost certainly you will not be setting the oracle environment up correctly with the cron job but you are when running it manually.
      Check your environment when running manually andput and env command in the script and see what is missing Oracle_HOME/ Oracle_base most likely.
      John

      • Paul said

        Hey Guys, I have the same problem, tried diffferent things to solve this, e.g. env variables, su -, etc. But no success so far. Script runs fine @ cl but not via cron (error message same as mentioned above). Any clues….? regards Paul

      • John Hallas said

        That post was written 7 years ago. These days I would use ADRCI to manage purging.
        I dont think this script is needed before.
        However it will undoubtedly be the environment variables that are not set correctly. O_H, SID, path to the executables

        John

  7. Yanna said

    Do you by any chance have a version for Windows based systems

    • John Hallas said

      I dont understand the question – a version of what – ADR is available with all database versions – we dont use Oracle on windows but I thought ADR was in theer as well.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: