Overview
When Oracle operates in the ARCHIVELOG mode, it generates a large number of log files in the specified archive log directory, and these log files are not cleaned up regularly by default. Prolonged operation can lead to log files consuming significant storage space, potentially causing Oracle to run out of disk space and fail to maintain its startup state.
Business operations may be impacted if the disk becomes full. Clean up expired archived logs regularly.
The control file of an Oracle database retains entries for archived logs even after their physical files are deleted. Ensure both the files and their entries in the control file are removed.
Preparation
Determine the location of the archive logs. The archive log paths may differ. If you are unsure where the archive logs are, you can use the command find / -name *.dbf to locate them.
Method One: Deleting Archive Logs with RMAN
Using this method, you can delete the physical files and their entries in the control file synchronously.
Viewing the Control File
Log in to Oracle Recovery Manager (RMAN).
Use the following command to enter RMAN, as shown in the following figure.
rman target /
Use the following command to view all archive log entries.
list archivelog all;
Deleting Logs Prior to a Specified Date
You can use the following command to delete archive logs from three days ago, which deletes both the physical files and their entries in the control file.
delete archivelog all completed before 'SYSDATE - 3';
Enter YES after the confirmation prompt to finish deletion.
Checking Physical File Status
Check the physical file list after deleting the files in the previous step. You can see that the physical files are deleted synchronously.
Method Two
If you have manually deleted a physical file before, you can use this method to delete its entry in the control file.
Deleting a Physical File
To delete the physical file xxxx.dbf, navigate to the location where the DBF file is stored and use the following command to delete it. Change the file name to the name of the log file you want to delete.
rm -f xxxx.dbf
Viewing the Control File
Use the following command to check the log file entries in the Oracle control file. You will find that xxxx.dbf still exists.
Log in to RMAN.
Use the following command to enter RMAN, as shown in the following figure.
rman target /
Use the following command to view all archive log entries.
list archivelog all;
Checking Consistency Between Physical Files and the Control File Content
If you have previously deleted physical files but did not remove the entries from the control file, proceed as follows.
You are advised to prioritize using the following command to check consistency between the physical files and the entries in the control file.
crosscheck archivelog all;
You can use the following command to filter expired log files after checking consistency.
list expired archivelog all;
Deleting Expired Files
You can use the following command to delete expired log files. Upon execution, you will be prompted to confirm the deletion of the identified expired files.
delete expired archivelog all;