自动从备库修复主库的坏块

简介: 数据库的坏块经常是一件非常棘手的事情,Oracle数据库从11.2后,使用 Active Data Guard option 时,主库和备库可以自动借用对方的block来修复自身的坏块,这个过程对应用是透明的。

数据库的坏块经常是一件非常棘手的事情,Oracle数据库从11.2后,使用 Active Data Guard option 时,主库和备库可以自动借用对方的block来修复自身的坏块,这个过程对应用是透明的。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. Automatic block repair requires the use of the

Oracle Active Data Guard option. You can use an Oracle Active Data

Guard standby database for automatic repair of data corruptions

detected by the primary database. Additionally if the corruption is

discovered on an Active Data Guard physical standby database the

corruption will be automatically repaired with a good block from the

Primary. Both of these operations are transparent to the applications.

ALTER DATABASE DATAFILE 13 resize 2m;


create table aa tablespace ex1 as select * from dba_objects ;
dd if=/dev/zero of=/u01/app/oracle/oradata/orcl/ex1.dbf bs=8192 seek=10 count=2 conv=notrunc
RMAN> host 'dd if=/dev/zero of=/u01/app/oracle/oradata/orcl/ex1.dbf bs=8192 seek=10 count=2 conv=notrunc';
2+0 records in
2+0 records out
16384 bytes (16 kB) copied, 0.00015527 s, 106 MB/s
host command complete
RMAN> list failure;
Database Role: PRIMARY
no failures found that match specification
RMAN> validate datafile 15;
Starting validate at Sep 09 2020 18:16:41
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=14 device type=DISK
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00013 name=/u01/app/oracle/oradata/orcl/ex1.dbf
channel ORA_DISK_1: validation complete, elapsed time: 00:00:03
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
13   FAILED 1              1            130             2488395   
  File Name: /u01/app/oracle/oradata/orcl/ex1.dbf
  Block Type Blocks Failing Blocks Processed
  ---------- -------------- ----------------
  Data       0              0               
  Index      0              0               
  Other      1              127             
