对于数据块的损坏除了BBED方式恢复外,还可以通过RMAN的blockrecover块介质恢复功能来修复受损块,使用RMAN块介质恢复的前提是必须要有一个可以使用RMAN备份,因此备份重于一切,切记盖老师的教诲,呵呵。
1、创建演示环境
点击( 此处 )折叠或打开
2、数据块损坏的恢复处理过程
模拟块损坏,可以通过操作系统命令dd 对块写入, 也可以通过上篇博客中BBED工具对块进行更改,这里我们BBED方式
三、如何发现坏块和定位坏块的位置
3.1 通过DBV命令检查数据文件
点击( 此处 )折叠或打开
3.2 对坏块的数据访问,提示信息
点击( 此处 )折叠或打开
3.3 RMAN 备份时 数据块检查提示corrupt block
点击( 此处 )折叠或打开
3.4 接下来最重要的事情就是定位受损坏块的对象
点击( 此处 )折叠或打开
1、创建演示环境
点击( 此处 )折叠或打开
- SQL> create table tt (id number ,name varchar2(10)) tablespace tbs;
-
- Table created.
-
- SQL> insert into tt values (1,'AAAA');
-
- 1 row created.
-
- SQL> insert into tt values (2,'BBBB');
-
- 1 row created.
-
- SQL> commit;
-
- Commit complete.
-
SQL> col file_name for a50
SQL> select file_id ,file_name from dba_data_files where tablespace_name='TBS';
FILE_ID FILE_NAME
---------- --------------------------------------------------
11 /oracle/database/oradata/primary/tbs01.dbf -
- #通过RMAN对数据文件11或是database进行backup#
-
- RMAN> backup datafile 11;
Starting backup at 2016-07-22 21:49:54
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=27 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00011 name=/oracle/database/oradata/primary/tbs01.dbf
channel ORA_DISK_1: starting piece 1 at 2016-07-22 21:49:55
channel ORA_DISK_1: finished piece 1 at 2016-07-22 21:49:56
piece handle=/oracle/database/fast_recovery_area/PRIMARY/backupset/2016_07_22/o1_mf_nnndf_TAG20160722T214955_cs49439t_.bkp tag=TAG20160722T214955 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-07-22 21:49:56
Starting Control File and SPFILE Autobackup at 2016-07-22 21:49:56
piece handle=/opt/oracle/obak/controlc-1743469316-20160722-01 comment=NONE
Finished Control File and SPFILE Autobackup at 2016-07-22 21:49:57
- #记录对象TT的对应的文件信息、头部块、总块数#
- SQL> col segment_name for a40
- SQL> select segment_name,header_file,header_block,blocks
2 from dba_segments
3 where segment_name = 'TT' and owner = 'SCOTT';
SEGMENT_NAME HEADER_FILE HEADER_BLOCK BLOCKS
---------------------------------------- ----------- ------------ ----------
TT 11 130 8
模拟块损坏,可以通过操作系统命令dd 对块写入, 也可以通过上篇博客中BBED工具对块进行更改,这里我们BBED方式
点击(此处)折叠或打开
- #在上古神器BBED中指定file和block,查找到需要修改的内容
-
- BBED> find /c ABCD
File: /oracle/database/oradata/primary/tbs01.dbf (11)
Block: 131 Offsets: 8184 to 8191 Dba:0x02c00083
------------------------------------------------------------------------
41424344 01069d37
<32 bytes="" per="" line="">
BBED> modify /c ABCDGGG file 11 block 131 offset 8184
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /oracle/database/oradata/primary/tbs01.dbf (11)
Block: 131 Offsets: 8184 to 8191 Dba:0x02c00083
------------------------------------------------------------------------
41424344 47474737
<32 bytes="" per="" line="">
BBED> sum apply
Check value for File 11, Block 131:
current = 0x349c, required = 0x349c
BBED> verify
DBVERIFY - Verification starting
FILE = /oracle/database/oradata/primary/tbs01.dbf
BLOCK = 131
Block 131 is corrupt
Corrupt block relative dba: 0x02c00083 (file 0, block 131)
Fractured block found during verification
Data in bad block:
type: 6 format: 2 rdba: 0x02c00083
last change scn: 0x0000.004a379d seq: 0x1 flg: 0x06
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x37474747
check value in block header: 0x349c
computed block checksum: 0x0
DBVERIFY - Verification complete
Total Blocks Examined : 1
Total Blocks Processed (Data) : 0
Total Blocks Failing (Data) : 0
Total Blocks Processed (Index): 0
Total Blocks Failing (Index): 0
Total Blocks Empty : 0
Total Blocks Marked Corrupt : 1
Total Blocks Influx : 2
Message 531 not found; product=RDBMS; facility=BBED
BBED> -
- #在RMAN中验证datafile 11 ,在BBED中已经通过verify验证发现corrupt
-
RMAN> backup validate datafile 11;
Starting backup at 2016-07-22 23:06:25
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00011 name=/oracle/database/oradata/primary/tbs01.dbf
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
11 FAILED 0 1145 1280 4863898
File Name: /oracle/database/oradata/primary/tbs01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 1 5
Index 0 0
Other 0 130
validate found one or more corrupt blocks
See trace file /oracle/database/diag/rdbms/primary/primary/trace/primary_ora_117887.trc for details
Finished backup at 2016-07-22 23:06:26
/* - 在视图v$database_block_corruption 记录着自上一次备份以来损坏的数据块、在我们这里发现数据块损坏类型是FRACTURED ,其他类型是 CORRUPT、CHECKSUM 、ALL ZERO 、LOGICAL 五中类型
-
- CORRUPT - Block is wrongly identified or is not a data block (for example, the data block address is missing)
- CHECKSUM - optional check value shows that the block is not self-consistent. It is impossible to determine exactly why the check value fails, but it probably fails because sectors in the middle of the block are from different versions.
- FRACTURED - Block header looks reasonable, but the front and back of the block are different versions.
- ALL ZERO - Block header on disk contained only zeros. The block may be valid if it was never filled and if it is in an Oracle7 file. The buffer will be reformatted to the Oracle8 standard for an empty block.
- LOGICAL - Specifies the range is for logically corrupt blocks. CORRUPTION_CHANGE# will have a nonzero value.
-
- */
-
- SQL> select * from v$database_block_corruption;
- FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTION_TYPE
---------- ---------- ---------- ------------------ ------------------
11 131 1 0 FRACTURED
SQL>
- #实施blockrecover操作恢复
- RMAN> blockrecover corruption list;
Starting recover at 2016-07-22 23:11:31
using channel ORA_DISK_1
channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00011
channel ORA_DISK_1: reading from backup piece /oracle/database/fast_recovery_area/PRIMARY/backupset/2016_07_22/o1_mf_nnndf_TAG20160722T214955_cs49439t_.bkp
channel ORA_DISK_1: piece handle=/oracle/database/fast_recovery_area/PRIMARY/backupset/2016_07_22/o1_mf_nnndf_TAG20160722T214955_cs49439t_.bkp tag=TAG20160722T214955
channel ORA_DISK_1: restored block(s) from backup piece 1
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:02
starting media recovery
media recovery complete, elapsed time: 00:00:03
Finished recover at 2016-07-22 23:11:36 -
- 恢复完成后,表TT的内容可以访问
-
SQL> select * from tt; - ID NAME
---------- --------------------
1 ABCD
2 BBBB
3.1 通过DBV命令检查数据文件
点击( 此处 )折叠或打开
- [oracle@Primary ~]$ dbv file=/oracle/database/oradata/primary/tbs01.dbf
- DBVERIFY: Release 11.2.0.4.0 - Production on Fri Jul 22 23:37:19 2016
- Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
- DBVERIFY - Verification starting : FILE = /oracle/database/oradata/primary/tbs01.dbf
- Page 131 is influx - most likely media corrupt
- Corrupt block relative dba: 0x02c00083 (file 11, block 131)
- Fractured block found during dbv:
- Data in bad block:
- type: 6 format: 2 rdba: 0x02c00083
- last change scn: 0x0000.004a379d seq: 0x1 flg: 0x06
- spare1: 0x0 spare2: 0x0 spare3: 0x0
- consistency value in tail: 0x37474747
- check value in block header: 0x349c
- computed block checksum: 0x0
-
- DBVERIFY - Verification complete
- Total Pages Examined : 1280
- Total Pages Processed (Data) : 4
- Total Pages Failing (Data) : 0
- Total Pages Processed (Index): 0
- Total Pages Failing (Index): 0
- Total Pages Processed (Other): 130
- Total Pages Processed (Seg) : 0
- Total Pages Failing (Seg) : 0
- Total Pages Empty : 1145
- Total Pages Marked Corrupt : 1
- Total Pages Influx : 1
- Total Pages Encrypted : 0
- Highest block SCN : 4863898 (0.4863898)
- [oracle@Primary ~]$
点击( 此处 )折叠或打开
- SQL> select * from tt;
- select * from tt
- *
- ERROR at line 1:
- ORA-01578: ORACLE data block corrupted (file # 11, block # 131)
- ORA-01110: data file 11: '/oracle/database/oradata/primary/tbs01.dbf'
-
- SQL>
点击( 此处 )折叠或打开
- RMAN> backup database;
- Starting backup at 2016-07-22 23:41:54
- using channel ORA_DISK_1
- channel ORA_DISK_1: starting full datafile backup set
- channel ORA_DISK_1: specifying datafile(s) in backup set
- input datafile file number=00001 name=/oracle/database/oradata/primary/system01.dbf
- input datafile file number=00002 name=/oracle/database/oradata/primary/sysaux01.dbf
- input datafile file number=00005 name=/oracle/database/oradata/primary/perfstat.dbf
- input datafile file number=00004 name=/oracle/database/oradata/primary/users01.dbf
- input datafile file number=00003 name=/oracle/database/oradata/primary/undotbs01.dbf
- input datafile file number=00010 name=/oracle/database/oradata/primary/users.dbf
- input datafile file number=00011 name=/oracle/database/oradata/primary/tbs01.dbf
- input datafile file number=00006 name=/oracle/database/oradata/primary/enmo.dbf
- input datafile file number=00007 name=/oracle/database/oradata/primary/enmo01.dbf
- input datafile file number=00008 name=/oracle/database/oradata/primary/enmo02.dbf
- input datafile file number=00009 name=/oracle/database/oradata/primary/enmo003.dbf
- channel ORA_DISK_1: starting piece 1 at 2016-07-22 23:41:54
- RMAN-00571: ===========================================================
- RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
- RMAN-00571: ===========================================================
- RMAN-03009: failure of backup command on ORA_DISK_1 channel at 07/22/2016 23:41:57
- ORA-19566: exceeded limit of 0 corrupt blocks for file /oracle/database/oradata/primary/tbs01.dbf
点击( 此处 )折叠或打开
- SQL> start get_corrupt_block.sql;
- Enter value for file_id: 11
- old 3: WHERE file_id = &file_id
- new 3: WHERE file_id = 11
- Enter value for block_id: 131
- old 4: AND &block_id BETWEEN block_id AND block_id + blocks - 1
- new 4: AND 131 BETWEEN block_id AND block_id + blocks - 1
- TABLESPACE_NAME SEGMENT_TYPE OWNER SEGMENT_NAME PARTITION_NAME
------------------------------ ------------------------------ ------------------------------ ------------------------------ ------------------------------
TBS TABLE SCOTT TT
- SQL> host cat get_corrupt_block.sql
- set linesize 300
- col tablespace_name for a30
- col segment_type for a30
- col owner for a30
- col segment_name for a30
- col partition_name for a30
- SELECT tablespace_name, segment_type, owner, segment_name, partition_name
- FROM dba_extents
- WHERE file_id = &file_id
- AND &block_id BETWEEN block_id AND block_id + blocks - 1
- SQL>
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27039319/viewspace-2122399/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/27039319/viewspace-2122399/