Sunday, December 6, 2020

Cleanup Logs on Oracle RAC 12c+

 The following technical steps illustrate the cleanup of Oracle logs on Oracle Cluster system (Grid Infrastructure 12c and above).

Before actioning these steps, make sure that logs are no more required for troubleshooting errors neither required for auditing purposes.

Cleanup Database related logs:

The following commands should be executed against each database installed on the host replacing "orcl" with the actual database/instance name, and "racnode1" with the actual hostname.

Cleaning up database related logs can be done by executing the following command from ADRCI:

# adrci

adrci> show home
ADR Homes:
diag/rdbms/orcl/orcl1
diag/asm/+asm/+ASM1
diag/crs/racnode1/crs
diag/tnslsnr/racnode1/asmnet1lsnr_asm
diag/tnslsnr/racnode1/listener_scan1
diag/tnslsnr/racnode1/listener
diag/tnslsnr/racnode1/listener_scan3
diag/tnslsnr/racnode1/listener_scan2

adrci> set home diag/rdbms/orcl/orcl1
adrci> purge -age 0 -type ALERT
adrci> purge -age 0 -type INCIDENT
adrci> purge -age 0 -type TRACE
adrci> purge -age 0 -type LOG
adrci> purge -age 0 -type CDUMP
adrci> purge -age 0 -type UTSCDMP
adrci> purge -age 0 -type HM

Note: -age 0 means; remove all logs except the ones created in the recent hour, you can replace 0 with the number of hours back you want to keep logs.

This will cleanup the logs under the following directories:

SELECT name, value FROM v$diag_info where VALUE like '%rdbms%';

NAME                  VALUE
--------------------- -------------------------------------------
ADR Home              /u01/oracle/diag/rdbms/orcl/orcl1
Diag Trace              /u01/oracle/diag/rdbms/orcl/orcl1/trace
Diag Alert               /u01/oracle/diag/rdbms/orcl/orcl1/alert
Diag Incident         /u01/oracle/diag/rdbms/orcl/orcl1/incident
Diag Cdump           /u01/oracle/diag/rdbms/orcl/orcl1/cdump
Health Monitor      /u01/oracle/diag/rdbms/orcl/orcl1/hm
Default Trace File  /u01/oracle/diag/rdbms/orcl/orcl1/trace/orcl1_ora_31270.trc


Or you can manually remove the logs as follows:

# cd /u01/oracle/diag/rdbms/orcl/orcl1/alert; du -sh .
# rm -f log_*.xml; ls -ltrh

# cd /u01/oracle/diag/rdbms/orcl/orcl1/trace; du -sh .
# rm -f *.trm *.trc; ls -ltrh

# cd /u01/oracle/diag/rdbms/orcl/orcl1/cdump; du -sh .
# rm -rf *; ls -ltrh

# cd /u01/oracle/diag/rdbms/orcl/orcl1/incident; du -sh .
# rm -rf cdmp_*; rm -rf incdir_*; du -sh .

For audit logs, you have to delete them manually, but you have to perform the following workaround to avoid slowing down the DB during this activity:

# cd /u01/oracle/admin/orcl;ls -rtlh; du -sh *
# mv adump adump_old; mkdir adump; chmod o-rwx adump; ls -rtlh
# rm -rf adump_old

 

Cleanup ASM related logs:

Using ADRCI

adrci> set home diag/asm/+asm/+ASM1
adrci> purge -age 0 -type ALERT
adrci> purge -age 0 -type INCIDENT
adrci> purge -age 0 -type TRACE

For ASM audit logs, you have to delete them manually, using the same technique we used for cleaning up database audit logs to avoid performance degradation:

# cd /u01/grid/12.2.0.3/rdbms/audit; ls -rtlh; du -sh *
# mv adump adump_old; mkdir adump; chmod o-rwx adump; ls -rtlh
# rm -rf adump_old

 

Cleanup Grid Infrastructure related logs:

First, start with cleaning up listeners' logs

Using ADRCI:

