enable or disable Oracle block change tracking
Oracle的block change tracking用于记录上次备份以来改变过的block信息,因此打开block change tracking可以大大加快增量备份的速度。
1. Enable block change tracking
1.1 检查数据库是否已经开启了block change tracking
SQL> set linesize 120
SQL> col filename format a60
SQL> SELECT filename, status, bytes FROM v$block_change_tracking;FILENAME STATUS BYTES
------------------------------------------------------------ ---------- ----------
DISABLEDdisabled 表示未启用
1.2 开启block change tracking
SQL> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE '+DATA_DG01/beiacce/block_change_tracking.log';
Database altered.
1.3 确认block change tracking已开启
SQL> SELECT filename, status, bytes FROM v$block_change_tracking;
FILENAME STATUS BYTES
------------------------------------------------------------ ---------- ----------
+DATA_DG01/beiacce/block_change_tracking.log ENABLED 53542912
备注:启动block change tracking时,oracle会启动一个CTWR的后台进程,这个进程的作用就是把信息写入block change tracking文件。如果是RAC系统,oracle会在每个实例上都启动这个后台进程。启动CTWR进程的信息记录在alert文件中。
……
Fri Aug 16 09:38:08 2013
ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE '+DATA_DG01/beiacce/block_change_tracking.log'
Fri Aug 16 09:38:09 2013
Block change tracking file is current.
Fri Aug 16 09:38:10 2013
Starting background process CTWR
CTWR started with pid=92, OS id=20330
Block change tracking service is active.
Fri Aug 16 09:38:11 2013
Completed: ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE '+DATA_DG01/beiacce/block_change_tracking.log'……
2. Disable block change tracking
1.1 检查数据库是否已经开启了block change tracking
SQL> SELECT filename, status, bytes FROM v$block_change_tracking;
FILENAME STATUS BYTES
------------------------------------------------------------ ---------- ----------
+DATA_DG01/beiacce/block_change_tracking.log ENABLED 53542912
1.2 关闭block change tracking
SQL> ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;
Database altered.
1.3 确认block change tracking已关闭
SQL> SELECT filename, status, bytes FROM v$block_change_tracking;
FILENAME STATUS BYTES
------------------------------------------------------------ ---------- ----------
DISABLED
备注:关闭block change tracking时,oracle会停止后台进程CTWR,停止CTWR进程的信息记录在alert文件中。另外需要注意一下,关闭block change tracking时,block change tracking文件是否也同时被删除了。如果没有被删除,可能需要执行手工删除。
……
Fri Aug 16 09:39:21 2013
ALTER DATABASE DISABLE BLOCK CHANGE TRACKING
Fri Aug 16 09:39:22 2013
Block change tracking service stopping.
Fri Aug 16 09:39:22 2013
Stopping background process CTWR
Fri Aug 16 09:39:23 2013
WARNING: Cannot delete file +DATA_DG01/beiacce/block_change_tracking.log
Fri Aug 16 09:39:23 2013
Errors in file /app/oracle/admin/BEIACCE/udump/beiacce1_ora_18564.trc:
ORA-01265: Unable to delete CHANGE TRACKING +DATA_DG01/beiacce/block_change_tracking.log
ORA-15028: ASM file '+DATA_DG01/beiacce/block_change_tracking.log' not dropped; currently being accessed
Completed: ALTER DATABASE DISABLE BLOCK CHANGE TRACKING……
alert日志表明删除block change tracking文件没有成功,原因是文件正被使用。使用这个文件的进程基本上就是2个,一个是CTWR,另一个就是RMAN备份。从alert日志中可以看出,停止block change tracking时是先停CTWR进程,再删除文件。因此占用这个文件的进程不太可能是CTWR,十有八九是备份进程。
删除block change tracking文件(ASM)
$> export ORACLE_SID=+ASM1
$> sqlplus "/as sysdba"SQL*Plus: Release 10.2.0.4.0 - Production on Fri Aug 16 09:48:53 2013
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing optionsSQL> alter diskgroup DATA_DG01 drop file '+DATA_DG01/beiacce/block_change_tracking.log';
Diskgroup altered.
如果没删除block change tracking文件,下次开启block change tracking又使用的是同一文件,会报以下错误:
SQL> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE '+DATA_DG01/beiacce/block_change_tracking.log';
ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE '+DATA_DG01/beiacce/block_change_tracking.log'
*
ERROR at line 1:
ORA-19751: could not create the change tracking file
ORA-19750: change tracking file: '+DATA_DG01/beiacce/block_change_tracking.log'
ORA-17502: ksfdcre:4 Failed to create file +DATA_DG01/beiacce/block_change_tracking.log
ORA-15005: name "beiacce/block_change_tracking.log" is already used by an existing alias
如果出现这种情况,可以在sql语句中加个reuse来重用已经存在的文件。即:
ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE '+DATA_DG01/beiacce/block_change_tracking.log' reuse;