一次坏块的处理过程

最近在一个数据库遇到了坏块,以下是处理过程。

一、坏块的发现及处理


首先是在做RMAN备份的时候,看到alert文件有坏块报错:
.......
Corrupt block relative dba: 0x00925026 (file 2, block 1200166)
Fractured block found during backing up datafile
Data in bad block:
type: 6 format: 2 rdba: 0x00925026
last change scn: 0x0578.15b7ebf7 seq: 0x1 flg: 0x06
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x33da0602
check value in block header: 0xf8d0
computed block checksum: 0xd82e
Reread of blocknum=1200166, file=+DATA/dwrac/datafile/dwdata_1m01.dbf. found same corrupt data
Reread of blocknum=1200166, file=+DATA/dwrac/datafile/dwdata_1m01.dbf. found same corrupt data
Reread of blocknum=1200166, file=+DATA/dwrac/datafile/dwdata_1m01.dbf. found same corrupt data
Reread of blocknum=1200166, file=+DATA/dwrac/datafile/dwdata_1m01.dbf. found same corrupt data
Reread of blocknum=1200166, file=+DATA/dwrac/datafile/dwdata_1m01.dbf. found same corrupt data
......

用dbv检查也证实了这一点。

[oracle@dwdb02 admin]$ dbv file="+DATA/dwrac/datafile/dwdata_1m01.dbf" start=502554 end=1217134 userid=admin/sdoadmin123 blocksize=16384

DBVERIFY: Release 10.2.0.5.0 - Production on Thu Feb 17 14:50:13 2011

Copyright (c) 1982, 2007, Oracle. All rights reserved.

DBVERIFY - Verification starting : FILE = +DATA/dwrac/datafile/dwdata_1m01.dbf
Page 502554 is marked corrupt
Corrupt block relative dba: 0x0087ab1a (file 2, block 502554)
Bad header found during dbv: 
Data in bad block:
type: 11 format: 2 rdba: 0x00800001
last change scn: 0x0000.00000000 seq: 0x1 flg: 0x04
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x00000b01
check value in block header: 0x85d8
computed block checksum: 0x0
......

DBVERIFY - Verification complete

Total Pages Examined : 714581
Total Pages Processed (Data) : 567369
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 143342
Total Pages Failing (Index): 0
Total Pages Processed (Other): 3866
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 0
Total Pages Marked Corrupt : 4
Total Pages Influx : 0
Highest block SCN : 0 (0.0)

10g以后rman备份发现的坏块信息可以在v$database_block_corruption查到。

SQL> select * from v$database_block_corruption;

FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTION_TYPE
---------- ---------- ---------- ------------------ ---------------
2 1217134 1 0 FRACTURED
508 2386314 1 0 FRACTURED
517 1115970 1 0 FRACTURED
2 1200166 1 0 FRACTURED
51 401698 1 0 FRACTURED
61 306642 1 0 FRACTURED
2 502554 1 0 FRACTURED
2 1213658 1 0 FRACTURED
34 701050 1 0 FRACTURED
60 347166 1 0 FRACTURED

FRACTURED意味着数据块是物理损坏,遇到这种情况,如果有备份的话最好是从备份恢复,甚至可以用rman做块级恢复,如
blockrecover datafile 2 block 1217134;
或者:
blockrecover corruption list;

不幸的是,这个数据库是一个新库,没有正式上线,也还没有上备份。没办法,只能看看损坏的对象是什么了。

--由于库太大,直接查dba_extents太慢,因此备份dba_extents到表dbextnet再查询。

SQL> select * from dbextent where file_id=2 and 1213658 between block_id and block_id+blocks-1;

OWNER SEGMENT_NAME PARTITION_NAME SEGMENT_TYPE TABLESPACE_NAME EXTENT_ID FILE_ID BLOCK_ID BYTES BLOCKS RELATIVE_FNO
------------------------------ -------------------------------------------------------------------------------- ------------------------------ ------------------ ------------------------------ ---------- ---------- ---------- ---------- ---------- ------------
CREATER_USER WIDGET_NEWUSE_IX2 INDEX DWDATA_1M 995 2 1213637 1048576 64 2

SQL> select * from dbextent where file_id=2 and 502554 between block_id and block_id+blocks-1;

OWNER SEGMENT_NAME PARTITION_NAME SEGMENT_TYPE TABLESPACE_NAME EXTENT_ID FILE_ID BLOCK_ID BYTES BLOCKS RELATIVE_FNO
------------------------------ -------------------------------------------------------------------------------- ------------------------------ ------------------ ------------------------------ ---------- ---------- ---------- ---------- ---------- ------------
CREATER_USER WIDGET_NEWUSE_IX2 INDEX DWDATA_1M 1787 2 502533 1048576 64 2


万幸的是,这里损坏的只是索引,把索引rebuild就可以。如果损坏的是表,则可能需要用到其他手段,如dbms_repare包来处理了。

