Category - RMAN

RMAN - Block Change Tracking in Oracle 19c database

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
==========================
Block change tracking tracks data file blocks affected by each database update.

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.
Block change tracking feature is not reading the entire database blocks it just directly reads only changed blocks results in block change tracking file.

Advantages
===========
Enabling Oracle Block Change Tracking is recommended to improve the performance of incremental backups.  
By RMAN not having to scan every block in the database, the backup window will be smaller and infrastructure utilization reduced (CPU, IO).  
There is always certain risk to making any change, but in the context of most applications enabling block change tracking will be transparent.

About Space Management in the Block Change Tracking File
=======================================================
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.

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.

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.

Location of the Block Change Tracking File
=========================================
By default, the block 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 block change tracking file in any location that you choose, by specifying its name when enabling block change tracking.

One block change tracking file is created for the whole database. Oracle recommends against using a raw device (that is, a disk without a file system) as a change tracking file.

Note:
In an Oracle Real Application Clusters (Oracle RAC) environment, the change tracking file must be located on shared storage accessible from all nodes in the cluster.

NOTE
=====
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.

Enabling Block Change Tracking
==============================
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.

1=> Check if DB_CREATE_FILE_DEST is defined.

SQL> show parameter db_create_file_Dest

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest		     string	 +DATA


2=> Check if BCT is enable or NOT.

COL STATUS   FORMAT A8
COL FILENAME FORMAT A60
SELECT STATUS, FILENAME FROM   V$BLOCK_CHANGE_TRACKING;

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


3=> Let we Enable BCT as below. And check Background Process status CTWR .

SQL> alter database enable block change tracking ;

Database altered.

SQL> 
COL STATUS   FORMAT A8
COL FILENAME FORMAT A60
 
SELECT STATUS, FILENAME FROM   V$BLOCK_CHANGE_TRACKING;

STATUS	 FILENAME
-------- --------------------------------------
ENABLED  +DATA/DBSET/CHANGETRACKING/ctf.279.1115071067

Check status as ASM level .

ASMCMD> pwd
+DATA/DBSET/CHANGETRACKING

ASMCMD> ls 
ctf.279.1115071067
ASMCMD> 

SQL> select * from v$sgastat where name like '%CTWR%';

POOL	       NAME			       BYTES	 CON_ID
-------------- -------------------------- ---------- ----------
large pool     CTWR dba buffer	   1892352	      0

SQL> select sid,program,status from v$session where program like '%CTWR%';

       SID PROGRAM					    STATUS
---------- ------------------------------------------------ --------
       388 oracle@racnoden1.ace2oracle.lab (CTWR)	    ACTIVE


Disabling Block Change Tracking
===============================
When you disable block change tracking, the database removes the block change tracking file from the operating system.

This section assumes that the block change tracking feature is currently enabled.

To disable block change tracking:

SQL> ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;
Database altered.

SQL> COL STATUS   FORMAT A8
COL FILENAME FORMAT A60
SELECT STATUS, FILENAME FROM   V$BLOCK_CHANGE_TRACKING;SQL> SQL> SQL> 

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

SQL> exit

[oracle@racnoden1 ~]$ su - grid
[grid@racnoden1 ~]$ cd +DATA/DBSET/CHANGETRACKING
-bash: cd: +DATA/DBSET/CHANGETRACKING: No such file or directory

As we can see FOLDER is deleted as soon we DISABLED BCT.

Wait Event and Problems with BCT
===============================
There would be wait event of "block change tracking buffer space" seen in the instance where CKPT is stuck.There could be multiple reasons.

Please check Oracle Doc (Doc ID 2094946.1) for resolution.

Let we try to Delete
===================

=> Let we try to delete BCT File when DB services are UP - It can not be deletd

[grid@racsetn1 ~]$ asmcmd
ASMCMD> cd +DATA/TNT/CHANGETRACKING/
ASMCMD> ls
ctf.294.1115904457
ASMCMD> rm ctf.294.1115904457
ORA-15032: not all alterations performed
ORA-15028: ASM file '+DATA/TNT/CHANGETRACKING/ctf.294.1115904457' not dropped; currently being accessed (DBD ERROR: OCIStmtExecute)
ASMCMD> rm -rf ctf.294.1115904457
ORA-15032: not all alterations performed
ORA-15028: ASM file '+DATA/TNT/CHANGETRACKING/ctf.294.1115904457' not dropped; currently being accessed (DBD ERROR: OCIStmtExecute)

=> Now we will delete BCT file post shutting down database. - It is now  deletd

[oracle@racsetn1 bkp]$ srvctl Stop database -db TNT

