Oracle RMAN clears archived logs

Source: Internet
Author: User

In the development environment and UAT environment, you often encounter the need to clear archived logs. There are many ways to solve this problem. You can use RM to clear archived logs directly, or use the find command to find matching records to clear archived logs, or write a shell script to clear the logs. In this way, Dev or UAT can be used. However, in the prod environment, we recommend that you use the Command provided by RMAN to handle the problem properly. Because the RM and find methods Delete the actual archive logs and release the space, the archive information stored in the control file is not completely cleared. It still occupies some space and cannot be cleared in time. Therefore, you need to control the file to release the space in the age out mode. This document describes how to use RMAN to clear archived logs and deploy the logs in shell scripts.

 

For more information, see
Oracle archiving logs
Oracle Control File)
Oracle online redo log file)
Delete archivelog all cannot completely delete archived logs?
Linux/Unix shell scripts call SQL and RMAN scripts
Linux/Unix shell script to clear archived log files

 

1. How to clear archived logs

A. manually delete
You can use rm or find to delete an archive. After deletion, you can use crosscheck archivelog all in RMAN to check whether the archive is invalid. The following operations are performed:
Rm-RF arch_816906485_48710.arc
Find/u02/database/gobo1/archive/-ctime + 0-delete
RMAN> crosscheck archivelog all

B. Clear Data Using RMAN
The RMAN cleanup method automatically clears the archive log files on the disk, and releases the archive information of the corresponding archive log in the control file.
You can clear archived logs based on different conditions, such as SCN, sequence, and time.
The preceding three methods can be used with clauses such as from, until, between... and so on to limit the scope. The method is flexible and variable.
The following command is used to verify the validity of archived logs, list invalid archived logs, and how to clear archived logs to list several common:
Crosscheck archivelog all; ---> verify log availability
List expired archivelog all; ---> list all invalid archive logs
Delete archivelog until sequence 16; ---> delete all archived logs whose log sequence is 16 or before 16
Delete archivelog all completed before 'sysdate-7'; ---> Delete the archived logs generated seven days earlier than the system time. Valid archived logs in the flash back area are not deleted.
Delete archivelog all completed before 'sysdate-1'; ---> same as above
Delete archivelog from time 'sysdate-1'; ---> note this command to delete the archived logs generated within one day of the system.
Delete noprompt archivelog all completed before 'sysdate'; ---> This command clears all archived logs.
Delete noprompt archivelog all; ---> same as the previous command

2. Use RMAN to clear archived logs

