Using Block Change Tracking to Improve Incremental Backup Performance
使用块改变跟踪改善增量备份的性能
The block change tracking feature for incremental backups improves backup performance by recording changed blocks for each data file.
块改变跟踪特性通过记录每个数据文件的块改变来改善增量备份的性能
About Block Change Tracking
If block change tracking is enabled on a primary or standby database, then RMAN uses a block change tracking file to identify changed blocks for incremental backups. By reading this small bitmap file to determine which blocks changed, RMAN avoids having to scan every block in the data file that it is backing up.
如果块改变跟踪enabled在主或从数据库,RMAN就会使用块改变追踪文件来识别改变的块来增量备份。通过读取这个位图文件来决定哪些块被改变过,从而使得RMAN避免扫描全部数据文件进行增量备份。
Block change tracking is disabled by default. Nevertheless, the benefits of avoiding full data file scans during backup are considerable, especially if only a small percentage of data blocks are changed between backups. If your backup strategy involves incremental backups, then block change tracking is recommended. Block change tracking does not change the commands used to perform incremental backups. The change tracking file requires no maintenance after initial configuration.
块改变跟踪特性默认是disable。然而,在备份期间避免全数据文件扫描的优点是值得考虑的,尤其在只有小百分比数据块被改变的情况下。如果你的备份策略引入了增量备份,推荐使用块改变跟踪特性。块改变跟踪不改变执行增量备份的命令。在初始化配置之后不需要额外的维护。
You can only enable block change tracking at a physical standby database if a license for the Oracle Active Data Guard option is enabled.
Space Management in the Block Change Tracking File
块改变跟踪文件的空间管理
The change tracking file maintains bitmaps that mark changes in the datafiles between backups. The database performs a bitmap switch before each backup. Oracle Database automatically manages space in the change tracking file to retain block change data that covers the eight most recent backups. After the maximum of eight bitmaps is reached, the oldest bitmap is overwritten by the bitmap that tracks the current changes.
块改变跟踪文件会维护在数据文件标记改变的位图信息。Oracle自动管理改变跟踪文件的大小,保留最近8次的块改变信息,超过8次,最老的位图信息会被新的覆盖。
The first level 0 incremental backup scans the entire data file. Subsequent incremental backups use the block change tracking file to scan only the blocks that have been marked as changed since the last backup. An incremental backup can be optimized only when it is based on a parent backup that was made after the start of the oldest bitmap in the block change tracking file.
第一个0级增量备份会扫描全部数据文件。随后的增量备份就使用块改变跟踪文件来只扫描那些自上次备份以来标记改变的块。
Consider the eight-bitmap limit when developing your incremental backup strategy. For example, if you make a level 0 database backup followed by seven differential incremental backups, then the block change tracking file now includes eight bitmaps. If you then make a cumulative level 1 incremental backup, then RMAN cannot optimize the backup, because the bitmap corresponding to the parent level 0 backup is overwritten with the bitmap that tracks the current changes.
要考虑change tracking file 的8次限制与备份策略的关系。 如果我们在0级备份之后又进行了7次不同的增量备份,那么这时block change tracking 就包含了8个bitmaps信息。 如果我们在进行1级的增量备份,那么此时的增量就不是最优的, 还会扫描整个data file。 因为我们之前0级的bitmap信息被我们当前的bitmap 信息覆盖掉了,这样就没有了参考的依据。
所以RMAN的备份策略要考虑到这个8次bitmap 的影响。
Location of the Block Change Tracking File
块改变跟踪文件的位置
One block change tracking file is created for the whole database. By default, the change tracking file is created as an Oracle managed file in the destination specified by the DB_CREATE_FILE_DEST
initialization parameter. You can also place the change tracking file in any location that you choose, by specifying its name when enabling block change tracking. Oracle recommends against using a raw device (that is, a disk without a file system) as a change tracking file.
一个块改变跟踪文件针对整个数据库,默认,块改变跟踪文件作为oracle的管理文件,在初始化参数DB_CREATE_FILE_DEST指定的路径下。你也可以在enable块改变跟踪特性的时候,指定名字,自定义路径。Oracle不建议使用裸设备作为块改变跟踪文件的存放地。
Note:
In an Oracle RAC environment, the change tracking file must be located on shared storage accessible from all nodes in the cluster.
注意RAC环境,块跟踪文件必须放在共享存储,所有节点可以访问
RMAN does not support backup and recovery of the change tracking file. The database resets the change tracking file when it determines that the change tracking file is invalid. If you restore and recover the whole database or a subset, then the database resets the block change tracking file and starts tracking changes again. After you make a level 0 incremental backup, the next incremental backup can use change tracking data.
RMAN不支持备份和恢复块改变跟踪文件。当数据库发现块跟踪文件无效,数据库会重置块跟踪文件。如果你还原了数据库,块改变跟踪文件也会被重置,重新开始记录。
Size of the Block Change Tracking File
块改变跟踪文件的大小
The size of the block change tracking file is proportional to the size of the database and the number of enabled threads of redo. The size of the block change tracking file can increase and decrease as the database changes. The size is not related to the frequency of updates to the database.
块改变跟踪文件的大小是跟数据库的大小和线程数量成比例的。块改变文件会随着数据库的改变而增减。跟数据库跟新的频率没关系。
Typically, the space required for block change tracking for a single instance is approximately 1/30,000 the size of the data blocks to be tracked. For an Oracle RAC environment, it is 1/30,000 of the size of the database, times the number of enabled threads.
典型的,单例程环境,块改变跟踪文件大约需要数据块大小的1/30,000。RAC环境,再乘以thread数量
The following factors that may cause the file to be larger than this estimate suggests:
- To avoid the overhead of allocating space as your database grows, the block change tracking file size starts at 10 megabytes. New space is allocated in 10 MB increments. Thus, for any database up to approximately 300 gigabytes, the file size is no smaller than 10 MB, for up to approximately 600 gigabytes the file size is no smaller than 20 megabytes, and so on.
- 为了避免超出空间,初始大小是10Mb,新空间以10Mb增加。对于大约300GB的数据库,这个文件尺寸不超过10Mb,600GB,不小于20M ,等等
- For each data file, a minimum of 320 kilobytes of space is allocated in the block change tracking file, regardless of the size of the data file. Thus, if you have a large number of relatively small data files, the change tracking file is larger than for databases with a smaller number of larger data files containing the same data.
Enabling and Disabling Block Change Tracking
Enable和disable 块改变跟踪
You can enable block change tracking when the database is either open or mounted. This section assumes that you intend to create the block change tracking file as an Oracle Managed File in the database area, which is where the database maintains active database files such as data files, control files, and online redo log files. See "Overview of the Fast Recovery Area" to learn about the database area and fast recovery area.
To enable block change tracking:
- Start SQL*Plus and connect to a target database with administrator privileges.
- Ensure that the
DB_CREATE_FILE_DEST
initialization parameter is set.SHOW PARAMETER DB_CREATE_FILE_DEST
- If the parameter is not set, and if the database is open, then you can set the parameter with the following form of the
ALTER SYSTEM
statement:ALTER SYSTEM SET DB_CREATE_FILE_DEST = ‘/disk1/bct/‘ SCOPE=BOTH SID=‘*‘;
- Enable block change tracking.
Execute the following
ALTER DATABASE
statement:执行如下语句来enable块改变跟踪(使用默认的DB_CREATE_FILE_DEST指定路径)ALTER DATABASE ENABLE BLOCK CHANGE TRACKING;
You can also create the change tracking file in a location that you choose yourself by using the following form of SQL statement:也可以自定义块改变跟踪文件路径
ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE ‘/mydir/rman_change_track.f‘ REUSE;
The
REUSE
option tells Oracle Database to overwrite any existing block change tracking file with the specified name.REUSE选项是告诉数据库覆盖存在的指定的块改变文件
enable块改变跟踪后,可以在路径下看到生成的块改变跟踪文件,以及后台进程ctwr.
[[email protected] fff_arch]# ps -ef | grep ctwr
oracle 12554 1 0 10:23 ? 00:00:00 ora_ctwr_fff1
root 12598 8571 0 10:23 pts/2 00:00:00 grep ctwr
Disabling Block Change Tracking
This section assumes that the block change tracking feature is currently enabled. When you disable block change tracking, the database removes the block change tracking file from the operating system.
diable块改变跟踪,数据库会从操作系统移除块改变跟踪文件
To disable block change tracking:
- Start SQL*Plus and connect to a target database with administrator privileges.
- Ensure that the target database is mounted or open.
- Disable block change tracking.
Execute the following
ALTER DATABASE
statement:ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;
Checking Whether Change Tracking is Enabled
You can query the V$BLOCK_CHANGE_TRACKING
view to determine whether change tracking is enabled, and if it is, the file name of the block change tracking file.
查询V$BLOCK_CHANGE_TRACKING
视图查看块改变跟踪的状态及文件名
To determine whether change tracking is enabled:
Enter the following query in SQL*Plus (sample output included):
COL STATUS FORMAT A8 COL FILENAME FORMAT A60 SELECT STATUS, FILENAME FROM V$BLOCK_CHANGE_TRACKING; STATUS FILENAME -------- ------------------------------------------------------------ ENABLED /disk1/bct/RDBMS/changetracking/o1_mf_2f71np5j_.chg
Changing the Location of the Block Change Tracking File
移动块改变跟踪文件
To move the change tracking file, use the ALTER DATABASE RENAME FILE
statement. The database must be mounted. The statement updates the control file to refer to the new location and preserves the contents of the change tracking file. If you cannot shut down the database, then you can disable and enable block change tracking. In this case, you lose the contents of the existing block change tracking file.
移动块改变跟踪文件,必须在mount状态下,使用ALTER DATABASE RENAME FILE
命令。如果不能shutdown,那就通过先disable,在enable的办法,只是会丢失存在的块改变跟踪文件的内容。disable会连同跟踪文件一同被删掉。
To change the location of the change tracking file:
- Start SQL*Plus and connect to a target database.
- If necessary, determine the current name of the change tracking file:
SQL> SELECT FILENAME FROM V$BLOCK_CHANGE_TRACKING;
- If possible, shut down the database. For example:
SQL> SHUTDOWN IMMEDIATE
If you shut down the database, then skip to the next step. If you choose not to shut down the database, then execute the following SQL statements and skip all remaining steps:
SQL> ALTER DATABASE DISABLE BLOCK CHANGE TRACKING; SQL> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE ‘new_location‘;
In this case you lose the contents of the block change tracking file. Until the next time you complete a level 0 incremental backup, RMAN must scan the entire file.
- Using host operating system commands, move the change tracking file to its new location.
- Mount the database and move the change tracking file to a location that has more space. For example:
ALTER DATABASE RENAME FILE ‘/disk1/bct/RDBMS/changetracking/o1_mf_2f71np5j_.chg‘ TO ‘/disk2/bct/RDBMS/changetracking/o1_mf_2f71np5j_.chg‘;
This statement changes the location of the change tracking file while preserving its contents.
- Open the database:
SQL> ALTER DATABASE OPEN;
总结:启用block change tracking跟踪特性,会提升RMAN增量备份的性能,但也会带来一些额外的开销,所以是否启用该特性需要根据实际情况的考量。
本文参考:
[1] http://docs.oracle.com/cd/E11882_01/backup.112/e10642/rcmbckba.htm#BRADV89551
[2] http://blog.csdn.net/tianlesoftware/article/details/6997647
[3] RMAN 10g : How To Size the Block Change Tracking File (Doc ID 306112.1)