adrci> show home
ADR Homes:
diag/rdbms/orcl/orcl1
diag/asm/+asm/+ASM1
diag/crs/racnode1/crs
diag/tnslsnr/racnode1/asmnet1lsnr_asm
diag/tnslsnr/racnode1/listener_scan1
diag/tnslsnr/racnode1/listener
diag/tnslsnr/racnode1/listener_scan3
diag/tnslsnr/racnode1/listener_scan2

adrci> set home diag/tnslsnr/racnode1/asmnet1lsnr_asm
adrci> purge -age 0 -type ALERT
adrci> purge -age 0 -type INCIDENT
adrci> purge -age 0 -type TRACE

adrci> set home diag/tnslsnr/racnode1/listener
adrci> purge -age 0 -type ALERT
adrci> purge -age 0 -type INCIDENT
adrci> purge -age 0 -type TRACE

adrci> set home diag/tnslsnr/racnode1/listener_scan1
adrci> purge -age 0 -type ALERT
adrci> purge -age 0 -type INCIDENT
adrci> purge -age 0 -type TRACE

adrci> set home diag/tnslsnr/racnode1/listener_scan2
adrci> purge -age 0 -type ALERT
adrci> purge -age 0 -type INCIDENT
adrci> purge -age 0 -type TRACE

adrci> set home diag/tnslsnr/racnode1/listener_scan3
adrci> purge -age 0 -type ALERT
adrci> purge -age 0 -type INCIDENT
adrci> purge -age 0 -type TRACE

Or instead of using ADRCI, you can cleanup the logs manually as follows:

# cd /u01/oracle/diag/tnslsnr/racnode1/listener/alert; ls -rtlh; du -sh .
# rm -f log_*.xml; ls -ltrh

# cd /u01/oracle/diag/tnslsnr/racnode1/listener/trace; ls -rtlh; du -sh .
# rm -f listener_*; ls -ltrh

# cd /u01/oracle/diag/tnslsnr/racnode1/listener_scan1/alert; ls -rtlh; du -sh .
# rm -f log_*.xml; ls -ltrh

# cd /u01/oracle/diag/tnslsnr/racnode1/listener_scan1/trace; ls -rtlh; du -sh .
# rm -f  listener_scan1_*.log; ls -ltrh

# cd /u01/oracle/diag/tnslsnr/racnode1/listener_scan2/alert; ls -rtlh; du -sh .
# rm -f log_*.xml; ls -ltrh

# cd /u01/oracle/diag/tnslsnr/racnode1/listener_scan2/trace; ls -rtlh; du -sh .
# rm -f  listener_scan2_*.log; ls -ltrh

# cd /u01/oracle/diag/tnslsnr/racnode1/listener_scan3/alert; ls -rtlh; du -sh .
# rm -f log_*.xml; ls -ltrh

# cd /u01/oracle/diag/tnslsnr/racnode1/listener_scan3/trace; ls -rtlh; du -sh .
# rm -f  listener_scan2_*.log; ls -ltrh
 

Second, cleaning up clusterware logs:

Using ADRCI:

adrci> set home diag/crs/racnode1/crs

adrci> purge -age 0 -type ALERT
adrci> purge -age 0 -type INCIDENT
adrci> purge -age 0 -type TRACE
adrci> purge -age 0 -type LOG
adrci> purge -age 0 -type CDUMP

Or manually cleanup the clusterware logs:

# cd /u01/oracle/diag/crs/racnode1/crs/alert; du -sh .
# rm -f log_*.xml; ls -ltrh

# cd /u01/oracle/diag/crs/racnode1/crs/trace; du -sh .
# rm -f *.trm *.trc; ls -ltrh

# cd /u01/oracle/diag/crs/racnode1/crs/cdump; du -sh .
# rm -rf *; ls -ltrh

# cd /u01/oracle/crsdata/racnode1/trace/chad; du -sh .
# rm -f ochad.trc.{1..9}; ls -ltrh

Follow the same steps on the other RAC nodes.

Tools to help you out:

Cleanup Oracle logs script

No comments:

Post a Comment