robin@SZDB:~> export ORACLE_SID=GOBO1robin@SZDB:~> rman target /Recovery Manager: Release 10.2.0.3.0 - Production on Thu Jul 11 17:07:00 2013Copyright (c) 1982, 2005, Oracle.  All rights reserved.connected to target database: GOBO1 (DBID=733951103)RMAN> host;robin@SZDB:~> cd /u02/database/GOBO1/archive/robin@SZDB:/u02/database/GOBO1/archive> ls      arch_816906485_1_10.arc      arch_816906485_1_12.arc  arch_816906485_1_11.arc      arch_816906485_1_13.arc      ............robin@SZDB:/u02/database/GOBO1/archive> rm -rf arch_816906485_1_10.arc arch_816906485_1_11.arc arch_816906485_1_12.arcrobin@SZDB:/u02/database/GOBO1/archive> exit;exit                                         host command complete                                                                     RMAN> crosscheck archivelog all;                 released channel: ORA_DISK_1                                                                       allocated channel: ORA_DISK_1                                                                      channel ORA_DISK_1: sid=1075 devtype=DISK                                                          archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_9.arc recid=2085 stamp=817211151 validation failed for archived log                                                                 archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_10.arc recid=2086 stamp=817250793      ..............validation succeeded for archived log                                                              archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_90.arc recid=2166 stamp=820458049Crosschecked 83 objects                    RMAN> list expired archivelog all;List of Archived Log CopiesKey     Thrd Seq     S Low Time          Name------- ---- ------- - ----------------- ----2086    1    10      X 20130604 11:05:51 /u02/database/GOBO1/archive/arch_816906485_1_10.arc2087    1    11      X 20130604 22:06:17 /u02/database/GOBO1/archive/arch_816906485_1_11.arc2088    1    12      X 20130605 19:30:53 /u02/database/GOBO1/archive/arch_816906485_1_12.arcRMAN> delete archivelog until sequence 16;released channel: ORA_DISK_1allocated channel: ORA_DISK_1channel ORA_DISK_1: sid=1075 devtype=DISKList of Archived Log CopiesKey     Thrd Seq     S Low Time          Name------- ---- ------- - ----------------- ----2084    1    8       A 20130604 09:53:17 /u02/database/GOBO1/archive/arch_816906485_1_8.arc                        .................2092    1    16      A 20130607 22:03:23 /u02/database/GOBO1/archive/arch_816906485_1_16.arcDo you really want to delete the above objects (enter YES or NO)? yes          ...............deleted archive logarchive log filename=/u02/database/GOBO1/archive/arch_816906485_1_16.arc recid=2092 stamp=817516861Deleted 9 objectsRMAN> delete archivelog all completed before 'sysdate-7';released channel: ORA_DISK_1allocated channel: ORA_DISK_1channel ORA_DISK_1: sid=1075 devtype=DISKList of Archived Log CopiesKey     Thrd Seq     S Low Time          Name------- ---- ------- - ----------------- ----2093    1    17      A 20130608 00:01:00 /u02/database/GOBO1/archive/arch_816906485_1_17.arc2094    1    18      A 20130608 18:00:17 /u02/database/GOBO1/archive/arch_816906485_1_18.arc            ...........deleted archive logarchive log filename=/u02/database/GOBO1/archive/arch_816906485_1_72.arc recid=2148 stamp=819847035Deleted 56 objects            RMAN> list copy of database archivelog all;List of Archived Log CopiesKey     Thrd Seq     S Low Time          Name------- ---- ------- - ----------------- ----2149    1    73      A 20130703 23:17:13 /u02/database/GOBO1/archive/arch_816906485_1_73.arc2150    1    74      A 20130704 22:00:19 /u02/database/GOBO1/archive/arch_816906485_1_74.arc2151    1    75      A 20130704 22:04:40 /u02/database/GOBO1/archive/arch_816906485_1_75.arc                       ...............2164    1    88      A 20130709 23:19:34 /u02/database/GOBO1/archive/arch_816906485_1_88.arc2165    1    89      A 20130710 13:00:34 /u02/database/GOBO1/archive/arch_816906485_1_89.arc2166    1    90      A 20130710 22:02:44 /u02/database/GOBO1/archive/arch_816906485_1_90.arcRMAN> delete archivelog from time 'sysdate-1';released channel: ORA_DISK_1allocated channel: ORA_DISK_1channel ORA_DISK_1: sid=1075 devtype=DISKList of Archived Log CopiesKey     Thrd Seq     S Low Time          Name------- ---- ------- - ----------------- ----2165    1    89      A 20130710 13:00:34 /u02/database/GOBO1/archive/arch_816906485_1_89.arc2166    1    90      A 20130710 22:02:44 /u02/database/GOBO1/archive/arch_816906485_1_90.arcDo you really want to delete the above objects (enter YES or NO)? yesdeleted archive logarchive log filename=/u02/database/GOBO1/archive/arch_816906485_1_89.arc recid=2165 stamp=820447373deleted archive logarchive log filename=/u02/database/GOBO1/archive/arch_816906485_1_90.arc recid=2166 stamp=820458049Deleted 2 objectsRMAN> delete archivelog all completed before 'sysdate - 1';released channel: ORA_DISK_1allocated channel: ORA_DISK_1channel ORA_DISK_1: sid=1075 devtype=DISKList of Archived Log CopiesKey     Thrd Seq     S Low Time          Name------- ---- ------- - ----------------- ----2149    1    73      A 20130703 23:17:13 /u02/database/GOBO1/archive/arch_816906485_1_73.arc              .......................2164    1    88      A 20130709 23:19:34 /u02/database/GOBO1/archive/arch_816906485_1_88.arcDo you really want to delete the above objects (enter YES or NO)? yes     ................archive log filename=/u02/database/GOBO1/archive/arch_816906485_1_88.arc recid=2164 stamp=820414835Deleted 16 objectsRMAN> sql " alter system archive log current";sql statement:  alter system archive log currentRMAN> list copy of archivelog all;List of Archived Log CopiesKey     Thrd Seq     S Low Time          Name------- ---- ------- - ----------------- ----2167    1    91      A 20130711 01:00:48 /u02/database/GOBO1/archive/arch_816906485_1_91.arcRMAN> delete noprompt archivelog all completed before 'sysdate';released channel: ORA_DISK_1allocated channel: ORA_DISK_1channel ORA_DISK_1: sid=1075 devtype=DISKList of Archived Log CopiesKey     Thrd Seq     S Low Time          Name------- ---- ------- - ----------------- ----2167    1    91      A 20130711 01:00:48 /u02/database/GOBO1/archive/arch_816906485_1_91.arcdeleted archive logarchive log filename=/u02/database/GOBO1/archive/arch_816906485_1_91.arc recid=2167 stamp=820517964Deleted 1 objects

