表有坏块时,全表查询会报错:
这时候如果有前面正常的rman备份,那么我们就可以通过rman备份直接对数据文件块做恢复
先对数据文件做个逻辑检查:
RMAN> backup check logical VALIDATE DATAFILE '+EXB_DATA/exb/datafile/cuteinfo.290.948015321';
Starting backup at 13-APR-22
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=65 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=00005 name=+EXB_DATA/exb/datafile/cuteinfo.290.948015321
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
---- ------ -------------- ------------ --------------- ----------
28 FAILED 0 355 1280 12504828
File Name: +EXB_DATA/exb/datafile/cuteinfo.290.948015321
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 775
Index 0 0
Other 1 150
或者直接检查数据文件:VALIDATE DATAFILE 5
检查完,我们可以通过视图查询到坏块信息
select * from v$database_block_corruption;
FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO CON_ID
---------- ---------- ---------- ------------------ --------- ----------
28 355424 1 0 CORRUPT 0
使用rman进行块恢复:
RMAN> blockrecover datafile 28 block 355424 from backupset;
Starting recover at 13-APR-22
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 00028
channel ORA_DISK_1: reading from backup piece /arch/backup/12c/full_0413_hi0qrt9h_1_1.bak
channel ORA_DISK_1: piece handle=/arch/backup/12c/full_0413_hi0qrt9h_1_1.bak tag=TAG20220413T164537
channel ORA_DISK_1: restored block(s) from backup piece 1
channel ORA_DISK_1: block restore complete, elapsed time: 00:00:01
starting media recovery
media recovery complete, elapsed time: 00:00:03
Finished recover at 13-APR-22
块恢复后,执行BLOCKRECOVER CORRUPTION LIST,会自动按照V$DATABASE_BLOCK_CORRUPTION进行修复(耗时较长):
RMAN> BLOCKRECOVER CORRUPTION LIST;
Starting recover at 13-APR-22
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 13-APR-22
个时候再访问v$database_block_corruption就看不到详细的坏块信息了:
SQL> select * from v$database_block_corruption;
no rows selected
再使用dbv检查发现没有坏块了。