青年数据库学习互助会

生产故障:oracle数据库坏块处理

IT数据库行业小学生,记录日常工作中数据库知识及一些故障案例,如有不对请指正,欢迎关注小编,小编微信xh870545795,CSDN:dba_notes
Image

在数据库中有一个概念叫做数据块的一致性,Oracle的数据块的一致性包括了两个层次:物理一致性和逻辑一致性,如果一个数据块在这两个层次上存在不一致性,那就对应到了物理坏块和逻辑坏块。
       在物理块损坏(也称为媒体损坏)中,数据库根本无法识别该块:校验和无效,块包含全零,块的页眉和页脚不匹配,或者关键数据块数据结构之一不正确等。在逻辑块损坏中,块的内容在物理上是健全的,并且通过了物理块检查;然而,该块在逻辑上可能不一致。逻辑损坏的示例包括行或索引条目的损坏。具体介绍请参考MOS文章:Physical and Logical Block Corruptions. All you wanted to know about it. (Doc ID 840978.1),本文主要介绍发生坏块故障时,如何修复。
一、现象
     客户一套12.1.0.2 rac数据库在做rman备份的时候报错如下:
Image
根据报错可以很明确看到,数据文件tbs_bffl_0566.dbf出现了坏块。
二、坏块修复
1.dbv检查坏块
dbv file='+DATAC1/DBM/DATAFILE/tbs_bffl_0566.dbf'
Image
Image

检查发现存在870988 871208两个坏块,可以通过rman继续查询坏块信息:

RMAN>backup validate datafile 721;
Image

RMAN VALIDATE后,错误信息会记录到v$database_block_corruption视图中,查询vdatabase_block_corruption视图:

select * from v$database_block_corruption;
Image

可看到有两个坏块,通过dba_extents查看坏块上的对象是什么

SELECT*FROM dba_extentsWHERE file_id =&AFNand&BL between block_id AND block_id + blocks -1;

问题到这里有个疑问,这个数据库有灾备环境,正常来说11g之后如果有灾备,可以自行修复坏块,为什么没自动修复呢?查询官网资料:https://docs.oracle.com/cd/E18283_01/server.112/e17022/manage_ps.htm#SBYDB00707,以下摘自官网说明:

9.2.1.5 Automatic Repair of Corrupt Data Blocks

A physical standby database operating in real-time query mode can also be used to repair corrupt data blocks in a primary database. If possible, any corrupt data block encountered when a primary database is accessed is automatically replaced with an uncorrupted copy of that block from a physical standby database operating in real-time query mode. Note that for this to work, the standby database must be synchronized with the primary database.

If a corrupt data block is discovered on a physical standby database, the server attempts to automatically repair the corruption by obtaining a copy of the block from the primary database if the following database initialization parameters are configured on the standby database:

  • The parameter is configured with a list and a parameter is configured for the primary databaseLOG_ARCHIVE_CONFIGDG_CONFIGLOG_ARCHIVE_DEST_n

    or

  • The parameter is configured and its value contains an Oracle Net service name for the primary databaseFAL_SERVER

If automatic repair is not possible, an error is returned.ORA-1578

总结起来就是

主库出现坏块自动用备库的块拷贝修复,要求有下:

standby 库需要 using current logfile。

备库出现坏块自动用主库的块修复,要求如下:

The LOG_ARCHIVE_CONFIG 参数配置了DG_CONFIG列表,且 LOG_ARCHIVE_DEST_n parameter is configured for the primary database ,或者:备库配置了 FAL_SERVER 指向主库。

经过检查发现adg配置不满足要求因此无法自动修复。由于客户生产端rman备份好久没成功,因此从灾备备份相应文件传输到主库修复。

2.灾备端备份相应数据文件

backup datafile 721format'/u01/app/oracle/rmanbk/721,bak';
Image

scp传输到主库。

3.主库修复

rman>catalog startwith'/u01/app/oracle/rmanbk';rman>blockrecover datafile 721 block 870988from backupset;rman>blockrecover datafile 721 block 871208from backupset;
Image

dbv检查:

dbv file='+DATAC1/DBM/DATAFILE/tbs_bffl_0566.dbf'
Image

至此修复完成,本次就分享到这里,如有不对,请指正!