SQL> alter index creater_user.WIDGET_NEWUSE_IX2 rebuild online parallel 16 tablespace dwdata_10m_1 nologging;

Index altered

......

注意:这里要用rebuild online,否则rebuild可能会读取原索引作为源来重建新索引,这样的话新建的索引也是损坏的。

全部处理完毕后,确认是否还有对象损坏。

SQL> select * from dba_extents E,v$database_block_corruption c where e.file_id=c.file# and c.block# between e.block_id and e.block_id+e.blocks-1;

OWNER SEGMENT_NAME PARTITION_NAME SEGMENT_TYPE TABLESPACE_NAME EXTENT_ID FILE_ID BLOCK_ID BYTES BLOCKS RELATIVE_FNO FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTION_TYPE
------------------------------ -------------------------------------------------------------------------------- ------------------------------ ------------------ ------------------------------ ---------- ---------- ---------- ---------- ---------- ------------ ---------- ---------- ---------- ------------------ ---------------

以上查询返回结果为空,表示没有数据库对象损坏,第一阶段处理完毕。

二、后续处理

上面的步骤解决了坏块对数据库的潜在影响,但是此时v$database_block_corruption的信息是还没有清除的,需要清除,需要再运行RMAN,如果没有坏块已经修复,才会从v$database_block_corruption删除对应记录。
但是在大部分情况下,即使删除了原来的对象,数据块的状态让人是标识损坏的,但是不影响一般的数据库操作,可以忽略。如果你看不顺眼或者担心它影响RMAN的备份,可以用以下方法格式化这个数据块,只有被正常格式化后,数据块状态才会恢复正常。

1. 首先创建一个新表

create table s (n number,c varchar2(4000)) nologging tablespace dwdata_1m;

注意表空间要指定在坏块所在的表空间上(v$database_block_corruption可查询到)

2. 确保目标数据块在free list上,并查询其大小
SQL> Select BYTES from dba_free_space where file_id=2 and 502554 between block_id and block_id + blocks -1;

BYTES
----------
1048576


3. 手工扩展

BEGIN
FOR I IN 1 .. 100000000
LOOP
EXECUTE IMMEDIATE 'alter table s allocate extent(size 1048576 datafile ''+DATA/dwrac/datafile/dwdata_1m01.dbf'')';
END LOOP;
END;

在这一步执行的同时,不断地查新dba_free_space,直至确认该数据块已经不在dba_free_space中了,之后就可以把上一步操作的循环中断。

SQL> Select * from dba_free_space where file_id= 2 and 502554 between block_id and block_id + blocks -1;

TABLESPACE_NAME FILE_ID BLOCK_ID BYTES BLOCKS RELATIVE_FNO
-------------------------------- ---------- ---------- ---------- ---------- ------------

4. 下一步就是要写里写入数据了

BEGIN
FOR i IN 1..1000000000 LOOP
INSERT /*+ APPEND */ INTO s select i, lpad('REFORMAT',3092, 'R') from dual connect by rownum<=10000;
commit ;
END LOOP;
END;
/

注意:必须要写入数据,数据块才能被重新格式化,才能修复块的状态。

5. 在写入数据的同时,不断用dbv检测坏块情况

--指定start和end参数,提高效率
[oracle@dwdb02 admin]$ dbv file="+DATA/dwrac/datafile/dwdata_1m01.dbf" start=502554 end=502554 userid=admin/sdoadmin123 blocksize=16384

DBVERIFY: Release 10.2.0.5.0 - Production on Thu Feb 17 15:56:53 2011

Copyright (c) 1982, 2007, Oracle. All rights reserved.

DBVERIFY - Verification starting : FILE = +DATA/dwrac/datafile/dwdata_1m01.dbf


DBVERIFY - Verification complete

Total Pages Examined : 714581
Total Pages Processed (Data) : 610675
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 100202
Total Pages Failing (Index): 0
Total Pages Processed (Other): 3704
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 0
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Highest block SCN : 0 (0.0)

如果Total Pages Marked Corrupt=0,则表示数据块已经修复了。此时就可以取消上一步的数据insert操作。

6. 用rman重新validate一次

RMAN> backup check logical validate datafile 2;

Starting backup at 17-FEB-11
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00508 name=+DATA/dwrac/datafile/dwdata_1m01.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:20:45
Finished backup at 17-FEB-11

正常的话,这一步完了以后,v$database_block_corruption里对应的坏块记录就应该被删除了。

SQL> select * from v$database_block_corruption t where file#=2 and block#=502554;

FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTION_TYPE
---------- ---------- ---------- ------------------ ---------------


重复上面的步骤直至v$database_block_corruption不包括任何数据。

以上只是坏块的处理过程,但是坏块产生的原因仍然不明朗,需进一步挖掘,但是从这些例子也可以看出备份的重要性!


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值