Delete Expired VS. Delete Obsolete

今天有朋友问,到底RMAN里面的命令delete expired和delete obsolete有什么区别?

先来看一下官方文档中的解释。via Backup and Recovery User Guide

delete exipired

If you run CROSSCHECK, and if RMAN cannot locate the files, then it updates their records in the RMAN repository to EXPIRED status. You can then use the DELETE EXPIRED command to remove records of expired backups and copies from the RMAN repository.

delete obsolete

The RMAN DELETE command supports an OBSOLETE option, which deletes backups that are no longer needed to satisfy specified recoverability requirements. You can delete files obsolete according to the configured default retention policy, or another retention policy that you specify as an option to the DELETE OBSOLETE command. As with other forms of the DELETE command, the files deleted are removed from backup media, deleted from the recovery catalog, and marked as DELETED in the control file.

delete expired删除的是那些本来RMAN以为存在但是实际上在磁盘或者磁带上已经被删除了的信息,删除的只是RMAN资料库中的记录;delete obsolete则删除旧于备份保留策略定义的备份数据同时也更新RMAN资料库以及控制文件。

那么再形象一点儿解释的话,就是“在不在”和“要不要”的区别。expired是不在了,obsolete是不要了。

不在的并不一定是不需要的。
不需要的也不一定就不在了。

外一句:数据库管理的时候,痛苦的是不需要的还在,还占据着资源;比这更痛苦的是,需要的已经不在了,想恢复却找不到备份集。 😀

RMAN Compressed Backupset

在Oracle10g就已经推出了Compressed Backupset。

There is some CPU overhead associated with compressing backup sets. If the database being backed up is running at or near its maximum load, you may find the overhead from using AS COMPRESSED BACKUPSET unacceptable. In most other circumstances, compressing backupsets saves enough disk space to be worth the CPU overhead.

今天在自己机器上的Oracle 11.1.0.6版本中测试了一下,压缩效果还是很让人满意的,不但存储空间变小,甚至备份所需要的时间也有所加快。

不使用压缩的备份:
backup database plus archivelog delete all input;

Size Elapsed Time
———- ————
652.77M 00:01:25

使用压缩的备份:
backup AS COMPRESSED BACKUPSET database plus archivelog delete all input;

Size Elapsed Time
———- ————
84.87M 00:00:48

在CPU并不是主要瓶颈的系统中,建议启动压缩备份。

Update:
Oracle11g中新增的zlib压缩算法和之前bzip2压缩算法之间的测试比较可以参看Oracle11g新特性:RMAN压缩备份 from Ningoo

利用RMAN转移数据文件

将数据文件从文件系统转移为裸设备,很简单,记录一下操作。

1. 从v$datafile中找到需要转换的数据文件file#
2. 从dba_data_files中找到数据文件所在的表空间名称,因为restore之前要将相关表空间offline才可以
3. 创建好相应的目的裸设备
4. 数据库必须处于归档状态

在RMAN中运行如下命令:

run{
sql “alter tablespace ADMASDB_DEFAULT offline”;
allocate channel d1 TYPE DISK;
set newname for datafile 136 to ‘/home/oracle/oradata/admas/roralv08’;
set newname for datafile 164 to ‘/home/oracle/oradata/admas/roralv5G_3’;
restore datafile 136;
restore datafile 164;
switch datafile all;
recover datafile 136;
recover datafile 164;
sql “alter tablespace ADMASDB_DEFAULT online”;
}