validate found one or more corrupt blocks
See trace file /u01/app/oracle/diag/rdbms/orcl/cdr1/trace/cdr1_ora_27031.trc for details
Finished validate at Sep 09 2020 18:16:45
RMAN> list failure;
Database Role: PRIMARY
List of Database Failures
=========================
Failure ID Priority Status    Time Detected        Summary
---------- -------- --------- -------------------- -------
2090       HIGH     OPEN      Sep 09 2020 18:16:44 Datafile 13: '/u01/app/oracle/oradata/orcl/ex1.dbf' contains one or more corrupt blocks
RMAN> advise failure;
Database Role: PRIMARY
List of Database Failures
=========================
Failure ID Priority Status    Time Detected        Summary
---------- -------- --------- -------------------- -------
2090       HIGH     OPEN      Sep 09 2020 16:43:42 Datafile 13: '/u01/app/oracle/oradata/orcl/ex1.dbf' contains one or more corrupt blocks
analyzing automatic repair options; this may take some time  
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=14 device type=DISK
analyzing automatic repair options complete
Mandatory Manual Actions
========================
1. No backup of block 100 in file 13 was found. Drop and re-create the associated object (if possible), or use the DBMS_REPAIR package to repair the block corruption
2. No backup of block 101 in file 13 was found. Drop and re-create the associated object (if possible), or use the DBMS_REPAIR package to repair the block corruption
3. Contact Oracle Support Services if the preceding recommendations cannot be used, or if they do not fix the failures selected for repair
Optional Manual Actions
=======================
1. Shut down, mount the database and try flush redo using ALTER SYSTEM FLUSH REDO TO 'standby name' command.  Then perform a Data Guard role change (failover).  Available standbys: orcl1by.
Automated Repair Options
========================
no automatic repair options available
RMAN> run{
allocate channel c1 type 'sbt_tape' parms='
SBT_LIBRARY=/opt/scutech/dbackup3/lib/libobk.so,
ENV=(URL=http://192.168.87.155:50306/d2/data/0d36020eecec11ea8000b49691622ac4/c7873e9aed0811ea8000b49691622ac4,
EXTRA=X-Access-Key:ea5350ac00fa61d08533a729da808de0)' trace=0;
blockrecover datafile 13 block 400 to 401;
}2> 3> 4> 5> 6> 7> 8> 
released channel: ORA_DISK_1
allocated channel: c1
channel c1: SID=14 device type=SBT_TAPE
channel c1: DBackup3 Oracle MMS Library
Starting recover at Sep 09 2020 16:46:46
channel c1: restoring block(s)
channel c1: specifying block(s) to restore from backup set
restoring blocks of datafile 00013
channel c1: reading from backup piece 6rva0apb_1_1
channel c1: piece handle=6rva0apb_1_1 tag=TAG20200909T164323
channel c1: restored block(s) from backup piece 1
channel c1: block restore complete, elapsed time: 00:00:01
starting media recovery
archived log for thread 1 with sequence 279 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_08/o1_mf_1_279_hogz5ylq_.arc
archived log for thread 1 with sequence 280 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_08/o1_mf_1_280_hoh3qxk1_.arc
archived log for thread 1 with sequence 281 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_08/o1_mf_1_281_hoh7bow0_.arc
archived log for thread 1 with sequence 282 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_09/o1_mf_1_282_hohw8y8y_.arc
archived log for thread 1 with sequence 283 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_09/o1_mf_1_283_hoj818t1_.arc
archived log for thread 1 with sequence 284 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_09/o1_mf_1_284_hojnjpd1_.arc
archived log for thread 1 with sequence 285 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_09/o1_mf_1_285_hok0g6kn_.arc
archived log for thread 1 with sequence 286 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_09/o1_mf_1_286_hok0gf3q_.arc
archived log for thread 1 with sequence 287 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_09/o1_mf_1_287_hok0gjb3_.arc
media recovery complete, elapsed time: 00:00:07
Finished recover at Sep 09 2020 16:47:00
Starting recover at Sep 09 2020 16:47:01
channel c1: restoring block(s)
channel c1: specifying block(s) to restore from backup set
restoring blocks of datafile 00013
channel c1: reading from backup piece 6rva0apb_1_1
channel c1: piece handle=6rva0apb_1_1 tag=TAG20200909T164323
channel c1: restored block(s) from backup piece 1
channel c1: block restore complete, elapsed time: 00:00:01
starting media recovery
archived log for thread 1 with sequence 279 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_08/o1_mf_1_279_hogz5ylq_.arc
archived log for thread 1 with sequence 280 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_08/o1_mf_1_280_hoh3qxk1_.arc
archived log for thread 1 with sequence 281 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_08/o1_mf_1_281_hoh7bow0_.arc
archived log for thread 1 with sequence 282 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_09/o1_mf_1_282_hohw8y8y_.arc
archived log for thread 1 with sequence 283 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_09/o1_mf_1_283_hoj818t1_.arc
archived log for thread 1 with sequence 284 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_09/o1_mf_1_284_hojnjpd1_.arc
archived log for thread 1 with sequence 285 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_09/o1_mf_1_285_hok0g6kn_.arc
archived log for thread 1 with sequence 286 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_09/o1_mf_1_286_hok0gf3q_.arc
archived log for thread 1 with sequence 287 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL/archivelog/2020_09_09/o1_mf_1_287_hok0gjb3_.arc
media recovery complete, elapsed time: 00:00:07
Finished recover at Sep 09 2020 16:47:14
released channel: c1
RMAN> list failure;
Database Role: PRIMARY
no failures found that match specification
RMAN>



切换数据库到active apply状态

select open_mode from v$database;
 alter database recover managed standby database cancel;
alter database open;
select open_mode from v$database;
 alter database recover managed standby database using current logfile disconnect;
 SQL> select open_mode from v$database;
OPEN_MODE
--------------------
MOUNTED
SQL>  alter database recover managed standby database cancel;
Database altered.
SQL> alter database open;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY
SQL>  alter database recover managed standby database using current logfile disconnect;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY WITH APPLY
SQL>




再测试




SQL> select count(*) from sys.aa
  2  ;
select count(*) from sys.aa
                         *
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 15, block # 10)
ORA-01110: data file 15: '/u01/app/oracle/oradata/orcl/ex1.dbf'
SQL> alter system flush buffer_cache;
System altered.
SQL> select count(*) from sys.aa;
  COUNT(*)
----------
     91475


在alert log里面有:


