Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

If you do not delete archive logs periodically, the disk space will be exhausted sooner or later. Therefore, you need to configure a script to delete archive logs periodically.

As for why and how to enable archive mode! For details, see Enabling the archive mode for Oracle

Delete archive scripts in Linux:

mkdir -p /home/oracle/scripts/log
vi /home/oracle/scripts/del_arch.sh
#! /bin/bash
source ~/.bash_profile
DAY_TAG=`date +"%Y-%m-%d"`
rman target / nocatalog msglog /home/oracle/scripts/log/del_arch_$DAY_TAG.log<<EOF crosscheck archivelog all; delete noprompt archivelog until time '(sysdate-7)'; delete noprompt force archivelog until time 'SYSDATE-10'; EOF

# # write crontab
crontab -e
# 00 07 * * * /home/oracle/scripts/del_arch.sh
Copy the code

Delete archive scripts in Windows:

The editordel_arch.batScript:

@echo off
set ORACLE_SID=orcl
set "Filename = del_arch_task_log_ % date: date: ~ 0, 4% % % % ~ 5, 2 date: ~ 8, 2%. The log"
(
echo.
echo ====================cleaning  %date% %time%  =========================
echo.
rman target / cmdfile=G:\scripts\del_arch.sql
echo.
echo =====================  finish %date% %time%  =========================
echo.
)>>G:\scripts\%filename% 2>&1<nul
Copy the code

The editordel_arch.sqlScript:

run{
 crosscheck archivelog all;
 delete noprompt archivelog until time 'sysdate-1/2';
 delete noprompt force archivelog until time 'SYSDATE-1';
}
Copy the code

📢 Note: Please modify the directory location in the script according to the actual situation.


This is the end of sharing ~

If you think the article is helpful to you, please like it, favorites it, pay attention to it, comment on it, and support it four times with one button. Your support is the biggest motivation for my creation.

❤️ technical exchange can follow the public number: Lucifer think twice before you do ❤️