[grid@racsetn1 ~]$ asmcmd
ASMCMD> cd  +DATA/TNT/CHANGETRACKING/
ASMCMD> ls
ctf.294.1115904457
ASMCMD> rm -rf ctf.294.1115904457
ASMCMD> exit
[grid@racsetn1 ~]$

Steps if Block Change Tracking File DELETED
=============================

=> If we try to start database in ABSENCE of BCT file which was DELETED Forcefully we will get below error.

[oracle@racsetn1 bkp]$ srvctl Start database -db TNT
PRCR-1079 : Failed to start resource ora.tnt.db
CRS-5017: The resource action "ora.tnt.db start" encountered the following error:
ORA-19751: could not create the change tracking file
ORA-19750: change tracking file: '+DATA/TNT/CHANGETRACKING/ctf.294.1115904457'
ORA-17502: ksfdcre:4 Failed to create file +DATA/TNT/CHANGETRACKING/ctf.294.1115904457
ORA-15046: ASM file name '+DATA/TNT/CHANGETRACKING/ctf.294.1115904457' is not in single-file creation form
ORA-17503: ksfdopn:2 Failed to open file +DATA/TNT/CHANGETRACKING/ctf.294.1115904457
ORA-15012: ASM file '+DATA/TNT/CHANGETRACKING/ctf.294.1115904457' does not exist
. For details refer to "(:CLSN00107:)" in "/grid_home/app/oracle/diag/crs/racsetn2/crs/trace/crsd_oraagent_oracle.trc".

CRS-2674: Start of 'ora.tnt.db' on 'racsetn2' failed
CRS-2632: There are no more servers to try to place resource 'ora.tnt.db' on that would satisfy its placement policy
CRS-5017: The resource action "ora.tnt.db start" encountered the following error:
ORA-19751: could not create the change tracking file
ORA-19750: change tracking file: '+DATA/TNT/CHANGETRACKING/ctf.294.1115904457'
ORA-17502: ksfdcre:4 Failed to create file +DATA/TNT/CHANGETRACKING/ctf.294.1115904457
ORA-15046: ASM file name '+DATA/TNT/CHANGETRACKING/ctf.294.1115904457' is not in single-file creation form
ORA-17503: ksfdopn:2 Failed to open file +DATA/TNT/CHANGETRACKING/ctf.294.1115904457
ORA-15012: ASM file '+DATA/TNT/CHANGETRACKING/ctf.294.1115904457' does not exist
. For details refer to "(:CLSN00107:)" in "/grid_home/app/oracle/diag/crs/racsetn1/crs/trace/crsd_oraagent_oracle.trc".

CRS-2674: Start of 'ora.tnt.db' on 'racsetn1' failed
[oracle@racsetn1 bkp]$

=>Error in Alert log as below

This instance was first to open
CHANGE TRACKING is enabled for this database, but the
change tracking file can not be found. Recreating the file.
2022-09-20T15:29:32.255026+05:30
Errors in file /ora_home/app/oracle/diag/rdbms/tnt/TNT1/trace/TNT1_ora_25787.trc:
ORA-19751: could not create the change tracking file
ORA-19750: change tracking file: '+DATA/TNT/CHANGETRACKING/ctf.294.1115904457'
ORA-17502: ksfdcre:4 Failed to create file +DATA/TNT/CHANGETRACKING/ctf.294.1115904457
ORA-15046: ASM file name '+DATA/TNT/CHANGETRACKING/ctf.294.1115904457' is not in single-file creation form
ORA-17503: ksfdopn:2 Failed to open file +DATA/TNT/CHANGETRACKING/ctf.294.1115904457
ORA-15012: ASM file '+DATA/TNT/CHANGETRACKING/ctf.294.1115904457' does not exist
ORA-19751 signalled during: ALTER DATABASE OPEN /* db agent *//* {1:4602:3357} */...
2022-09-20T15:29:34.695545+05:30
License high water mark = 1
2022-09-20T15:29:34.695803+05:30

=> So in this case we need to Disable Block Change Tracking and start database.

[oracle@racsetn1 bkp]$ sqlplus "/as sysdba"

SQL> startup mount;
ORACLE instance started.

Total System Global Area 2751463160 bytes
Fixed Size            8900344 bytes
Variable Size          637534208 bytes
Database Buffers     2097152000 bytes
Redo Buffers            7876608 bytes
Database mounted.
SQL> ALTER DATABASE DISABLE BLOCK CHANGE TRACKING;

Database altered.

SQL> shut immediate;
ORA-01109: database not open
Database dismounted.

[oracle@racsetn1 bkp]$ srvctl Start database -db TNT