Oracle Dataguard 下块自动修复技术

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.

在Oracle11gr2版本之后,若搭建实时应用日志的物理备库,那么在主库数据文件少量坏块的情况下,可以利用ABCR技术快速修复坏块

(一)
ABCR 功能是否开启由隐含参数 _auto_bmr 控制,默认为 ENABLE

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

(二)
DG同步状态,可以看到当前是一台物理备库

DGMGRL> show configuration

Configuration - orcl

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

Fast-Start Failover: DISABLED

Configuration Status:
SUCCESS

(三)
配置下测试环境

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

(四)
首先测试下在不开启ABCR功能的情况下,坏块是否可以自动修复

alter system set "_auto_bmr" = disabled;

搞破坏

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

查询报错

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'  

确认坏块的对象,并人为修复

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;

(五)
开启ABMR时又怎么样呢?

alter system set "_auto_bmr" = enabled;

搞破坏

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

查询没有报错

alter system flush buffer_cache;

select count(*) from baiyang.T_OBJS;

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

查看告警日志,自动修复坏块

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)

数据库块的修复方式还有有多种,如RMAN blockrecover、RMAN datafilerecover、DatabaseRecoveryAdvisor、DGswitchover等,ABCR无疑是最省心的一种,建议任何情况下都搭建ADG的主备架构,避免故障被触发概率。

上一篇:IDC:2015年中国*行业IT市场十大预测


下一篇:SQL Server自动化运维系列——监控跑批Job运行状态(Power Shell)