DEV Community

Cover image for PurgeLog: Oracle Logs and Traces Housekeeping
Project-42
Project-42

Posted on

PurgeLog: Oracle Logs and Traces Housekeeping

This recent post by Michael Dinh for pythian.com - HOW TO EASILY PURGE LOGS FOR GI AND DB reminded me that I have never posted anything about this great tool for housekeeping.

I actually discovered it after a customer requested more information about it, and couldn't be more grateful about it since is a very easy and powerful tool.

If you check MOS Doc 2081655.1 you will see all explained, including how to set it up and more importantly, the Script Download link purgeLogs 20201221 - Revision: 1.65

purgeLogs Doc ID 2081655.1

Something I dint see mentioned there, is that it also runs in Solaris, just in case you were wondering.

The basic configuration is quite simple, but you can add options to cleanup Audit files (both from ASM and DB) and also TFA/AHF and OSWatcher logs, which is great.

This is what I normally run in one of my Home Lab Servers (I don't normally have the boxes running for more than few hours, don't have any cronjob created for them)

[root@rac1-node1 ~]# /opt/utils/purgeLogs -orcl 7 -aud -lsnr -tfa 15 -osw 15
Enter fullscreen mode Exit fullscreen mode

This will cleanup all Oracle (DB and GI) Logs and Traces including Audit and Listener older than 7 days, and will also cleanup TFA/AHF and OSWatcher files for last 15

The Audit files period goes connected to the "-orcl" attribute, so if you want to have different periods for them, you will need a separate command, but still very easy to do.
In this example, we cleanup Oracle (DB and GI) Logs and Traces including Audit and Listener older than 15 days and then we can do a second run where we will only cleanup Oracle (DB and GI) Logs and Traces older than 7 days

/opt/utils/purgeLogs -orcl 15 -aud -lsnr 
/opt/utils/purgeLogs -orcl 7
Enter fullscreen mode Exit fullscreen mode

Let's try it out.

Let's see some of the logs/trace location to compare after the execution. See how the listener log has information from Dec 2020 and trace/audit locations have files from same time as well:

[root@rac1-node1 ~]# head /u01/app/grid/diag/tnslsnr/rac1-node1/listener/trace/listener.log
2020-12-12T13:21:51.456851+00:00
12-DEC-2020 13:21:51 * (CONNECT_DATA=(CID=(PROGRAM=)(HOST=rac1-node1.raclab.local)(USER=oracle))(COMMAND=status)(ARGUMENTS=64)(SERVICE=LISTENER)(VERSION=318767104)) * status * 0
2020-12-12T13:22:27.888635+00:00
12-DEC-2020 13:22:27 * ping * 0
12-DEC-2020 13:22:27 * (CONNECT_DATA=(CID=(PROGRAM=)(HOST=rac1-node2.raclab.local)(USER=oracle))(COMMAND=status)(ARGUMENTS=64)(SERVICE=(ADDRESS=(PROTOCOL=TCP)(HOST=rac1-node1.raclab.local)(PORT=1521)))(VERSION=318767104)) * status * 1189
TNS-01189: The listener could not authenticate the user
2020-12-12T13:22:51.461060+00:00
12-DEC-2020 13:22:51 * (CONNECT_DATA=(CID=(PROGRAM=)(HOST=rac1-node1.raclab.local)(USER=oracle))(COMMAND=status)(ARGUMENTS=64)(SERVICE=LISTENER)(VERSION=318767104)) * status * 0
2020-12-12T13:23:51.459288+00:00

[root@rac1-node1 ~]# ls -lthr /u01/app/oracle/diag/rdbms/db112/db1121/trace/*.tr* |head -5
total 29M
-rw-r----- 1 oracle oinstall  152 Dec 11 14:04 db1121_ora_10103.trm
-rw-r----- 1 oracle oinstall 2.8K Dec 11 14:04 db1121_ora_10103.trc
-rw-r----- 1 oracle oinstall   62 Dec 11 14:04 db1121_mark_10214.trm
-rw-r----- 1 oracle oinstall  912 Dec 11 14:04 db1121_mark_10214.trc