Reading datafile '/u01/app/oracle/oradata/orcl/ex1.dbf' for corruption at rdba: 0x03c0000b (file 15, block 11)
Reread (file 15, block 11) found same corrupt data (no logical check)
Automatic block media recovery requested for (file# 15, block# 11)
Wed Sep 09 19:29:41 2020
Automatic block media recovery successful for (file# 15, block# 11)
Wed Sep 09 19:29:41 2020
Automatic block media recovery successful for (file# 15, block# 11)


结论:

备库必须处于ADG的状态才能自动修复坏块


相关文章
|
Oracle 关系型数据库 数据库
实战篇:Oracle 数据坏块的 N 种修复方式
实战篇:Oracle 数据坏块的 N 种修复方式
实战篇:Oracle 数据坏块的 N 种修复方式
|
安全 关系型数据库 数据库
Postgresql 数据库用户权限授权(用户角色分配模式)
为了更方面和安全地管理数据库用户账号权限安全,实现通过用户角色代理的模式,实现用户账号功能授权的模式
19432 2
Postgresql 数据库用户权限授权(用户角色分配模式)
|
存储 SQL 监控
22 PostgreSQL 监控3PostgreSQL 性能快照和图形化分析工具 pg_stats_info 的使用|学习笔记
快速学习22 PostgreSQL 监控3PostgreSQL 性能快照和图形化分析工具 pg_stats_info 的使用
22 PostgreSQL 监控3PostgreSQL 性能快照和图形化分析工具 pg_stats_info 的使用|学习笔记
|
机器学习/深度学习 缓存 监控
linux查看CPU、内存、网络、磁盘IO命令
`Linux`系统中,使用`top`命令查看CPU状态,要查看CPU详细信息,可利用`cat /proc/cpuinfo`相关命令。`free`命令用于查看内存使用情况。网络相关命令包括`ifconfig`(查看网卡状态)、`ifdown/ifup`(禁用/启用网卡)、`netstat`(列出网络连接,如`-tuln`组合)以及`nslookup`、`ping`、`telnet`、`traceroute`等。磁盘IO方面,`iostat`(如`-k -p ALL`)显示磁盘IO统计,`iotop`(如`-o -d 1`)则用于查看磁盘IO瓶颈。
908 10
|
10月前
|
存储 网络协议 Nacos
高效搭建Nacos:实现微服务的服务注册与配置中心
Nacos(Dynamic Naming and Configuration Service)是阿里巴巴开源的一款动态服务发现、配置管理和服务管理平台。它旨在帮助开发者更轻松地构建、部署和管理分布式系统,特别是在微服务架构中。
1688 82
高效搭建Nacos:实现微服务的服务注册与配置中心
|
9月前
|
SQL Oracle 关系型数据库
如何在 Oracle 中配置和使用 SQL Profiles 来优化查询性能?
在 Oracle 数据库中,SQL Profiles 是优化查询性能的工具,通过提供额外统计信息帮助生成更有效的执行计划。配置和使用步骤包括:1. 启用自动 SQL 调优;2. 手动创建 SQL Profile,涉及收集、执行调优任务、查看报告及应用建议;3. 验证效果;4. 使用 `DBA_SQL_PROFILES` 视图管理 Profile。
|
SQL 关系型数据库 数据库
【一文搞懂PGSQL】4.逻辑备份和物理备份 pg_dump/ pg_basebackup
本文介绍了PostgreSQL数据库的备份与恢复方法,包括数据和归档日志的备份,以及使用`pg_dump`和`pg_basebackup`工具进行逻辑备份和物理备份的具体操作。通过示例展示了单库和单表的备份与恢复过程,并提供了错误处理方案。此外,还详细描述了如何利用物理备份工具进行数据损坏修复及特定时间点恢复(PITR)的操作步骤,以应对误操作导致的数据丢失问题。
|
运维 Kubernetes 安全
推荐3个开源好用的堡垒机
【7月更文挑战第11天】
4453 0
推荐3个开源好用的堡垒机
|
IDE Unix 开发工具
Solaris中查看硬件信息常用命令
Solaris中查看硬件信息常用命令
489 1
|
存储 SQL 关系型数据库
mysql查询数据库表大小怎么操作
mysql查询数据库表大小怎么操作
1899 0