Recently, I have been playing with DG. Due to the shortage of disk resources, a policy for archiving logs is required.
I found several scripts on the Internet and found that writing is so troublesome.
Mao, So I simply wrote one, and the actual path can be modified by myself.
You can use both the master and slave databases. You can use crontab by yourself. We recommend that you stagger the time.
Note that DEST_ID is queried in advance. The following isScript deleted from the master database(You only need to change the dest_id of the standby database.) In my primary database v $ archived_log, the archive dest_id of the primary database is 1, and the standby database is dest_id = 2.
- #! /Bin/bash
-
- ########### Easy scriptByLcrash @ 2011-1-25 ############
- #For DeleteDG archive log #
- # You shoshouldModifyUSER_HOME & make sure del_dir exists #
- #AndYou can change your keepDate By ModifySQL below #
- ######################################## ##################
-
- USER_HOME =/opt/Oracle
- DEL_DIR = $ USER_HOME/del_arch
-
- Source $ USER_HOME/. bash_profile
- $ ORACLE_HOME/bin/sqlplus-S"/As sysdba"<EOF
- SetHeadingOff
- SetFeedbackOff
- Spool/opt/oracle/del_arch/del_arch.list
- Select 'Rm-rf'|Name FromV \ $ archived_log
- WhereDEST_ID = 1And SEQUENCE# <(Select Max(SEQUENCE#)FromV \ $ archived_logWhereApplied ='Yes')AndCOMPLETION_TIME <= sysdate-0;
- SpoolOff
- Exit
- EOF
-
- Cd $ DEL_DIR
- Sed-n'/Dbf/P'Del_arch.list> del_arch_do.sh
- Chmod + x del_arch_do.sh
- Source del_arch_do.sh
-
- Rm del_arch.list
- Mv {,'Date+ % Y-% m-% d-% H'} del_arch_do.sh
-
-
- Rman target/<EOF
- Crosscheck archivelogAll;
- DeleteObsolete;
- DeleteNoprompt expired archivelogAll;
- EOF
By the way:
1. When I started using uniread sqlplus, I found that it could not be moved and it was a waste of time. Later I changed it to $ ORACLE_HOME/bin/sqlplus.
Prevent replacement of other aliases
2. the SQL statement in the script is very annoying because it is too long to recognize two lines for me.
So we can wrap the where statement in another line.
Second (second) Second