[root@rac1-node1 ~]# ls -lrth /u01/app/19.3.0/grid/rdbms/audit/ |head -5
total 12M
-rw-r----- 1 oracle oinstall  838 Dec 11 14:03 +ASM1_ora_7437_20201211140332383484588514.aud
-rw-r----- 1 oracle oinstall  899 Dec 11 14:03 +ASM1_ora_7437_20201211140346459666144005.aud
-rw-r----- 1 oracle oinstall  905 Dec 11 14:03 +ASM1_ora_7688_20201211140346542256454593.aud
-rw-r----- 1 oracle oinstall  905 Dec 11 14:03 +ASM1_ora_7770_20201211140358694624901360.aud
[root@rac1-node1 ~]#
Enter fullscreen mode Exit fullscreen mode

Let's now run the command, which in this case will cleanup anything older than 1 day (output truncated since it was too long)

[root@rac1-node1 ~]# /opt/utils/purgeLogs -orcl 1 -aud -lsnr

│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│
 purgeLogs version: 1.64
 Copyright (c) 2015-2020 Oracle and/or its affiliates.
 -------------------------------------------------------
 Author: Ruggero Citton <ruggero.citton@oracle.com>
 RAC Pack, Cloud Innovation and Solution Engineering Team
│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│

2021-01-16 13:47:10: I Cleaning up Listener logs
2021-01-16 13:47:10: I ... purging Listener logs, ORACLE_BASE is '/u01/app/grid'
2021-01-16 13:47:10: I ... purging SCAN1 Listener logs, ORACLE_BASE is '/u01/app/grid'
2021-01-16 13:47:10: I ... purging SCAN2 Listener logs, ORACLE_BASE is '/u01/app/grid'
2021-01-16 13:47:10: I ... purging SCAN3 Listener logs, ORACLE_BASE is '/u01/app/grid'
2021-01-16 13:47:10: I ... purging Management Listener logs, ORACLE_BASE is '/u01/app/grid'
2021-01-16 13:47:10: W Path /u01/app/grid/diag/tnslsnr/rac1-node1/mgmtlsnr/trace does not exist, Management Listener logs cleanup skipped...
2021-01-16 13:47:10: I ... purging ASM Listener logs, ORACLE_BASE is '/u01/app/grid'
2021-01-16 13:47:10: I GI Audit logs purge started
2021-01-16 13:47:10: I ... purging GI Audit logs under '/u01/app/19.3.0/grid/rdbms/audit' older then 1 days
[....]
2021-01-16 13:47:46: I adrci RDBMS purging diagnostic destination diag/rdbms/cdb19/cdb191
2021-01-16 13:47:46: I ... purging ALERT older than 1 days
2021-01-16 13:47:47: I ... purging INCIDENT older than 1 days
2021-01-16 13:47:47: I ... purging TRACE older than 1 days
2021-01-16 13:47:47: I ... purging CDUMP older than 1 days
2021-01-16 13:47:47: I ... purging HM older than 1 days
2021-01-16 13:47:47: I ... purging STAGE older than 1 days
2021-01-16 13:47:47: I ... purging SWEEP older than 1 days
2021-01-16 13:47:47: I ... purging UTSCDMP older than 1 days
2021-01-16 13:47:47: I Getting dbhome for 'db112'
2021-01-16 13:47:51: I adrci RDBMS purging diagnostic destination diag/rdbms/db112/db1121
2021-01-16 13:47:51: I ... purging ALERT older than 1 days
2021-01-16 13:47:51: I ... purging INCIDENT older than 1 days
[....]
2021-01-16 13:48:33: I Purging RDBMS Audit logs on '/u01/app/oracle/admin/db19/adump' older then 1 days
2021-01-16 13:48:33: I Purging RDBMS Audit logs on '/u01/app/oracle/admin/db112/adump' older then 1 days
2021-01-16 13:48:33: I Purging RDBMS Audit logs on '/u01/app/oracle/admin/cdb121/adump' older then 1 days
2021-01-16 13:48:33: S Purging completed succesfully!
[root@rac1-node1 ~]#
Enter fullscreen mode Exit fullscreen mode

