ORACLE 定时清理归档日志详细过程

               

 

 

业务增长发展迅猛,归档日志增长太快,磁盘承受不了,所以准备做个定时清理归档日志的定时任务。

 

1、RM方式清理归档日志

清理归档日志,可以人为的删除已经归档好的日志文件,然后再调用rman里面RMAN> crosscheck archivelog all;来去数据库里面删除归档记录;也可以通过ram调用delete命令来删除归档日志。

 

2、使用rman清理归档日志

                RMAN清除方式会自动清除磁盘上的归档日志文件,同时会释放控制文件中对应的归档日志的归档信息。

                可以基于不同的条件来清除归档日志,如基于SCN,基于SEQUENCE,基于TIME等方式。

                对于上述的三种方式又可以配合from, until, between .. and .. 等等子句来限定范围,方式灵活多变。

                下面的命令用于校验归档日志的有效性,列出无效的归档日志,以及以何种方式清除归档日志,列出几种常用的:


  delete noprompt archivelog until time "to_date('XXXX-XX-XX','YYYY-MM-DD')";    ---> 清理到某天日期之前的归档
                delete noprompt archivelog until time "to_date('2016-09-14 18:00:00','YYYY-MM-DD hh24:mi:ss')";   ---> 清理到具体时分秒之前的归档日志
                cross check archivelog all;                           --->校验日志的可用性
                list expired archivelog all;                         --->列出所有失效的归档日志
                delete archivelog until sequence 16;                 --->删除log sequence为16及16之前的所有归档日志
                delete archivelog all completed before 'sysdate-7';   --->删除系统时间7天以前的归档日志,不会删除闪回区有效的归档日志
                delete archivelog all completed before 'sysdate - 1'; --->同上,1天以前的
                delete archivelog from time 'sysdate-1';             --->注意这个命令,删除系统时间1天以内到现在的归档日志
                delete noprompt archivelog all completed before 'sysdate';  --->该命令清除当前所有的归档日志
                delete noprompt archivelog all completed before 'sysdate-0';  --->该命令清除当前所有的归档日志
                delete noprompt archivelog all;                              --->同上一命令



 

 

3、实现清理一个小时前的归档日志

 

执行命令:delete force archivelog all completed before 'sysdate-1/24';

验证执行过程。

(1)查看当前时间

 

[oracle@hch_test_121_90 ~]$ date

 

Tue Oct 11 11:20:20 CST 2016

 

[oracle@hch_test_121_90 ~]$

 

 

 

(2)查看当前一个小时之前的归档日志,看到有一个o1_mf_1_2822_czrm1dj8_.arc,如下所示:

 

[oracle@hch_test_121_90 ~]$ ll  /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/ |more

 

total 3181880

 

-rw-r----- 1 oracle oinstall 41340416 Oct 11 10:19  o1_mf_1_2822_czrm1dj8_.arc

 

-rw-r----- 1 oracle oinstall 40434176 Oct  11 10:20 o1_mf_1_2823_czrm49l9_.arc

 

-rw-r----- 1 oracle oinstall 41180160 Oct  11 10:22 o1_mf_1_2824_czrm76nd_.arc

 

-rw-r----- 1 oracle oinstall 40340480 Oct  11 10:23 o1_mf_1_2825_czrm9xos_.arc

 

 

 

(3)开始执行删除命令,按计划删除这一条归档日志

 

RMAN> delete force archivelog all  completed before 'sysdate-1/24';

 

 

 

using target database control file  instead of recovery catalog

 

allocated channel: ORA_DISK_1

 

channel ORA_DISK_1: SID=11 device  type=DISK

 

List of Archived Log Copies for database  with db_unique_name POWERDES

 

=====================================================================

 

 

 

Key      Thrd Seq     S Low Time

 

------- ---- ------- - ---------

 

1396     1    2822    A 11-OCT-16

 

         Name: /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2822_czrm1dj8_.arc

 

 

 

 

 

Do you really want to delete the above  objects (enter YES or NO)? YES   # 输入删除命令

 

deleted archived log

 

archived log file  name=/oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2822_czrm1dj8_.arc  RECID=1396 STAMP=924949164

 

Deleted 1 objects

 

 

 

RMAN>

 

 

4、自动化脚本定时任务实现清理一个小时前的归档日志

(1)自动化脚本

[root@hch_test_121_90 ~]# more  archivelog_clear.sh

 

#!/bin/sh

 

BACK_DIR=/oracle/clear_archlog/data

 

export DATE=`date +%F`

 

echo "      " >>  $BACK_DIR/$DATE/rman_backup.log

 

echo `date '+%Y-%m-%d %H:%M:%S'` >>  $BACK_DIR/$DATE/rman_backup.log

 

su - oracle -c "

 

mkdir -p $BACK_DIR/$DATE

 

rman log=$BACK_DIR/$DATE/rman_backup.log  target / <<EOF

 

# delete force archivelog all completed before  'sysdate-1/24';  # 这里执行清除归档日志,如果不想手动输入YES,则可以添加noprompt参数

 

delete force noprompt archivelog all  completed before 'sysdate-1/24';

 

exit;

 

EOF

 

"

 

echo "   " >>  $BACK_DIR/$DATE/rman_backup.log

 

[root@hch_test_121_90 ~]#

 

(2)crontab定时任务

[root@hch_test_121_90 ~]# crontab -l

 

10 */1 * * * sh  /home/oracle/archivelog_clear.sh

 

[root@hch_test_121_90 ~]#

 

 

(3)查看执行后的日志

[root@hch_test_121_90 ~]# more  /oracle/clear_archlog/data/2016-10-11/rman_backup.log

 

 

 

Recovery Manager: Release 11.2.0.1.0 -  Production on Tue Oct 11 11:28:04 2016

 

 

 

Copyright (c) 1982, 2009, Oracle and/or  its affiliates.  All rights reserved.

 

 

 

connected to target database: POWERDES  (DBID=3458668465)

 

 

 

RMAN>

 

using target database control file  instead of recovery catalog

 

allocated channel: ORA_DISK_1

 

channel ORA_DISK_1: SID=137 device  type=DISK

 

List of Archived Log Copies for database  with db_unique_name POWERDES

 

=====================================================================

 

 

 

Key      Thrd Seq     S Low Time

 

------- ---- ------- - ---------

 

1397     1    2823    A 11-OCT-16

 

         Name:  /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2823_czrm49l9_.arc

 

 

 

1398     1    2824    A 11-OCT-16

 

         Name:  /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2824_czrm76nd_.arc

 

 

 

1399     1    2825    A 11-OCT-16

 

         Name: /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2825_czrm9xos_.arc

 

 

 

1400     1    2826    A 11-OCT-16

 

         Name:  /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2826_czrmdqqy_.arc

 

 

 

1401     1    2827    A 11-OCT-16

 

         Name: /oracle/app/oracle/flash_recovery_area/POWERDES/archivelog/2016_10_11/o1_mf_1_2827_czrmhksn_.arc

 

 

 

 

 

Do you really want to delete the above  objects (enter YES or NO)? "exit;" is an invalid response - please  re-enter.

 

 

 

Do you really want to delete the above  objects (enter YES or NO)?

 

Error occurred getting response -  assuming NO response

 

 

 

RMAN>

 

 

 

Recovery Manager complete.

 

[root@hch_test_121_90 ~]#

 

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值