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'
確認壞塊的物件,並人為修復
[email protected]> 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
[email protected]> 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的主備架構,避免故障被觸發概率。