See how the script truncated the listener.log file of any old records, the same that did with audit files and trace files (no trace files in that location since I didn't start the DB recently)

[root@rac1-node1 ~]# head /u01/app/grid/diag/tnslsnr/rac1-node1/listener/trace/listener.log

2021-01-16T13:47:48.094559+00:00
16-JAN-2021 13:47:48 * (CONNECT_DATA=(CID=(PROGRAM=)(HOST=rac1-node1.raclab.local)(USER=oracle))(COMMAND=status)(ARGUMENTS=64)(SERVICE=LISTENER)(VERSION=318767104)) * status * 0
2021-01-16T13:48:48.091847+00:00
16-JAN-2021 13:48:48 * (CONNECT_DATA=(CID=(PROGRAM=)(HOST=rac1-node1.raclab.local)(USER=oracle))(COMMAND=status)(ARGUMENTS=64)(SERVICE=LISTENER)(VERSION=318767104)) * status * 0
[root@rac1-node1 ~]# ls -lthr /u01/app/oracle/diag/rdbms/db112/db1121/trace/*.tr* |head -5
ls: cannot access /u01/app/oracle/diag/rdbms/db112/db1121/trace/*.tr*: No such file or directory
[root@rac1-node1 ~]#
[root@rac1-node1 ~]# ls -lrth /u01/app/19.3.0/grid/rdbms/audit/ |head -5
total 276K
-rw-r----- 1 oracle oinstall 838 Jan 16 12:10 +ASM1_ora_7207_20210116121000402108307709.aud
-rw-r----- 1 oracle oinstall 899 Jan 16 12:10 +ASM1_ora_7207_20210116121014786453494743.aud
-rw-r----- 1 oracle oinstall 905 Jan 16 12:10 +ASM1_ora_7449_20210116121014874778755693.aud
-rw-r----- 1 oracle oinstall 905 Jan 16 12:10 +ASM1_ora_7579_20210116121028185252731961.aud
[root@rac1-node1 ~]#
Enter fullscreen mode Exit fullscreen mode

To get it executed regularly, you can just add this to root cron of every host:

0 0 * * MON /opt/utils/purgeLogs -orcl 15 -aud -lsnr -tfa 15 -osw 15
Enter fullscreen mode Exit fullscreen mode

You also have a dry-run option, just in case you want to check it properly first and avoid nasty surprises

[root@rac1-node1 ~]# /opt/utils/purgeLogs -dryrun -orcl 7 -aud -lsnr -tfa 15 -osw 15

│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│
 purgeLogs version: 1.64
 Copyright (c) 2015-2020 Oracle and/or its affiliates.
 -------------------------------------------------------
 Author: Ruggero Citton <ruggero.citton@oracle.com>
 RAC Pack, Cloud Innovation and Solution Engineering Team
│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│

2021-01-16 13:15:52: I DRYRUN - Cleaning up Listener logs, ORACLE_BASE is '/u01/app/grid'
        echo "" >| /u01/app/grid/diag/tnslsnr/rac1-node1/listener/trace/listener.log
2021-01-16 13:15:52: I DRYRUN - Cleaning up SCAN1 Listener logs, ORACLE_BASE is '/u01/app/grid'
        echo "" >| /u01/app/grid/diag/tnslsnr/rac1-node1/listener_scan1/trace/listener_scan1.log
2021-01-16 13:15:52: I DRYRUN - Cleaning up SCAN2 Listener logs, ORACLE_BASE is '/u01/app/grid'
        echo "" >| /u01/app/grid/diag/tnslsnr/rac1-node1/listener_scan2/trace/listener_scan2.log
2021-01-16 13:15:52: I DRYRUN - Cleaning up SCAN3 Listener logs, ORACLE_BASE is '/u01/app/grid'
[....]
2021-01-16 13:15:52: I GI Audit logs purge started
2021-01-16 13:15:52: I DRYRUN - Purging GI Audit logs under '/u01/app/19.3.0/grid/rdbms/audit' older then 7 days
        rm /u01/app/19.3.0/grid/rdbms/audit/+ASM1_ora_28136_20201212150856457826030998.aud
        rm /u01/app/19.3.0/grid/rdbms/audit/+ASM1_ora_2857_20201212133503423553983140.aud
        rm /u01/app/19.3.0/grid/rdbms/audit/+ASM1_ora_12878_20201217133522936627859143.aud
        rm /u01/app/19.3.0/grid/rdbms/audit/+ASM1_ora_26992_20201217112131382742482339.aud
[....]
        rm /u01/app/oracle/admin/db112/adump/db1121_ora_26323_20210105140349071050143795.aud
2021-01-16 13:17:05: I DRYRUN - Purging RDBMS Audit logs on '/u01/app/oracle/admin/cdb121/adump' older than 7 days

~~~~~~~~~~~~~~~~~TFA purge started~~~~~~~~~~~~~~~~~
2021-01-16 13:17:05: I DRYRUN - Purging TFA archives older then 15 days
        /opt/oracle.ahf/tfa/bin/tfactl purge -older 15d -force
2021-01-16 13:17:05: I DRYRUN - Purging ODA OSW archives older then 15 days
2021-01-16 13:17:05: W Path /opt/oracle/oak/oswbb/archive does not exist, ODA OSW archive cleanup skipped...
2021-01-16 13:17:05: I DRYRUN - Purging ExaWatcher archives older then 15 days
2021-01-16 13:17:05: W Path /opt/oracle.ExaWatcher/archive does not exist, ExaWatcher archive cleanup skipped...
[root@rac1-node1 ~]#
Enter fullscreen mode Exit fullscreen mode

There are some issues you can find with this system, like the script deleting files from the default trace/log directories just because they are older than the period we chosen.
Won't be first time someone selected the Database Diagnostic Location to drop them some important Export or something like that :)

To show you this, I moved an old trace to a directory and just changed its name to see how the script doesn't only purge files with ".log/.trc/.trm/.aud..." extensions

[root@rac1-node1 ~]# cp -pr /u01/app/oracle/diag/rdbms/db112/db1121/trace/db1121_ora_10103.trc /tmp/test/very_important_file
[root@rac1-node1 ~]# ls -lrth /tmp/test/
total 4.0K
-rw-r----- 1 oracle oinstall 2.8K Dec 11 14:04 very_important_file
[root@rac1-node1 ~]#
Enter fullscreen mode Exit fullscreen mode

Since PurgeLog allow us to select a extra directory for cleaning up, we run the command with that option to see the results directly:

[root@rac1-node1 ~]# /opt/utils/purgeLogs -extra /tmp/test:5

│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│
 purgeLogs version: 1.64
 Copyright (c) 2015-2020 Oracle and/or its affiliates.
 -------------------------------------------------------
 Author: Ruggero Citton <ruggero.citton@oracle.com>
 RAC Pack, Cloud Innovation and Solution Engineering Team
│▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒│


~~~~~~~~~~~~~~~~~~~~~~Extra purge started~~~~~~~~~~~~~~~~~~~~~~
2021-01-16 13:56:05: I Purging files older then 5 days on user specified folder '/tmp/test'
2021-01-16 13:56:05: S Purging completed succesfully!
[root@rac1-node1 ~]#
[root@rac1-node1 ~]# ls -lrth /tmp/test/
total 0
[root@rac1-node1 ~]#
Enter fullscreen mode Exit fullscreen mode

Remember, with great power comes great responsibility
As mentioned in the Documentation, make sure you are not leaving anything that doesn't belong to the default Oracle Diagnostic Location, or you will see it disappear :)

Top comments (0)