oracle数据库删除归档,【学习笔记】Oracle数据库删除归档日志的正常方法

【学习笔记】Oracle数据库删除归档日志的正常方法

时间:2016-11-03 21:43   来源:Oracle研究中心   作者:代某人   点击:

天萃荷净

Oracle研究中心学习笔记:分享一篇关于Oracle数据库删除归档日志的文章,该文章介绍rman中的delete命令基本上可以满足我们需要,不需要使用rm命令来删除。

使用脚本调用rm命令来删除归档日志,其实rman中的delete命令基本上可以满足我们需要,不需要使用rm命令来删除。下面是测试删除已经备份2次,5分钟之前生成的归档文件。

1 版本介绍

oracleplus.net> select * from v$version;

BANNER

——————————————————————————–

Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production

PL/SQL Release 11.2.0.3.0 – Production

CORE 11.2.0.3.0 Production

TNS for Linux: Version 11.2.0.3.0 – Production

NLSRTL Version 11.2.0.3.0 – Production

oracleplus.net> !uname -a

Linux orcl9i 2.6.9-89.EL #1 Mon Apr 20 10:22:29 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

2 多次备份归档日志

这里使用switch logfile命令来切换日志,

oracleplus.net> set time on

06:24:49 oracleplus.net> alter system switch logfile;

System altered.

06:27:18 oracleplus.net> alter system switch logfile;

System altered.

备份归档日志

RMAN> backup archivelog all not backed up 2 times format ‘/soft/rman/ar_%s_%p_%t’;

Starting backup at 08-NOV-14

current log archived

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=1 device type=DISK

skipping archived logs of thread 1 from sequence 1343 to 1344; already backed up

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=1 RECID=303 STAMP=863072653

input archived log thread=1 sequence=2 RECID=304 STAMP=863072685

input archived log thread=1 sequence=3 RECID=305 STAMP=863072694

input archived log thread=1 sequence=4 RECID=306 STAMP=863072848

input archived log thread=1 sequence=5 RECID=307 STAMP=863072869

channel ORA_DISK_1: starting piece 1 at 08-NOV-14

channel ORA_DISK_1: finished piece 1 at 08-NOV-14

piece handle=/soft/rman/ar_80_1_863072870 tag=TAG20141108T062750 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03

Finished backup at 08-NOV-14

切换日志

06:28:24 oracleplus.net> alter system switch logfile;

System altered.

再次备份归档日志

RMAN> backup archivelog all not backed up 2 times format ‘/soft/rman/ar_%s_%p_%t’;

Starting backup at 08-NOV-14

current log archived

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=34 device type=DISK

skipping archived logs of thread 1 from sequence 1343 to 1344; already backed up

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=1 RECID=303 STAMP=863072653

input archived log thread=1 sequence=2 RECID=304 STAMP=863072685

input archived log thread=1 sequence=3 RECID=305 STAMP=863072694

input archived log thread=1 sequence=4 RECID=306 STAMP=863072848

input archived log thread=1 sequence=5 RECID=307 STAMP=863072869

input archived log thread=1 sequence=6 RECID=308 STAMP=863072911

input archived log thread=1 sequence=7 RECID=309 STAMP=863072953

channel ORA_DISK_1: starting piece 1 at 08-NOV-14

channel ORA_DISK_1: finished piece 1 at 08-NOV-14

piece handle=/soft/rman/ar_81_1_863072954 tag=TAG20141108T062914 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03

Finished backup at 08-NOV-14

又一次备份

RMAN> backup archivelog all not backed up 2 times format ‘/soft/rman/ar_%s_%p_%t’;

Starting backup at 08-NOV-14

current log archived

using channel ORA_DISK_1

skipping archived logs of thread 1 from sequence 1343 to 1344; already backed up

skipping archived logs of thread 1 from sequence 1 to 5; already backed up

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=6 RECID=308 STAMP=863072911

input archived log thread=1 sequence=7 RECID=309 STAMP=863072953

input archived log thread=1 sequence=8 RECID=310 STAMP=863072962

channel ORA_DISK_1: starting piece 1 at 08-NOV-14

channel ORA_DISK_1: finished piece 1 at 08-NOV-14

piece handle=/soft/rman/ar_82_1_863072962 tag=TAG20141108T062922 comment=NONE

channel ORA_DISK_1: backup set

06:29:58 oracleplus.net> alter system switch logfile;

System altered.

3 删除归档

删除5分钟前生成的,已经成功备份2次的归档文件,意味着要做删除sequence=8之前的所有的归档文件。

这里可以看到有如下的归档文件

[root@oracleplus.net nbu]#ls -lrt

