Auto repair technology of Oracle Dataguard

Posted by phpnewbie81 on Fri, 06 Dec 2019 11:48:32 +0100

Oracle Active Data Guard and Automatic Block Repair

Starting in Oracle Database 11g Release 2 (11.2), the primary database automatically attempts to repair the corrupted block in real time by fetching a good version of the same block from a physical standby database. This capability is referred to as automatic block repair, and it allows corrupt data blocks to be automatically repaired as soon as the corruption is detected. Automatic block repair reduces the amount of time that data is inaccessible due to block corruption. It also reduces block recovery time by using up-to-date good blocks in real-time, as opposed to retrieving blocks from disk or tape backups, or from Flashback logs.

After Oracle11gr2, if a physical backup database for real-time application logs is set up, then when there are a few bad blocks in the main database data file, ABCR technology can be used to quickly repair the bad blocks

(1)
Whether the ABCR function is enabled is controlled by the implicit parameter auto BMR, which is enabled by default

select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE    11.2.0.4.0      Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production

col NAME for a30
col VALUE for a30
col describ for a40 

SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ FROM x$ksppi x,x$ksppcv y
  WHERE x.inst_id = USERENV ('Instance')
   AND y.inst_id = USERENV ('Instance')
   AND x.indx = y.indx
   AND x.ksppinm LIKE '%_auto_bmr%';

NAME                           VALUE                          DESCRIB
------------------------------ ------------------------------ ----------------------------------------
_auto_bmr                      ENABLE                       enable/disable Auto BMR
_auto_bmr_req_timeout          60                             Auto BMR Requester Timeout
_auto_bmr_sess_threshold       30                             Auto BMR Request Session Threshold
_auto_bmr_pub_timeout          10                             Auto BMR Publish Timeout
_auto_bmr_fc_time              60                             Auto BMR Flood Control Time
_auto_bmr_bg_time              3600                           Auto BMR Process Run Time
_auto_bmr_sys_threshold        100                            Auto BMR Request System Threshold
_auto_bmr_max_rowno            1024                           x$krbabrstat Max number of rows

(two)
DG synchronization status, you can see that it is currently a physical standby database

DGMGRL> show configuration

Configuration - orcl

  Protection Mode: MaxPerformance
  Databases:
    orcl    - Primary database
    standby - Physical standby database

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS

(three)
Test environment under configuration

create table T_OBJS  as select * from all_objects ;
create index baiyang.idx_name on baiyang.T_OBJS(OBJECT_NAME);

select segment_name,header_file , header_block,blocks from dba_segments where OWNER ='BAIYANG' and  segment_name ='T_OBJS';

OWNER                          SEGMENT_NAME      HEADER_FILE HEADER_BLOCK     BLOCKS
------------------------------ ----------------- ----------- ------------ ----------
SYS                            T_OBJS                  4          300       1280

(four)
First, test whether the bad block can be automatically repaired without turning on the ABCR function

alter system set "_auto_bmr" = disabled;

Sabotage

dd if=/dev/zero of=/u01/app/oracle/oradata/orcl/users01.dbf bs=8192 seek=300 count=2 conv=notrunc

Query and report error

alter system flush buffer_cache;

select count(*) from baiyang.T_OBJS;
>  select count(*) from baiyang.T_OBJS  
>                               *  
> ERROR at line 1:  
> ORA-01578: ORACLE data block corrupted (file # 4, block # 300)  
> ORA-01110: data file 4: '/u01/app/oracle/oradata/orcl/users01.dbf'  

Identify the object of the bad block and fix it manually

sys@ORCL> select * from v$database_block_corruption;

     FILE#     BLOCK#     BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
         4        300          2                  0 ALL ZERO

RMAN> blockrecover datafile 4 block 301;
RMAN> blockrecover datafile 4 block 301;

(five)
What happens when ABMR is turned on?

alter system set "_auto_bmr" = enabled;

Sabotage

dd if=/dev/zero of=/u01/app/oracle/oradata/orcl/users01.dbf bs=8192 seek=400 count=2 conv=notrunc

sys@ORCL> select * from v$database_block_corruption;

     FILE#     BLOCK#     BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
         4        400          2                  0 ALL ZERO

No error in query

alter system flush buffer_cache;

select count(*) from baiyang.T_OBJS;

  COUNT(*)
----------
     84428

Check the alarm log and automatically repair the bad block

Wed Dec 05 15:55:59 2018
Automatic block media recovery successful for (file# 4, block# 401)
Automatic block media recovery successful for (file# 4, block# 402)

There are many ways to repair database blocks, such as RMAN blockrecover, RMAN datafilerecover, DatabaseRecoveryAdvisor, DGswitchover, etc. ABCR is undoubtedly the most convenient one. It is recommended to build the main and standby architecture of ADG in any case to avoid the probability of failure being triggered.

Topics: Database Oracle rman SQL