[Oracle] oracle 开启关闭Block Change Tracking


本文总阅读量

0、Block Change Tracking功能

默认情况下Block Change Tracking是被禁用的,该功能通过读取小的位图文件来决定哪个块改变了,在增量备份的过程中,开启这个功能可以避免扫面所有的数据文件,加快备份效率。

1、检查是否开启Block Change Tracking

1
2
3
4
5
6
7
19:38:00 SYS@ boston> COL STATUS   FORMAT A8
19:38:06 SYS@ boston> COL FILENAME FORMAT A60
19:38:08 SYS@ boston> SELECT STATUS, FILENAME FROM V$BLOCK_CHANGE_TRACKING;

STATUS FILENAME
-------- ------------------------------------------------------------
DISABLED

2、开启block change tracking

设置 DB_CREATE_FILE_DEST参数
SHOW PARAMETER DB_CREATE_FILE_DEST

1
2
3
4
19:38:28 SYS@ boston> SHOW PARAMETER DB_CREATE_FILE_DEST
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest string

如果db_create_file_dest参数没有设置,可以使用下面命令设置
ALTER SYSTEM SET DB_CREATE_FILE_DEST = '/home/oracle/' SCOPE=BOTH SID='*';

1
2
3
4
5
6
7
8
9
19:40:40 SYS@ boston> ALTER SYSTEM SET DB_CREATE_FILE_DEST = '/home/oracle/' SCOPE=BOTH SID='*';
System altered.

Elapsed: 00:00:00.12
19:41:48 SYS@ boston> SHOW PARAMETER DB_CREATE_FILE_DEST

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest string /home/oracle/

设置完成db_create_file_dest参数之后,开启block change tracking

ALTER DATABASE ENABLE BLOCK CHANGE TRACKING;

1
2
3
4
5
6
7
8
19:41:51 SYS@ boston> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING;
Database altered.
Elapsed: 00:00:04.49
19:44:18 SYS@ boston> SELECT STATUS, FILENAME FROM V$BLOCK_CHANGE_TRACKING;
STATUS FILENAME
-------- ------------------------------------------------------------
ENABLED /home/oracle/BOSTON/changetracking/o1_mf_gc678fqg_.chg
Elapsed: 00:00:00.00

如果没有指定db_create_file_dest参数,也可以在开启block change tracking参数时指定
ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE '/tmp/rman_change_track.f' REUSE;

1
2
3
4
5
6
7
8
9
10
11
19:46:20 SYS@ boston> ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;
Database altered.
Elapsed: 00:00:01.35
19:46:57 SYS@ boston> ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE '/tmp/rman_change_track.f' REUSE;
Database altered.
Elapsed: 00:00:05.02
19:47:03 SYS@ boston> SELECT STATUS, FILENAME FROM V$BLOCK_CHANGE_TRACKING;
STATUS FILENAME
-------- ------------------------------------------------------------
ENABLED /tmp/rman_change_track.f
Elapsed: 00:00:00.00

3、禁用Block Change Tracking

ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;

4、改变Block Change Tracking File位置

方法1:在不关闭数据库的情况下修改文件位置,可使用下面方法:

1
2
ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;
ALTER DATABASE ENABLE BLOCK CHANGE TRACKING USING FILE '/tmp/rman_change_track.f' REUSE;

这种方法会丢失已经存在的Block Change Tracking File,要想不丢失Block Change Tracking File需要使用下面方法

方法2:查看Block Change Tracking File原来的位置:

SELECT FILENAME FROM V$BLOCK_CHANGE_TRACKING;

1
2
3
4
19:52:19 SYS@ boston> SELECT FILENAME FROM V$BLOCK_CHANGE_TRACKING;
FILENAME
------------------------------------------------------------
/tmp/rman_change_track.f

关闭数据库
SHUTDOWN IMMEDIATE
操作系统下拷贝物理文件到新的目标路径
mv /tmp/rman_change_track.f /home/oracle/new_rman_change_track.f
启动数据库到mount
startup mount
修改Block Change Tracking File
ALTER DATABASE RENAME FILE '/tmp/rman_change_track.f' TO '/home/oracle/new_rman_change_track.f';
打开数据库
ALTER DATABASE OPEN;
查看Block Change Tracking File的文件路径

1
2
3
4
20:03:18 SYS@ boston> SELECT FILENAME FROM V$BLOCK_CHANGE_TRACKING;
FILENAME
----------------------------------------------------------------------------------------------------------------------------------
/home/oracle/new_rman_change_track.f
目录
  1. 1. 0、Block Change Tracking功能
  2. 2. 1、检查是否开启Block Change Tracking
  3. 3. 2、开启block change tracking
  4. 4. 3、禁用Block Change Tracking
  5. 5. 4、改变Block Change Tracking File位置

Proudly powered by Hexo and Theme by Lap
本站访客数人次
© 2020 zeven0707's blog