As the databases keep growing, so does the space occupied by their backups. Fortunately, RMAN has built-in support to compress such large-sized backups which can be handy rather than using an OS utility such as TAR or so on. The following are the 3 kinds of compression techniques used by RMAN:
- Null compression
- Unused block compression
- Binary compression
RMAN uses block compression by default and that’s why you can’t set it off (or on either). Two modes of block compression are available, Unused Block Compression (UBC) and Null Block Compression (NBC). In NBC, all the empty blocks which were not used are skipped. This mode is always used in level 0 and for full backups. In UBC, blocks which are not used by any object are not read or included in the backups. Even the blocks which were used in the past but are empty now (for example, blocks after a truncate table or drop table operation) are skipped. Unlike NBC, which works for all the backups, UBC only works for disk-based backups and tape backups done with Oracle Secure Backup.
Since block level compression works out of the box, there is no special reason to mention it in the BACKUP command.
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 have never been 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.
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. Skipping unused data blocks where possible enables RMAN to back up datafiles using less space, and can make I/O more efficient. 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.
Unused Block Compression is done, if all of the following conditions apply:
- The COMPATIBLE initialization parameter is set to 10.2
- There are currently no guaranteed restore points defined for the database
- 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
- The backup set is being created on DISK
- backup is done to TAPE using “OSB” (Oracle Secure Backup)!
3. Binary Compression
Binary Compression can be done by specifying “AS COMPRESSED” clause in backup command, this compression is called as binary compression.
RMAN can apply a binary compression algorithm as it writes data to backup sets. This compression is similar to the compression provided by many tape vendors when backing up data to tape. But we cannot give exact percentage of compression. This binary compression algorithm can greatly reduce the space required for disk backup storage. It is typically 2x to 4x, and greater for text-intensive databases.
The command to take the compressed backup :
RMAN> backup as compressed backupset database;
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.
There is no special command to restore a database from the compressed backupsets, the restore command will be the same as with uncompressed backups. The restore from the compressed backpuset will take more time than uncompressed backupsets.
In addition to the existing binary compression of backup in Oracle 10G, RMAN 11G executable offers a wider range of compression levels with the Advanced Compression Option (ACO). The default compression algorithm setting is BASIC and does not require the Advanced Compression Option.
If, however, you have enabled the Oracle Database 11g Release 2 Advanced Compression Option, you can choose from the following compression levels:
- LOW – Least impact on backup throughput and suited for environments where CPU resources are the limiting factor.
- MEDIUM – Recommended for most environments. Good combination of compression ratios and speed
- HIGH – Best suited for backups over slower networks where the limiting factor is network speed
The following table summarizes all the compression modes:
|Compression Mode||Default||ACO Required||Backup size||CPU overhead|
|Basic||Yes||No||Small||between Medium to High|
Compression can be used for backupset of datafile, archive log and controlfiles. For example:
RMAN> backup as compressed backupset archivelog all; RMAN> backup as compressed backupset database; RMAN> backup as compressed backupset current controlfile;
RMAN compress the backupset contents before writing to disk. No extra decompression steps are required during recovery for rman compressed backup;
To configure the compression algorithm:
RMAN> CONFIGURE COMPRESSION ALGORITHM '[alg_name]';
Various Compression Types
For various compression types you can refer to V$RMAN_COMPRESSION_ALGORITHM view.
SQL> select ALGORITHM_NAME, ALGORITHM_DESCRIPTION, ALGORITHM_COMPATIBILITY from V$RMAN_COMPRESSION_ALGORITHM ; ALGORITHM_NAME ALGORITHM_DESCRIPTION ALGORITHM_COMPATIB --------------- ------------------------------------------------------------ ------------------ BZIP2 good compression ratio 126.96.36.199.0 BASIC good compression ratio 188.8.131.52.0 LOW maximum possible compression speed 184.108.40.206.0 ZLIB balance between speed and compression ratio 220.127.116.11.0 MEDIUM balance between speed and compression ratio 18.104.22.168.0 HIGH maximum possible compression ratio 22.214.171.124.0 6 rows selected.
Undo Block Compression/Optimization
Starting 11g, RMAN performs undo block optimization. In backup undo optimization, RMAN excludes undo not needed for recovery of a backup, that is, for transactions that have been committed. Undo optimization is only possible if:
- This is a backup set backup.
- Full or incremental level 0.
- Not a validate.
- Backup piece version is 11.0 or above.
- User has not disabled undo optimization with “_undo_block_compression = FALSE“
- Backup is going to DISK or OSB tape.
- No Guaranteed Restore Point (This check is enabled from 11.2 onwards).