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

前端之家收集整理的这篇文章主要介绍了ORACLE 定时清理归档日志详细过程前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

1RM方式清理归档日志

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

2、使用rman清理归档日志

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

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

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

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

DELETENOPROMPT ARCHIVELOG UNTIL TIME "TO_DATE('XXXX-XX-XX','YYYY-MM-DD')";

deletenoprompt archivelog until time "to_date('2016-09-14 18:00:00','YYYY-MM-DD')"

crosscheckarchivelog all;--->校验日志的可用性

listexpired archivelog all;--->列出所有失效的归档日志

deletearchivelog until sequence 16;--->删除log sequence为16及16之前的所有归档日志

deletearchivelog all completed before 'sysdate-7';--->删除系统时间7天以前的归档日志,不会删除闪回区有效的归档日志

deletearchivelog all completed before 'sysdate - 1';--->同上,1天以前的

deletearchivelog from time 'sysdate-1';--->注意这个命令,删除系统时间1天以内到现在的归档日志

deletenoprompt archivelog all completed before 'sysdate'; --->该命令清除当前所有的归档日志

deletenoprompt archivelog all completed before 'sysdate-0'; --->该命令清除当前所有的归档日志

deletenoprompt 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://www.f2er.com/oracle/212320.html

猜你在找的Oracle相关文章