11gR2新特性-RMAN压缩备份的增强
ORACLE在10g版本推出了以bzip2算法的压缩备份,在11gR1又推出了zlib压缩算法的压缩备份,在11gR2版本又推出了基本压缩备份和高级压缩备份,而高级压缩备份又分高中低三种级别。本文主要对比10gR2和11gR2的压缩备份,由于本人没有11gR1测试环境,11gR1也很少有人使用,这里11gR1就不测试了。
先看下10.2.0.5.0版本的数据库的当前信息,下面是数据文件的大小和数据文件空闲大小。
SQL> select * from v$version; BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi PL/SQL Release 10.2.0.5.0 - Production CORE 10.2.0.5.0 Production TNS for Linux: Version 10.2.0.5.0 - Production NLSRTL Version 10.2.0.5.0 - Production SQL> select sum(BYTES/1024/1024) from dba_data_files; SUM(BYTES/1024/1024) -------------------- 945 SQL> select sum(BYTES/1024/1024) from dba_free_space; SUM(BYTES/1024/1024) -------------------- 415.25
数据文件真实使用530M。
SQL> select 945-415.25 from dual; 945-415.25 ---------- 529.75
在看下10gR2在启用压缩时备份文件的大小和备份时间(虚拟机环境CPU和I/O能力有限,和生产环境可能存在一定的误差)。
RMAN> backup database format '/home/oracle/backup/10205-%U-%T-%s'; Starting backup at 30-11-12 allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=143 devtype=DISK channel ORA_DISK_1: starting full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset input datafile fno=00001 name=/u01/app/oracle/oradata/orac/system01.dbf input datafile fno=00002 name=/u01/app/oracle/oradata/orac/undotbs01.dbf input datafile fno=00003 name=/u01/app/oracle/oradata/orac/sysaux01.dbf input datafile fno=00005 name=/u01/app/oracle/oradata/orac/gguser.dbf input datafile fno=00004 name=/u01/app/oracle/oradata/orac/users01.dbf channel ORA_DISK_1: starting piece 1 at 30-11-13 channel ORA_DISK_1: finished piece 1 at 30-11-13 piece handle=/home/oracle/backup/10205-0bnrj1eu_1_1-20121130-11 tag=TAG20121130T051302 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15 channel ORA_DISK_1: starting full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset including current control file in backupset including current SPFILE in backupset channel ORA_DISK_1: starting piece 1 at 30-11-13 channel ORA_DISK_1: finished piece 1 at 30-11-13 piece handle=/home/oracle/backup/10205-0cnrj1fd_1_1-20121130-12 tag=TAG20121130T051302 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 30-1-13 [oracle@t10205 backup]$ du -sh * 404M 10205-0bnrj1eu_1_1-20121130-11 6.9M 10205-0cnrj1fd_1_1-20121130-12
没有启用压缩时,15秒完成数据库的备份,备份文件404M,下面再看看启用压缩后,备份需要的时间和备份文件大小。
RMAN> backup as compressed backupset full database format '/home/oracle/backup/compress-%U'; Starting backup at 30-11-12 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=158 devtype=DISK channel ORA_DISK_1: starting compressed full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset input datafile fno=00001 name=/u01/app/oracle/oradata/orac/system01.dbf input datafile fno=00002 name=/u01/app/oracle/oradata/orac/undotbs01.dbf input datafile fno=00003 name=/u01/app/oracle/oradata/orac/sysaux01.dbf input datafile fno=00005 name=/u01/app/oracle/oradata/orac/gguser.dbf input datafile fno=00004 name=/u01/app/oracle/oradata/orac/users01.dbf channel ORA_DISK_1: starting piece 1 at 30-11-12 channel ORA_DISK_1: finished piece 1 at 30-11-12 piece handle=/home/oracle/backup/compress-0dnrj1rf_1_1 tag=TAG20121130T051942 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:16 channel ORA_DISK_1: starting compressed full datafile backupset channel ORA_DISK_1: specifying datafile(s) in backupset including current control file in backupset including current SPFILE in backupset channel ORA_DISK_1: starting piece 1 at 30-11-12 channel ORA_DISK_1: finished piece 1 at 30-11-12 piece handle=/home/oracle/backup/compress-0enrj1ru_1_1 tag=TAG20121130T051942 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02 Finished backup at 30-11-12 [oracle@t10205 backup]$ du -sh com* 80M compress-0dnrj1rf_1_1 1.1M compress-0enrj1ru_1_1
我的数据库数据量太小,而且CPU资源充足,备份时间的差距不明显,但是压缩后,备份文件只有80M。再看下11gR2的备份情况,先看下11gR2测试数据库的数据量情况。
SQL> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production PL/SQL Release 11.2.0.4.0 - Production CORE 11.2.0.4.0 Production TNS for Linux: Version 11.2.0.4.0 - Production NLSRTL Version 11.2.0.4.0 - Production SQL> select sum(BYTES/1024/1024) from dba_data_files; SUM(BYTES/1024/1024) -------------------- 2040 SQL> select sum(BYTES/1024/1024) from dba_free_space; SUM(BYTES/1024/1024) -------------------- 909.0625 SQL> select 2040-909.0625 from dual; 2040-909.0625 ------------- 1130.9375
看下不压缩的时候,备份速度和备份的大小。
RMAN> backup database format '/home/oracle/11204-%T-%U'; Starting backup at 05-DEC-13 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=25 device type=DISK channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00003 name=/u01/app/oracle/oradata/mining/undotbs01.dbf input datafile file number=00001 name=/u01/app/oracle/oradata/mining/system01.dbf input datafile file number=00002 name=/u01/app/oracle/oradata/mining/sysaux01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/mining/users01.dbf channel ORA_DISK_1: starting piece 1 at 05-DEC-13 channel ORA_DISK_1: finished piece 1 at 05-DEC-13 piece handle=/home/oracle/11204-20131205-01oqois9_1_1 tag=TAG20131205T130513 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:02:36 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set including current SPFILE in backup set channel ORA_DISK_1: starting piece 1 at 05-DEC-13 channel ORA_DISK_1: finished piece 1 at 05-DEC-13 piece handle=/home/oracle/11204-20131205-02oqoj15_1_1 tag=TAG20131205T130513 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 05-DEC-13 [oracle@mining ~]$ du -sh 11204* 931M 11204-20131205-01oqois9_1_1 9.4M 11204-20131205-02oqoj15_1_1
在没有压缩的情况下,用了2分36秒备份完,备份大小为931M。再看下启用压缩后,备份的时间和备份大小。在这里不得不提一下11gR2压缩备份的变化,在10g版本,压缩备份只有bzip2一种压缩算法,在11gR1版本,又引入了zlib算法,也就是11gR1版本有两种压缩备份方式bzip2和zlib,在11gR2版本,将压缩备份改成了BASIC基本压缩备份和高级压缩备份,而高级压缩备份又分为高中低三种级别,也就是在11gR2版本,可以有4种压缩备份方式的选择。下面就分别测试下这4中压缩方式的备份,默认是BASIC基本压缩备份。
RMAN> show COMPRESSION ALGORITHM; RMAN configuration parameters for database with db_unique_name MINING are: CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
先测试下默认的压缩方式BASIC,基本压缩备份。
RMAN> backup as compressed backupset full database format '/home/oracle/full-%s-%U.bak'; Starting backup at 05-DEC-13 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=16 device type=DISK channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00003 name=/u01/app/oracle/oradata/mining/undotbs01.dbf input datafile file number=00001 name=/u01/app/oracle/oradata/mining/system01.dbf input datafile file number=00002 name=/u01/app/oracle/oradata/mining/sysaux01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/mining/users01.dbf channel ORA_DISK_1: starting piece 1 at 05-DEC-13 channel ORA_DISK_1: finished piece 1 at 05-DEC-13 piece handle=/home/oracle/full-3-03oqoptc_1_1.bak tag=TAG20131205T150516 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55 channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set including current SPFILE in backup set channel ORA_DISK_1: starting piece 1 at 05-DEC-13 channel ORA_DISK_1: finished piece 1 at 05-DEC-13 piece handle=/home/oracle/full-4-04oqopv3_1_1.bak tag=TAG20131205T150516 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 05-DEC-13 [oracle@mining ~]$ du -sh full* 202M full-3-03oqoptc_1_1.bak 1.1M full-4-04oqopv3_1_1.bak
看来我的CPU很闲,而且I/O是备份的瓶颈,BASIC模式的压缩备份的时间比不启用压缩还要短,只需要55秒,备份文件202M。下面看下LOW级别的压缩。
RMAN> CONFIGURE COMPRESSION ALGORITHM 'LOW'; new RMAN configuration parameters: CONFIGURE COMPRESSION ALGORITHM 'LOW' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE; new RMAN configuration parameters are successfully stored RMAN> backup as compressed backupset full database format '/home/oracle/low-%s-%U.bak'; Starting backup at 05-DEC-13 allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=16 device type=DISK channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00003 name=/u01/app/oracle/oradata/mining/undotbs01.dbf input datafile file number=00001 name=/u01/app/oracle/oradata/mining/system01.dbf input datafile file number=00002 name=/u01/app/oracle/oradata/mining/sysaux01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/mining/users01.dbf channel ORA_DISK_1: starting piece 1 at 05-DEC-13 channel ORA_DISK_1: finished piece 1 at 05-DEC-13 piece handle=/home/oracle/low-5-05oqorn4_1_1.bak tag=TAG20131205T153604 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25 channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set including current SPFILE in backup set channel ORA_DISK_1: starting piece 1 at 05-DEC-13 channel ORA_DISK_1: finished piece 1 at 05-DEC-13 piece handle=/home/oracle/low-6-06oqornt_1_1.bak tag=TAG20131205T153604 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 05-DEC-13 [oracle@mining ~]$ du -sh low* 260M low-5-05oqorn4_1_1.bak 1.1M low-6-06oqornt_1_1.bak
LOW级别的压缩模式,备份只需要25秒,备份文件大小为260M。再看下MEDIUM级别的压缩。
RMAN> CONFIGURE COMPRESSION ALGORITHM 'MEDIUM'; old RMAN configuration parameters: CONFIGURE COMPRESSION ALGORITHM 'LOW' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE; new RMAN configuration parameters: CONFIGURE COMPRESSION ALGORITHM 'MEDIUM' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE; new RMAN configuration parameters are successfully stored RMAN> backup as compressed backupset full database format '/home/oracle/medium-%s-%U.bak'; Starting backup at 05-DEC-13 using channel ORA_DISK_1 channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00003 name=/u01/app/oracle/oradata/mining/undotbs01.dbf input datafile file number=00001 name=/u01/app/oracle/oradata/mining/system01.dbf input datafile file number=00002 name=/u01/app/oracle/oradata/mining/sysaux01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/mining/users01.dbf channel ORA_DISK_1: starting piece 1 at 05-DEC-13 channel ORA_DISK_1: finished piece 1 at 05-DEC-13 piece handle=/home/oracle/medium-7-07oqorvc_1_1.bak tag=TAG20131205T154028 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35 channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set including current SPFILE in backup set channel ORA_DISK_1: starting piece 1 at 05-DEC-13 channel ORA_DISK_1: finished piece 1 at 05-DEC-13 piece handle=/home/oracle/medium-8-08oqos0f_1_1.bak tag=TAG20131205T154028 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 05-DEC-13 [oracle@mining ~]$ du -sh medium* 215M medium-7-07oqorvc_1_1.bak 1.1M medium-8-08oqos0f_1_1.bak
中级的压缩模式,备份时间35秒,备份文件215M。再看下HIGH级别的压缩。
RMAN> CONFIGURE COMPRESSION ALGORITHM 'HIGH'; old RMAN configuration parameters: CONFIGURE COMPRESSION ALGORITHM 'MEDIUM' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE; new RMAN configuration parameters: CONFIGURE COMPRESSION ALGORITHM 'HIGH' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE; new RMAN configuration parameters are successfully stored RMAN> backup as compressed backupset full database format '/home/oracle/high-%s-%U.bak'; Starting backup at 05-DEC-13 using channel ORA_DISK_1 channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00003 name=/u01/app/oracle/oradata/mining/undotbs01.dbf input datafile file number=00001 name=/u01/app/oracle/oradata/mining/system01.dbf input datafile file number=00002 name=/u01/app/oracle/oradata/mining/sysaux01.dbf input datafile file number=00004 name=/u01/app/oracle/oradata/mining/users01.dbf channel ORA_DISK_1: starting piece 1 at 05-DEC-13 channel ORA_DISK_1: finished piece 1 at 05-DEC-13 piece handle=/home/oracle/high-9-09oqos5o_1_1.bak tag=TAG20131205T154352 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:02:55 channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set including current control file in backup set including current SPFILE in backup set channel ORA_DISK_1: starting piece 1 at 05-DEC-13 channel ORA_DISK_1: finished piece 1 at 05-DEC-13 piece handle=/home/oracle/high-10-0aoqosb8_1_1.bak tag=TAG20131205T154352 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 05-DEC-13 [oracle@mining ~]$ du -sh high* 1.1M high-10-0aoqosb8_1_1.bak 160M high-9-09oqos5o_1_1.bak
HIGH级别的压缩模式,耗时2分55秒,备份文件160M。下面是整理后的对比情况。
版本 | 数据文件大小 | 数据文件使用大小 | 压缩级别 | 备份时间 | 备份大小 | 压缩率 |
10.2.0.5.0 | 945(MB) | 529.75(MB) | 未压缩 | 15秒 | 404(MB) | |
bzip2 | 16秒 | 80(MB) | 19.8% | |||
11.2.0.4.0 | 2040(MB) | 1130.9375(MB) | 未压缩 | 2分36秒 | 931(MB) | |
BASIC | 55秒 | 202(MB) | 21.7% | |||
LOW | 25秒 | 260(MB) | 27.9% | |||
MEDIUM | 35秒 | 215(MB) | 23.1% | |||
HIGH | 2分55秒 | 160(MB) | 17.2% |
从实验结果看,并不一定使用压缩备份,备份的时间就会变长,在I/O能力不是很好的环境,压缩备份可以减少I/O,从而提升备份速率,当然这要根据不同的环境选择最适合自己的压缩级别。