The Specific Method of oracle Automatically Cleaning archivelog Files
- 2021-09-20 21:53:11
- OfStack
1. Log on to the server and create rman script to automatically delete the archived log two days ago
[oracle@108 ~]$ cat > > del_ora_log.rman < < EOF
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt force archivelog until time 'sysdate-2'; --Delete archivelog two days ago
exit;
EOF
2. Manually perform log cleanup
[oracle@108 ~]$ rman target/ cmdfile=/home/oracle/del_ora_log.rman msglog=/home/oracle/del_ora_log.rman.log
3. Add scripts to system timer tasks
Note: When the task is executed, the environment variable cannot be applied, which leads to the successful execution of rman command. You can put the environment variable and command into a script, so that there is no problem in execution.
Shell code
PATH=$PATH:$HOME/bin
export PATH
export ORACLE_BASE=/home/oracle/app
export ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=ORCL
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:/usr/local/lib
rman target/ cmdfile=/home/oracle/del_ora_log.rman msglog=/home/oracle/del_ora_log.rman.log > > /home/oracle/rman.log 2 > & 1
[oracle@108 ~]$ crontab -e
13 * * * * /home/oracle/del_ora_log.sh > > del_ora_log.log 2 > & 1
4. Some tables insert data frequently but the data is not important, so log can be removed.
alter table < tablename > NOLOGGING;
[oracle@108 ~]$ cat > > del_ora_log.rman < < EOF
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt force archivelog until time 'sysdate-2'; --Delete archivelog two days ago
exit;
EOF
2. Manually perform log cleanup
[oracle@108 ~]$ rman target/ cmdfile=/home/oracle/del_ora_log.rman msglog=/home/oracle/del_ora_log.rman.log
3. Add scripts to system timer tasks
Note: When the task is executed, the environment variable cannot be applied, which leads to the successful execution of rman command. You can put the environment variable and command into a script, so that there is no problem in execution.
Shell code
PATH=$PATH:$HOME/bin
export PATH
export ORACLE_BASE=/home/oracle/app
export ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=ORCL
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:/usr/local/lib
rman target/ cmdfile=/home/oracle/del_ora_log.rman msglog=/home/oracle/del_ora_log.rman.log > > /home/oracle/rman.log 2 > & 1
[oracle@108 ~]$ crontab -e
13 * * * * /home/oracle/del_ora_log.sh > > del_ora_log.log 2 > & 1
4. Some tables insert data frequently but the data is not important, so log can be removed.
alter table < tablename > NOLOGGING;