RMAN备份文件远大于数据库大小的原因分析
在跟客户进行交流的时候,客户提出有一套数据库只有40G的大小,但是通过RMAN备份出来的文件有80GB,使用expdp导出来的DUMP文件小于40GB,感觉有些诧异,RMAN不是只备份有数据的数据块吗?怎么备份也不应该超过40GB啊,难道跟高水位线有关?带着这些疑问通过在MOS上查阅了一些文章,发现确实有出现RMAN备份文件远大于数据库所占用空间的问题出现的可能性。
首先要明白RMAN的压缩类型:
By default RMAN has three types of compression :
1. Null compression
2. Unused block compression
3. Binary compression <<<< 这是我们最常用到的压缩类型,backup as compressed backupset ....
Till Oracle Version 10.1 only 'Null' compression is done by default but from Oracle Version 10.2 'Null' and 'unused block' compression is done. The types of compression are done automatically, no special command is required.
'Null' and 'unused block' compression are filtering which blocks are send to the backups. 'Binary' compression is an additional compression on the blocks send to the backup.
1. Null Compression:
When backing up datafiles into backup sets, RMAN does not back up the contents of data blocks that have never been allocated. (In previous releases, this behavior was referred to as NULL compression). This means RMAN will never backup the blocks that are ever used. RMAN, through Oracle version 9i and forward has performed null compression.
Example : You have a tablespace having one datafile of size 100MB and out of 100MB only 50 MB is used. Then RMAN will backup only 50MB. <<<< 在10.2之前的版本(准确的说是10.2.0.2之前的版本),Oracle默认都是这种压缩类型,RMAN不备份从未分配的数据块,换句话说,RMAN不备份从来没使用过的块。例如:如果一个表空间有一个大小为100MB的数据文件,该文件使用了50MB,RMAN只备份50MB(RMAN的备份和是不是高水位线下的空块没关系,和数据块有没有被分配过有关系)。
Null Compression also applies to SE and SE ONE
2. Unused Block Compression:
From Oracle version 10.2 forward, RMAN skips the blocks that do no currently contain data and this is called 'Unused Block Compression'. RMAN now creates more compact backups of datafiles, by skipping datafile blocks that are not currently used to store data. In previous releases, RMAN only supported NULL compression, which skipped space in datafiles that had never been allocated. No extra action is required on the part of the DBA to use this feature.
Example : You have a tablespace having one datafile of size 100MB and out of 100MB, 50MB is used by the user tables. Then user dropped a table belonging to that tablespace which was of 25MB, with the new unused block compression on 25MB of the files is backed up. In this example if null compression is used then it would have backed up 50MB because null compression will consider the blocks that are formatted/ever used. <<<< 从10.2版本开始(准确的说是10.2.0.2版本),出现了一种新的压缩类型-Unused Block Compression,这种备份类型将跳过当前不包含数据的块(即使曾经使用过该块),这是新版本RMAN默认的压缩方式。例如:如果一个表空间有一个大小为100MB的数据文件,50MB用于用户表,用户drop了一个属于该空间的25MB大小的表,新的默认的UNUSED BLOCK COMPRESSION压缩类型将只备份25MB的数据块。如果在NULL COMPRESSION的压缩类型,将备份50MB的数据块,因为NULL COMPRESSION的压缩类型会考虑块被格式化过,或者说曾经被使用过。
Unused Block Compression is done, if all of the following conditions apply: <<<< 虽然UNUSED BLOCK COMPRESSION是10.2的默认压缩类型,但不是说10.2的版本通过RMAN备份就一定使用这种压缩类型,使用它必须满足以下5个条件。
+ The COMPATIBLE initialization parameter is set to 10.2 <<<< 即使将Oracle数据库升级到10.2.0.2以上的版本,默认情况下COMPATIBLE初始化参数的值为空,要使用UNUSED BLOCK COMPRESSION功能必须手动设置该参数。
+ There are currently no guaranteed restore points defined for the database <<<< 没有FLASHBACK中的强制还原点。
+ The datafile is locally managed <<<< 本地化数据文件管理方式,默认即是。
+ The datafile is being backed up to a backup set as part of a full backup or a level 0 incremental backup <<<< 数据文件作为全库备份的一部分,或者是基于0级别备份的增量备份。
+ The backup set is being created on DISK <<<< 备份集创建在磁盘上。
or
backup is done to TAPE using "OSB" (Oracle Secure Backup)! <<<< 或者使用OSB将数据备份到磁带,其他第三方的备份软件无法使用这种压缩类型,只能是NULL COMPRESSION。
Unused Block Compression is NOT used if backup done to tape using a THIRD PARTY BACKUP SOFTWARE !
Unused block compression IS executed in Standard Edition. <<<< 标准版也可以使用这种类型的压缩方式。
以上内容摘取自《A Complete Understanding of RMAN Compression (文档 ID 563427.1)》
以下的内容说明在10.2.0.1版本中,UNUSED BLOCK COMPRESSION压缩类型不可用:
Unused block compression is NOT available with the Base Release of 10gR2 (10.2.0.1).
It only became available in the first Patch Set Release (10.2.0.2) for NEW tablespaces only.
So for tablespaces created:
- before 10.2.0.2 was applied
- before compatible was set to 10.2
we cannot use Unused Block Compression.
The cause of this problem has been identified and verified in an 'unpublished' Bug 4720762 - Fixed in Product Version 11.0
以上内容摘自:《Why is RMAN not using Unused Block Compression during backup? (文档 ID 798844.1)》
总结:后经过和客户的确认,客户数据库的版本为10.2.0.4,所以我们大胆的推测,虽然客户的版本高于10.2.0.2,但是由于默认情况下数据库初始化参数COMPITABLE为空,或不符合其他条件导致UNUSED BLOCK COMPRESSION压缩类型无法在RMAN中使用到,所以凡是曾经使用到的数据块RMAN都会进行备份(NULL COMPRESSION),80GB可能是客户曾经用到过的空间大小,后来释放了相应空间,所以当前备份才呈现出40GB的数据库RMAN备份出来有80GB。
--end--