total 41736

-rw-r—– 1 oracle oinstall 15620096 Nov 8 06:24 1_1_863072613.dbf

-rw-r—– 1 oracle oinstall 26667008 Nov 8 06:24 1_2_863072613.dbf

-rw-r—– 1 oracle oinstall 306176 Nov 8 06:24 1_3_863072613.dbf

-rw-r—– 1 oracle oinstall 40960 Nov 8 06:27 1_4_863072613.dbf

-rw-r—– 1 oracle oinstall 7168 Nov 8 06:27 1_5_863072613.dbf

-rw-r—– 1 oracle oinstall 1536 Nov 8 06:28 1_6_863072613.dbf

-rw-r—– 1 oracle oinstall 6656 Nov 8 06:29 1_7_863072613.dbf

-rw-r—– 1 oracle oinstall 1536 Nov 8 06:29 1_8_863072613.dbf

-rw-r—– 1 oracle oinstall 15872 Nov 8 06:30 1_9_863072613.dbf

06:39:02 oracleplus.net> select sysdate from dual;

SYSDATE

——————-

2014-11-08 06:39:08

06:39:08 oracleplus.net> !rman target /

Recovery Manager: Release 11.2.0.3.0 – Production on Sat Nov 8 06:39:11 2014

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

connected to target database: ORCL1123 (DBID=3499064767)

如果备份集存放在TAPE上面,需要将device type disk更改为device type tape;

RMAN> delete noprompt archivelog until time ‘sysdate-5/1440’ backed up 2 timesto device type disk;

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=36 device type=DISK

RMAN-08138: WARNING: archived log not deleted – must create more backups

archived log file name=/oracle/nbu/1_8_863072613.dbf thread=1 sequence=8

RMAN-08138: WARNING: archived log not deleted – must create more backups

archived log file name=/oracle/nbu/1_9_863072613.dbf thread=1 sequence=9

List of Archived Log Copies for database with db_unique_name ORCL1123

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

Key Thrd Seq S Low Time

——- —- ——- – ———

301 1 1343 A 07-NOV-14

Name: /oracle/nbu/1_1343_849959296.dbf

302 1 1344 A 07-NOV-14

Name: /oracle/nbu/1_1344_849959296.dbf

303 1 1 A 08-NOV-14

Name: /oracle/nbu/1_1_863072613.dbf

304 1 2 A 08-NOV-14

Name: /oracle/nbu/1_2_863072613.dbf

305 1 3 A 08-NOV-14

Name: /oracle/nbu/1_3_863072613.dbf

306 1 4 A 08-NOV-14

Name: /oracle/nbu/1_4_863072613.dbf

307 1 5 A 08-NOV-14

Name: /oracle/nbu/1_5_863072613.dbf

308 1 6 A 08-NOV-14

Name: /oracle/nbu/1_6_863072613.dbf

309 1 7 A 08-NOV-14

Name: /oracle/nbu/1_7_863072613.dbf

deleted archived log

archived log file name=/oracle/nbu/1_1_863072613.dbf RECID=303 STAMP=863072653

deleted archived log

archived log file name=/oracle/nbu/1_2_863072613.dbf RECID=304 STAMP=863072685

deleted archived log

archived log file name=/oracle/nbu/1_3_863072613.dbf RECID=305 STAMP=863072694

deleted archived log

archived log file name=/oracle/nbu/1_4_863072613.dbf RECID=306 STAMP=863072848

deleted archived log

archived log file name=/oracle/nbu/1_5_863072613.dbf RECID=307 STAMP=863072869

deleted archived log

archived log file name=/oracle/nbu/1_6_863072613.dbf RECID=308 STAMP=863072911

deleted archived log

archived log file name=/oracle/nbu/1_7_863072613.dbf RECID=309 STAMP=863072953

Deleted 7 objects

[root@oracleplus.net nbu]#ls -lrt

total 20

-rw-r—– 1 oracle oinstall 1536 Nov 8 06:29 1_8_863072613.dbf

-rw-r—– 1 oracle oinstall 15872 Nov 8 06:30 1_9_863072613.dbf

这里可以看到只剩下8与9两个归档文件了。

在删除归档的时候,建议使用rman的delete命令,少使用操作系统的rm命令。

本文固定链接: htOracle о tp://www.htz.pw/2014/11/09/delete-archivelog-until-time-n-backed-up-n-times.html | 认真就输

--------------------------------------ORACLE-DBA----------------------------------------

最权威、专业的Oracle案例资源汇总之【学习笔记】Oracle数据库删除归档日志的正常方法

9bd101509341196819122f36086c9a60.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值