To delete archive logs automatically on standby you should set LOG_AUTO_DEL_RETENTION_TARGET parameter. The Foreign Archive Logs in Logical Standby Database is automatically deleted by SQL Apply after the time specified in the LOG_AUTO_DEL_RETENTION_TARGET parameter.
Automatic deletion can be delayed with the DBMS_LOGSTDBY.APPLY_SET procedure.
Lets test it;
Step 1:
Query deleted logs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | [Logical - 04-03-2017 21:06:55] SQL> column file_name format a105 [Logical - 04-03-2017 21:07:05] SQL> SELECT * FROM DBA_LOGMNR_PURGED_LOG; FILE_NAME --------------------------------------------------------------------------------------------------------- /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_50_dclvkng2_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_51_dclvknft_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_52_dclvrgtp_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_53_dclvrq2c_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_54_dclwb296_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_55_dclwccow_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_56_dclxzx3n_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_57_dcly5j87_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_58_dclzsrz2_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_59_dcmlt7hy_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_60_dcmlv2sp_.arc FILE_NAME --------------------------------------------------------------------------------------------------------- /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_61_dcmlvv59_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_62_dcmlxh21_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_63_dcmodg64_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_64_dcn7xlq2_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_65_dcnh1gcs_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_66_dcnx9opj_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_67_dco4w7j7_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_68_dcocdnsl_.arc 19 rows selected. |
Step 2:
Query whether logs are deleted by the operating system.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | [oracle@logical 2017_03_03]$ pwd /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03 [oracle@logical 2017_03_03]$ ll total 205724 -rw-r----- 1 oracle oinstall 18794496 Mar 3 15:23 o1_mf_1_50_dclvkng2_.arc -rw-r----- 1 oracle oinstall 7680 Mar 3 15:23 o1_mf_1_51_dclvknft_.arc -rw-r----- 1 oracle oinstall 563200 Mar 3 15:26 o1_mf_1_52_dclvrgtp_.arc -rw-r----- 1 oracle oinstall 5120 Mar 3 15:26 o1_mf_1_53_dclvrq2c_.arc -rw-r----- 1 oracle oinstall 352256 Mar 3 15:36 o1_mf_1_54_dclwb296_.arc -rw-r----- 1 oracle oinstall 27648 Mar 3 15:36 o1_mf_1_55_dclwccow_.arc -rw-r----- 1 oracle oinstall 4408832 Mar 3 16:04 o1_mf_1_56_dclxzx3n_.arc -rw-r----- 1 oracle oinstall 148480 Mar 3 16:07 o1_mf_1_57_dcly5j87_.arc -rw-r----- 1 oracle oinstall 1494528 Mar 3 16:35 o1_mf_1_58_dclzsrz2_.arc -rw-r----- 1 oracle oinstall 39453696 Mar 3 22:00 o1_mf_1_59_dcmlt7hy_.arc -rw-r----- 1 oracle oinstall 34148864 Mar 3 22:00 o1_mf_1_60_dcmlv2sp_.arc -rw-r----- 1 oracle oinstall 39014400 Mar 3 22:00 o1_mf_1_61_dcmlvv59_.arc -rw-r----- 1 oracle oinstall 38416384 Mar 3 22:01 o1_mf_1_62_dcmlxh21_.arc -rw-r----- 1 oracle oinstall 33534976 Mar 3 22:43 o1_mf_1_63_dcmodg64_.arc [oracle@logical 2017_03_03]$ cd .. [oracle@logical primary]$ cd 2017_03_04/ [oracle@logical 2017_03_04]$ ll total 233988 -rw-r----- 1 oracle oinstall 33626624 Mar 4 04:00 o1_mf_1_64_dcn7xlq2_.arc -rw-r----- 1 oracle oinstall 37053440 Mar 4 06:01 o1_mf_1_65_dcnh1gcs_.arc -rw-r----- 1 oracle oinstall 35869696 Mar 4 10:05 o1_mf_1_66_dcnx9opj_.arc -rw-r----- 1 oracle oinstall 33534464 Mar 4 12:14 o1_mf_1_67_dco4w7j7_.arc -rw-r----- 1 oracle oinstall 35462144 Mar 4 14:05 o1_mf_1_68_dcocdnsl_.arc -rw-r----- 1 oracle oinstall 34808832 Mar 4 18:05 o1_mf_1_69_dcosh5xd_.arc -rw-r----- 1 oracle oinstall 28633088 Mar 4 21:10 o1_mf_1_70_dcp48o0w_.arc -rw-r----- 1 oracle oinstall 316416 Mar 4 21:13 o1_mf_1_71_dcp4gm6m_.arc |
Step 3:
Set the Log_Auto_Del_Retention_Target Parameter to an appropriate value, and check if the logs are automatically deleted.
1 2 3 4 5 6 7 | [Logical - 04-03-2017 21:08:12] SQL> execute dbms_logstdby.apply_set('LOG_AUTO_DEL_RETENTION_TARGET',60); PL/SQL procedure successfully completed. [Logical - 04-03-2017 21:08:31] SQL> execute dbms_logstdby.apply_set ('LOG_AUTO_DELETE','TRUE'); PL/SQL procedure successfully completed. |
Step 4:
Check if the logs are deleted.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | [Logical - 04-03-2017 21:08:47] SQL> set linesize 9000 [Logical - 04-03-2017 21:08:59] SQL> column file_name format a105 [Logical - 04-03-2017 21:09:07] SQL> SELECT * FROM DBA_LOGMNR_PURGED_LOG; FILE_NAME --------------------------------------------------------------------------------------------------------- /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_50_dclvkng2_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_51_dclvknft_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_52_dclvrgtp_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_53_dclvrq2c_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_54_dclwb296_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_55_dclwccow_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_56_dclxzx3n_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_57_dcly5j87_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_58_dclzsrz2_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_59_dcmlt7hy_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_60_dcmlv2sp_.arc FILE_NAME --------------------------------------------------------------------------------------------------------- /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_61_dcmlvv59_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_62_dcmlxh21_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_63_dcmodg64_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_64_dcn7xlq2_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_65_dcnh1gcs_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_66_dcnx9opj_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_67_dco4w7j7_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_68_dcocdnsl_.arc 19 rows selected. |
Step 5:
Check to see if the 69. Archive has been applied, which should be deleted but has not been deleted.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | [Logical - 04-03-2017 21:09:09] SQL> SELECT SEQUENCE#, THREAD#, APPLIED FROM DBA_LOGSTDBY_LOG; SEQUENCE# THREAD# APPLIED ---------- ---------- -------- 50 1 YES 51 1 YES 52 1 YES 53 1 YES 54 1 YES 55 1 YES 56 1 YES 57 1 YES 58 1 YES 59 1 YES 60 1 YES SEQUENCE# THREAD# APPLIED ---------- ---------- -------- 61 1 YES 62 1 YES 63 1 YES 64 1 YES 65 1 YES 66 1 YES 67 1 YES 68 1 YES 69 1 YES 70 1 YES 21 rows selected. |
Step 6:
Manually trigger Procedure, which will delete logs.
1 2 3 | [Logical - 04-03-2017 21:21:49] SQL> EXECUTE DBMS_LOGSTDBY.PURGE_SESSION; PL/SQL procedure successfully completed. |
Step 7:
Check if the logs are deleted.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | [Logical - 04-03-2017 21:22:18] SQL> SELECT * FROM DBA_LOGMNR_PURGED_LOG; FILE_NAME --------------------------------------------------------------------------------------------------------- /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_50_dclvkng2_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_51_dclvknft_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_52_dclvrgtp_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_53_dclvrq2c_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_54_dclwb296_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_55_dclwccow_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_56_dclxzx3n_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_57_dcly5j87_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_58_dclzsrz2_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_59_dcmlt7hy_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_60_dcmlv2sp_.arc FILE_NAME --------------------------------------------------------------------------------------------------------- /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_61_dcmlvv59_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_62_dcmlxh21_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_03/o1_mf_1_63_dcmodg64_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_64_dcn7xlq2_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_65_dcnh1gcs_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_66_dcnx9opj_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_67_dco4w7j7_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_68_dcocdnsl_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_69_dcosh5xd_.arc /u01/app/oracle/fast_recovery_area/LOGICAL/foreign_archivelog/primary/2017_03_04/o1_mf_1_70_dcp48o0w_.arc 21 rows selected. |
Step 8:
Create CRONJOB to delete Logs on the operating system side.