Purging Oracle traces with ADRCI



ADRCI is an Oracle command-line tool used to manage Oracle Database diagnostic data.

$ adrci

ADRCI: Release 12.1.0.2.0 - Production on Fri Sep 29 14:28:26 2017

Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

ADR base = "/oracle/BBDD1/saptrace"

We should set adrci_home we want to work with, in case of show control command and other is needed to work with only one ADR Home..

adrci> show home
ADR Homes:
diag/rdbms/bbdd1/BBDD1
diag/tnslsnr/hostname10p/listener_bbdd1

If we try to work without selecting one... this will hapen:
adrci> show control
DIA-48448: This command does not support multiple ADR homes

So i selected one on them:

adrci> set home diag/rdbms/bbdd1/BBDD1
adrci> show home
ADR Homes:
diag/rdbms/bbdd1/BBDD1
adrci>  show control


and now, we can see

adrci>  show control

ADR Home = /oracle/BBDD1/saptrace/diag/rdbms/bbdd1/BBDD1:
*************************************************************************
ADRID                SHORTP_POLICY        LONGP_POLICY         LAST_MOD_TIME                            LAST_AUTOPRG_TIME                        LAST_MANUPRG_TIME                        ADRDIR_VERSION       ADRSCHM_VERSION      ADRSCHMV_SUMMARY     ADRALERT_VERSION     CREATE_TIME
-------------------- -------------------- -------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- -------------------- -------------------- -------------------- -------------------- ----------------------------------------
4147224502           720                  8760                 2017-05-08 11:29:59.425712 +02:00        2017-09-26 09:11:17.904064 +02:00                                                 1                    2                    82                   1                    2017-05-08 11:29:59.425712 +02:00
1 rows fetched


SHORTP_POLICY--> Number of hours after which to purge ADR contents that have a short life, witch means: Trace files, Core dump files and Packaging information)
LONGP_POLICY--> Number of hours after which to purge ADR contents that have a long life, witch means: Incident information, Incident dumps and Alert logs

So in this example, trace files kill keep 720 hours (30 days) and alert log 8760 hours (365 days)

So as we don´t have enough free space to allocate so many trace files, we are going to modify SHORTP_POLICY and LONGP_POLICY

adrci> set control (SHORTP_POLICY = 168)
adrci> set control (LONGP_POLICY = 720)
and now configuration is:
adrci> show control

ADR Home = /oracle/BBDD1/saptrace/diag/rdbms/bbdd1/BBDD1:
*************************************************************************
ADRID                SHORTP_POLICY        LONGP_POLICY         LAST_MOD_TIME                            LAST_AUTOPRG_TIME                        LAST_MANUPRG_TIME                        ADRDIR_VERSION       ADRSCHM_VERSION      ADRSCHMV_SUMMARY     ADRALERT_VERSION     CREATE_TIME
-------------------- -------------------- -------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- -------------------- -------------------- -------------------- -------------------- ----------------------------------------
4147224502           168                  720                  2017-09-29 14:50:07.926183 +02:00        2017-09-26 09:11:17.904064 +02:00                                     

So now, oracle will retain 7 days trace files and 30 alert log.

But, maybe you want to purge files without set a purge policy, only to purge just now, because filesystem is empty, you can do
(be careful, in this case time is in nimutes, not in hours like SHORTP_POLICY or LONGP_POLICY)
adrci> purge -age 8640  -type trace
---purge trace files older that 6 days
adrci> purge -age 1440 -type alert
---purge trace files older that 1 day

But this is only half truth, because this command only works with files and not with his contents... which means that this command are going not to analyze your alert.log and clean lines older than a date. It only will delete the file if the last modification date is older that a date you said and if the file match with this mask log*.xml...


so if you rename every day the alert maintaining this mask

$ mydate=`date '+%d%m%Y_%H%M%S'`
$ mv log.xml log_${mydate}.xml
$ ls -ltr
total 14072
-rwxrwxr-x   1 oracle     oinstall   7149505 Sep 29 15:12 log_29092017_153603.xml
-rw-rw----   1 oracle     oinstall      1289 Sep 29 15:36 log.xml

$ adrci

ADRCI: Release 12.1.0.2.0 - Production on Fri Sep 29 15:37:20 2017

Copyright (c) 1982, 2014, Oracle and/or its affiliates.  All rights reserved.

ADR base = "/oracle/BBDD1/saptrace"
adrci> purge -age 3 -type alert
adrci> exit
$ ls -ltr
total 4
-rw-rw----   1 oracle     oinstall      1289 Sep 29 15:36 log.xml
You can see that after the purge execution, the only file i has in my system is log.xml.. so a workaround of this is to schedule daily in your crontab a line like this
30 0 * * * mv /your_path/log.xml /your_path/log_`date '+%d%m%Y_%H%M%S'`.xml 2>>/dev/null

And finally, i had one bad new, i try to do same with file alert_${ORACLE_SID}.log moving it to:
mv alert_${ORACLE_SID}.log alert_${ORACLE_SID}_`date '+%d%m%Y_%H%M%S'`.log
and purging it, but it did not work, so in case of alert.log i fear you should to purge it with operating system commands...
Next week, i´m going to tell you who to purge alert.log file effectively..

Comments

Popular posts from this blog

Oracle Historical Session Information with ASH >10g

Check sessions and processes limits in Oracle

Purging and archiving Oracle alert.log and listener.log