如果自己搞不定可以找诗檀软件专业ORACLE数据库修复团队成员帮您恢复!
诗檀软件专业数据库修复团队
服务热线 : 13764045638 QQ号:47079569 邮箱:service@parnassusdata.com
损坏块的RMAN
在这种情况下,我们的数据库管理员Bob决定使用RMAN的块多媒体功能只恢复数据文件的损坏块。
首先,Bob检查了为本次损坏生成的alert.log 文件和一个跟踪文件,如下:
Hex dump of (file 4, block 76) in trace filec:\oracle\product\10.2.0\admin\db1\udump\db1_ora_2968.trc
Corrupt block relative dba: 0x0100004c (file 4, block 76)
Bad check value found during buffer read
Data in bad block:
type: 6 format: 2 rdba: 0x0100004c
last change scn: 0x0000.00086aeb seq: 0x3 flg: 0x06
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x6aeb0603
check value in block header: 0xa13a
computed block checksum: 0xb
Reread of rdba: 0x0100004c (file 4, block 76) found same corrupted data
通过打开写入到alert.log文件带有扩展名 .trc的跟踪文件,他获得更多信息:
Corrupt block relative dba: 0x0100004c (file 4, block 76)
Bad check value found during buffer read
Data in bad block:
type: 6 format: 2 rdba: 0x0100004c
last change scn: 0x0000.00086aeb seq: 0x3 flg: 0x06
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x6aeb0603
check value in block header: 0xa13a
computed block checksum: 0xb
Reread of rdba: 0x0100004c (file 4, block 76) found same corrupted data
为了获得更多信息,Bob 使用 dbv (dbverify) 实用工具获得所有损坏块的列表:
C:\>dbv file=c:\oracle\product\10.2.0\oradata\db1\users01.dbf
DBVERIFY: Release 10.2.0.1.0 – Production on Sat Oct 17 20:50:00 2015
Copyright (c) 1982, 2005, Oracle. All rights reserved.
DBVERIFY – Verification starting : FILE =c:\oracle\product\10.2.0\oradata\db1\USERS01.DBF
Page 76 is marked corrupt
Corrupt block relative dba: 0x0100004c (file 4, block 76)
Bad check value found during dbv:
Data in bad block:
type: 6 format: 2 rdba: 0x0100004c
last change scn: 0x0000.00086aeb seq: 0x3 flg: 0x06
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x6aeb0603
check value in block header: 0xa13a
computed block checksum: 0xb
DBVERIFY – Verification complete
Total Pages Examined : 640
Total Pages Processed (Data) : 29
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 2
Total Pages Failing (Index): 0
Total Pages Processed (Other): 35
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 573
Total Pages Marked Corrupt : 1
Total Pages Influx : 0
Highest block SCN : 551659 (0.551659)
C:\>
从上面的结果可以看出, Bob只有一个损坏块。
注释:如果损坏的数据块的数量不是太大,然后使用BLOCK RECOVER命令并指定损坏的块,如果有很多损坏的块我们不想 一一指定,那么你有另一个选择,运行backup 或 backup validate命令之后运行 blockrecover corruption list命令,一旦开始运行这些命令中的一个, v$database_block_corruption 视图就会被一系列损坏数据块填充。 |
然后Bob 运行了 backup validate命令,填充了v$database_block_corruption 视图:
SQL>
select * from
v$database_block_corruption;
no rows selected
RMAN> backup validate datafile 4;
SQL>
select * from
v$database_block_corruption;
FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
———- ———- ———- —————— ———
4 76 1 0 CHECKSUM
Bob使用第一种方法,通过运行 blockrecover 命令恢复损坏的块,如下:
RMAN> blockrecover datafile 4 block 76;
Starting blockrecover at 17-OCT-09
using target database control file instead of recovery catalog
channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00004
channel ORA_DISK_1: reading from backup piece
C:\ORACLE\product\10.2.0\flash_recovery_area\db1\backupset\2009_10_17\
o1_mf_nnndf_tag20091017t163201_5fmbsl9r_.bkp
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:02
starting media recovery
archive log thread 1 sequence 3 is already on disk as file
C:\ORACLE\product\10.2.0\flash_recovery_area\db1\archivelog\2009_10_17\
o1_mf_1_3_5fmbtrk2_.arc
………………
………………
media recovery complete, elapsed time: 00:00:01
Finished blockrecover at 17-OCT-09
RMAN>
SQL>
select * from
test_corruption;
STR
———-
Test
该命令从备份复原了具体的数据块,通过应用归档重做日志文件恢复数据文件。
注释: blockrecover 不再在 Oracle 11g中使用,块恢复的新的句法是recover?datafile? |
损坏数据块的RMAN
恢复该块的另一个选择是运行 blockrecover corruption list命令,该命令恢复写入到v$database_block_corruption视图的所有损坏数据块,从Oracle 11g开始,当任何进程或数据库实用工具遇到数据块损坏时v$database_block_corruption视图得到更新,另外,你可以使用validate datafile block 命令在具体的数据文件中验证特定的块。
这里, Bob 尝试使用该命令恢复损坏的块,如下:
RMAN> blockrecover corruption list;
restoring blocks of datafile 00004
……
……
starting media recovery
Finished blockrecover at 17-OCT-09
SQL>
select * from
test_corruption;
STR
———-
Test
正如我们看到的, blockrecover corruption list 命令恢复了所有损坏的数据块。
恢复多个数据文件的多个块是有可能的,使用表空间名和数据块地址 (DBA)恢复数据块也是有可能的,为进行检验,我们创建两个表空间和三个表,损坏所有的表,然后使用不同的方法恢复它们。
创建两个表空间和三个表:
SQL>
create
tablespace tbs_one datafile ‘c:\tbs_one.dbf’ SIZE 1M;
Tablespace created.
SQL>
create
tablespace tbs_two datafile ‘c:\tbs_two.dbf’ size 1M;0
Tablespace created.
SQL>
create
table tbl_one (str varchar2(10)) tablespace users;
Table created.
SQL>
drop
table tbl_one;
Table dropped.
SQL>
create
table tbl_one (str varchar2(10)) tablespace tbs_one;
Table created.
SQL>
create
table tbl_two (str varchar2(10)) tablespace tbs_two;
Table created.
SQL>
create
table tbl_three (str varchar2(10)) tablespace users;
Table created.
SQL>
insert into
tbl_one values(‘test’);
1 row created.
SQL> insert into
tbl_two values(‘test’);
1 row created.
SQL>
insert into
tbl_three values(‘test’);
1 row created.
SQL> commit;
Commit complete.
SQL>
RMAN> backup database plus archivelog;
你已经创建了带有三个表的表空间并备份了整个数据库,现在我们通过在十六进编辑器中打开并改变行的第一个字母(字母t)损坏三个所有的数据文件,保存文件并编辑。
为了查看损坏,从RMAN 运行backup validate database命令,检查 v$database_block_corrupton视图。
RMAN> backup validate database;
SQL>
select * from
v$database_block_corruption;
FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTION
———- ———- ———- —————— ———-
5 13 1 0 CHECKSUM
6 13 1 0 CHECKSUM
4 69 1 0 CHECKSUM
SQL>
select * from
tbl_one;
STR
———-
test
SQL> select * from
tbl_two;
STR
———-
test
SQL> select * from
tbl_three;
STR
———-
test
在这里,虽然你已经损坏了数据文件,但是你还是可以查询表,事实上,从数据库高速缓存缓冲区查询的行不是从数据文件,如果你刷新高速缓存缓冲区,你将不能查询表,因为现在我们直接从数据文件查询。
SQL> alter
system flush buffer_cache;
System altered.
SQL> select * from
tbl_one;
select * from tbl_one
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 5, block # 13)
ORA-01110: data file 5: ‘c:\tbs_one.dbf’
SQL> select * from
tbl_two;
select * from tbl_two
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 6, block # 13)
ORA-01110: data file 6: ‘c:\tbs_two.dbf’
SQL> select * from
tbl_three;
select * from tbl_three
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 4, block # 69)
ORA-01110: data file 4:
‘C:\ORACLE\product\10.2.0\oradata\db1\users01.dbf’
SQL>
现在铜鼓在一个命令行中使用数据文件参数恢复前两个表空间,使用表空间参数会恢复第三个表空间,现在恢复所有的损坏数据块:
RMAN> blockrecover datafile 5 block 13 datafile 6 block 13;
Starting blockrecover at 18-OCT-09
restoring blocks of datafile 00005
restoring blocks of datafile 00006
…………
…………
starting media recovery
media recovery complete, elapsed time: 00:00:03
Finished blockrecover at 18-OCT-09
RMAN>
正如显示的那样,使用一个命令恢复了两个不同的数据文件,现在使用有关写入到 alert.log文件的数据块地址 (DBA)的信息,恢复第三个表空间,这是 来自 alert.log文件的信息:
Hex dump of (file 4, block 69) in trace filec:\oracle\product\10.2.0\admin\db1\udump\db1_ora_2460.trc
Corrupt block relative dba: 0x01000045 (file 4, block 69)
Bad check value found during buffer read
Data in bad block:
type: 6 format: 2 rdba: 0x01000045
last change scn: 0x0000.00086381 seq: 0x3 flg: 0x06
spare1: 0x0 spare2: 0x0 spare3: 0x0
consistency value in tail: 0x63810603
check value in block header: 0xca6
computed block checksum: 0x56
Reread of rdba: 0x01000045 (file 4, block 69) found same corrupted data
Sun Oct 18 14:59:27 2015
Corrupt Block Found
tsn = 4, tsname = users
rfn = 4, blk = 69, rdba = 16777285
objn = 51349, objd = 51349, object = tbl_three, subobject =
segment owner = sys, segment type = Table Segment
Sun Oct 18 15:18:11 2015
损坏块的数据块号是16777285 ,它存在于用户表空间上,现在使用这些值,恢复损坏块,如下:
RMAN> blockrecover tablespace users dba 16777285;
Starting blockrecover at 18-OCT-09
using channel ORA_DISK_1
…………..
…………..
Finished blockrecover at 18-OCT-09
RMAN>
接下来,使用下列命令查询表,已检查损坏数据库块是否得以恢复:
SQL> select * from
tbl_one
2 union all
3 select * from
tbl_two
4 union all
5 select * from
tbl_three;
STR
———-
test
test
test
SQL>
Comment