How to Delete Trace Files in Oracle Database

  • by

Delete Trace Files

Trace files have to be controlled and cleaned regularly, otherwise your disk space will be exhausted soon or later. But cleaning trace files may become a hard work, because the trace files belongs to various logging purposes and they are scattered all over the database server, it may cost you a lot of time to find them and delete trace files.

Trace files include core dump, user dump and background dump from grid, rdbms or listener. Their filename extensions usually are *.trc, *.trm or *.log. For the alert log, it's a little different, you can delete or trim it for reducing the size of the file.

Please note that auditing files and the alert log are not included in trace files by definition, you have to find an integrated way to delete all trace logs, audit files, alert log and so on.

Here in this post, I recommend you to use ADRCI command interface to control over these trace files. It could be the best tool to do the tedious job.

List All Homes of Trace Files

As I said, there are several kinds of trace file located at various ADR homes. In this case, a RAC envrionment, I have 8 ARD homes. It will be a boring job to clean them one by one if you do not use ADRCI.

[grid@primary01 ~]$ adrci

ADRCI: Release 12.1.0.2.0 - Production on Tue Mar 7 10:42:16 2018

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

ADR base = "/u01/app/grid"
adrci> show homes
ADR Homes:
diag/rdbms/_mgmtdb/-MGMTDB
diag/asm/+asm/+ASM2
diag/clients/user_root/host_1450230238_82
diag/clients/user_grid/host_1450230238_82
diag/crs/node2/crs
diag/tnslsnr/node2/mgmtlsnr
diag/tnslsnr/node2/listener
diag/tnslsnr/node2/listener_scan1
adrci> show homepath
ADR Homes:
diag/rdbms/_mgmtdb/-MGMTDB
diag/asm/+asm/+ASM2
diag/clients/user_root/host_1450230238_82
diag/clients/user_grid/host_1450230238_82
diag/crs/node2/crs
diag/tnslsnr/node2/mgmtlsnr
diag/tnslsnr/node2/listener
diag/tnslsnr/node2/listener_scan1

Set Current Home

This step is to set current workspace for all the following commands.

adrci> set homepath diag/crs/node2/crs

Show Current Configuration

adrci> show control

ADR Home = /u01/app/grid/diag/crs/node2/crs:
*************************************************************************
ADRID                SHORTP_POLICY        LONGP_POLICY         LAST_MOD_TIME                            LAST_AUTOPRG_TIME                        LAST_MANUPRG_TIME                        ADRDIR_VERSION       ADRSCHM_VERSION      ADRSCHMV_SUMMARY     ADRALERT_VERSION     CREATE_TIME
-------------------- -------------------- -------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- -------------------- -------------------- -------------------- -------------------- ----------------------------------------
3841422557           720                  8760                 2015-08-21 16:03:18.127927 +08:00                                                 2018-03-07 10:43:49.850300 +08:00        1                    2                    82                   1                    2015-08-21 16:03:18.127927 +08:00
1 rows fetched

It displays various attributes of the ADR, including the short life (SHORTP_POLICY) and long life (LONGP_POLICY) purging policy attributes in hours.

Set Trace File Keep Time

We are going to set the policies of long life and short life trace files. They configure the keep time of crucial and non-crucial trace files repectively.

  1. SHORTP_POLICY: Number of hours after which to purge ADR contents that have a short life. Default is 720 (30 days).
  2. LONGP_POLICY: Number of hours after which to purge ADR contents that have a long life. Default is 8760 (365 days).
adrci> set control (SHORTP_POLICY = 168)
adrci> set control (LONGP_POLICY = 672)
adrci> show control

ADR Home = /u01/app/grid/diag/crs/node2/crs:
*************************************************************************
ADRID                SHORTP_POLICY        LONGP_POLICY         LAST_MOD_TIME                            LAST_AUTOPRG_TIME                        LAST_MANUPRG_TIME                        ADRDIR_VERSION       ADRSCHM_VERSION      ADRSCHMV_SUMMARY     ADRALERT_VERSION     CREATE_TIME
-------------------- -------------------- -------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- -------------------- -------------------- -------------------- -------------------- ----------------------------------------
3841422557           168                  672                  2018-03-07 10:44:29.704205 +08:00                                                 2018-03-07 10:43:49.850300 +08:00        1                    2                    82                   1                    2015-08-21 16:03:18.127927 +08:00
1 rows fetched

Which means we set the long life keep time as 28 days and the short life keep time as 7 days.

Delete Trace Files Immediately

adrci> purge -age 10080

This command can delete all trace files older than 10080 minutes (7 days) in current home immediately. You don't have to wait background processes to do the job.

I made a script to delete Oracle log files automatically, you can take a look at it and modify it for your environment.

More about ADRCI commands can be found: ADRCI Command Reference.

Leave a Reply

Your email address will not be published. Required fields are marked *