3. Clear simple shell scripts for archiving logs

# It is appropriate to use shell scripts to call RMAN when the RAC environment or ASM needs to clear archive. # Second, if your archive is located in the flash back area, make a reasonable retention policy, it can also make Oracle automatically aging useless archive logs Robin @ szdb :~ /Dba_scripts/custom/bin> More clean_arch.sh # + snapshot + # + clean archived log as specified time | # + Author: Robinson | # + blog: http://blog.csdn.net/robinson_0612 | # + usage: | # + clean_arch.sh $ oracle_sid | # + ------------------------------------------------------- + ##! /Bin/bash # -------------------- # define variable # ------------------ if [-f ~ /. Bash_profile]; then .~ /. Bash_profilefiif [-z "$ {1}"]; then Echo "Usage:" Echo "'basename $0 'oracle_sid" Exit 1fioracle_sid = $1; export oracle_sid $ ORACLE_HOME/bin/RMAN log =/users/Robin/log/RMAN. log <EOF connect target/run {crosscheck archivelog all; Delete noprompt expired archivelog all; Delete noprompt archivelog all completed before 'sysdate-1';} exit; eofexit

4. Summary
A. It is best to clear archived logs in RMAN mode. This is the most thorough method.
B. In the production environment, archive logs should be cleared during RMAN backup. For example, delete input and delete all input are used to clear archivelog logs during Backup.
C. If archive logs are not cleared during backup, the arch will be large, resulting in archiving failure due to full archiving disk. It is recommended to delete or store the data in the flash back area.
D. Use the delete noprompt archivelog all completed before 'sysdate-n' method if you want to clear most of them and keep the most recent ones.
E. Detailed clear archiving log Syntax: http://docs.oracle.com/cd/B19306_01/backup.102/b14194/rcmsynta008.htm#RCMRF106

 

References
Oracle cold backup

Oracle Hot Backup

Concept of Oracle backup recovery

Oracle instance recovery

Oracle recovery based on user management

System tablespace management and Backup Recovery

Sysaux tablespace management and recovery

Oracle backup control file recovery (unsing backup controlfile)

RMAN overview and architecture

RMAN configuration, Monitoring and Management

Detailed description of RMAN backup

RMAN restoration and recovery

Create and use RMAN catalog

Create RMAN storage script based on catalog

Catalog-based RMAN backup and recovery

RMAN backup path confusion

Customize the date and time format displayed by RMAN

Backup and recovery of read-only tablespace

Incomplete recovery of Oracle based on user management

Understanding using backup controlfile

Use RMAN for recovery from different machine backups (WIN platform)

Use RMAN to migrate a file system database to ASM

Oracle backup policy (RMAN) in Linux)

Linux RMAN backup shell script

Use RMAN to migrate the database to a different machine

Run the SQL statement at the RMAN prompt.

Oracle RMAN-based Incomplete recovery (Incomplete recovery by RMAN)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.