Automate the cleanup of Oracle archive logs with scripts

Source: Internet
Author: User
Tags shebang

Background

Because the Oracle database has an archive mode turned on, often because the archive log file is too large to connect to the database, it is necessary to manually clean up the archive log after the problem is discovered, and it may have been a long time since the problem was discovered and has a very serious impact on the user's use in the production environment.

The project involves multi-party data docking, the frequent insertion and update of the database will generate a large number of archived logs, the archive log space is 500G, about a week or so of time to archive the log space is 100%.

To solve this problem, use the script + timed task to automatically clean up the archive log and keep the archive for only 5 days.

Archive Log Cleanup Scripts
#!/bin/bash#Author Wangchengwei#FileName clear_archivelog.sh#Date 2015-12-31#DESC Delete all archivelog.if[- F~/.bash_profile]; Then. ~/.bash_profilefi#set EnvEcho "Oracle Home:"$ORACLE _homeEcho "Oracle SID:"$ORACLE _sid$ORACLE _home/bin/rman target Sys/[email protected] log=/oracle/logs/rman.log <<eofcrosscheck archivelog all;delete noprompt Expired Archivelog All;delete noprompt Archivelog all completed before' sysdate-5 ';Exit; Eof

Another way of writing

$ORACLE_HOME/bin/rman log=/oracle/logs/rman.log <<EOF       connect target sys/[email protected]run{crosscheck archivelog all;    delete noprompt expired archivelog all;    ‘sysdate - 5‘;    }  

Many scripts are used on the Web $ORACLE_HOME/bin/rman target / , and the following problems are found in the actual use of direct use / . So it's recommended that you add the username, password, and SID.

Recovery Manager:release11.2. 0. 4. 0-ProductionOn   Thu Dec    : £ ºCopyright (c)1982, ., Oracle and/orits affiliates. All Rights reserved.connected toTarget Database ( notstarted) rman>usingTarget Database controlfileinstead ofRecovery catalogrman-00571: ===========================================================rman-00569: =============== ERROR MESSAGE, STACK follows ===============rman-00571: ===========================================================rman-03002: Failure ofCrosscheck command  at//+: 08 rman-12010: Automatic channel allocation initialization failedrman-06403: Could notObtainaFully Authorized sessionora-01034: ORACLE notavailableora-27101: Shared Memory Realm does notexistlinux-x86_64 Error:2: No Suchfile or Directory
Set up Scheduled Tasks
-e   #打开配置#加入以下内容,定于每天11点执行011 * * * /oracle/scripts/clear_archivelog.sh > /oracle/scripts/runlog.log##判断定时服务是否启动#启动、停止或重启服务

Scheduled tasks need to be set under Oracle user.

Automate the cleanup of Oracle archive logs with scripts

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.