Delete Archive Log Older Than 5 Days in Oracle RMAN

Delete Archive Log Older Than 5 Days in Oracle RMAN

Purpose

The DELETE NOPROMPT ARCHIVELOG UNTIL TIME command removes old archive log files from your Oracle database to free up disk space and maintain storage efficiency. This RMAN (Recovery Manager) command automatically deletes archive logs that are older than a specified time period without requiring manual confirmation. Archive logs can quickly consume large amounts of disk space, making regular cleanup essential for database health and performance.

Code

1DELETE NOPROMPT ARCHIVELOG UNTIL TIME "SYSDATE-5"

Breakdown of Code

The command consists of four main components that work together:

  • DELETE - The primary RMAN command that removes physical backup files and updates repository records in the target control file
  • NOPROMPT - An option that skips the confirmation prompt and displays each item as it is deleted, making the command suitable for automated scripts
  • ARCHIVELOG - Specifies that the deletion targets archived redo log files rather than database backups or other objects
  • UNTIL TIME "SYSDATE-5" - Defines the time boundary, deleting all archive logs created more than 5 days ago from the current system date

How It Works

When you execute this command, RMAN connects to the target database and identifies all archive log files with creation timestamps older than 5 days. The command then removes these files from disk storage and updates the control file records to reflect the deletion with a status of 'D' (deleted). If you use a recovery catalog, RMAN also removes the repository records for the deleted files.

The deletion process uses all configured channels automatically. RMAN ignores any I/O errors during deletion when files are already missing from the media.

Key Points

  • No confirmation required - The NOPROMPT parameter eliminates interactive prompts, making this command ideal for scheduled maintenance scripts and cron jobs
  • Time-based deletion - Using SYSDATE-5 creates a rolling 5-day retention window that automatically adjusts each time the command runs
  • Automatic cleanup - The command handles both physical file deletion and metadata updates in a single operation
  • Safe for automation - Best suited for scripts and scheduled tasks where manual intervention is not possible

Best Practices and Insights

Always run the CROSSCHECK command before deletion to update the status of archive logs in the RMAN repository. This ensures accurate tracking of which files actually exist on disk versus what the repository shows.

Consider backing up archive logs before deletion to maintain recovery capability. You can use the command BACKUP ARCHIVELOG ALL NOT BACKED UP 1 TIMES DELETE INPUT to automatically back up and then delete archive logs in one operation.

Monitor your archive log destination to prevent it from filling up, which can cause database hangs. A common best practice is to schedule backups when disk space reaches 80% capacity.

For Data Guard environments, disk backups are only accessible to the database that created them, while tape backups are accessible to all databases in the environment. If deletion fails, you may need to connect to the specific database that created the files and use DELETE FORCE to remove the metadata.

Common Variations

You can adjust the retention period by changing the number in the SYSDATE calculation:

1-- Delete logs older than 1 day
2DELETE NOPROMPT ARCHIVELOG UNTIL TIME "SYSDATE-1"
3
4-- Delete logs older than 30 days
5DELETE NOPROMPT ARCHIVELOG UNTIL TIME "SYSDATE-30"

For more precise control, you can specify an exact date and time:

1DELETE NOPROMPT ARCHIVELOG UNTIL TIME "TO_DATE('2026-02-10 20:00:00','YYYY-MM-DD HH24:MI:SS')"

You can also delete based on sequence numbers or delete only logs that have been backed up a specific number of times.

Important Considerations

The database must be mounted or open for this command to work. RMAN must be connected to the target database with appropriate privileges.

Review your backup strategy before implementing automated archive log deletion. Ensure that you maintain sufficient archive logs for your required recovery point objective (RPO) and that all necessary logs are backed up before deletion.

For production systems, test the deletion process in a non-production environment first to verify the retention period meets your recovery requirements.

References

Posts in this series