For physically damaged data blocks, we can use the RMAN Block Media restoration (BLOCKMEDIARECOVERY) function to restore the damaged blocks without the need to restore the entire database or
For physically damaged data blocks, we can use the rman block media recovery function to restore the damaged blocks without the need to restore the entire database or
For physically damaged data blocks, we can use the block media recovery function of rman block media to restore the damaged blocks, instead of restoring the entire database or all files to fix these small amounts of damaged data blocks. Restoring the entire database or data file is not worth it because it is not a cannon used to fight mosquitoes! However, the premise is that you have to have an available RMAN backup, so anytime backup is everything. This article demonstrates the entire process of using RMAN to recover bad blocks.
Related reading:
Use the Duplicate function of RMAN to create a physical partition uard
Basic Oracle tutorial-copying a database through RMAN
Reference for RMAN backup policy formulation
RMAN backup learning notes
Oracle Database Backup encryption RMAN Encryption
1. Create a demo Environment
SQL> select * from v $ version where rownum <2;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0-Production
-- Create a data file for demonstration
SQL> create tablespace tbs_tmp datafile '/u02/database/usbo/oradata/tbs_tmp.dbf' size 10 m autoextend on;
SQL> conn scott/tiger;
-- Create an object tb_tmp based on the new data file
SQL> create table tb_tmp tablespace tbs_tmp as select * from dba_objects;
SQL> col file_name format a60
SQL> select file_id, file_name from dba_data_files where tablespace_name = 'tbs _ TMP ';
FILE_ID FILE_NAME
----------------------------------------------------------------------
6/u02/database/usbo/oradata/tbs_tmp.dbf
-- Information on the table object tb_tmp, including the corresponding file information, header blocks, and total number of blocks
SQL> select segment_name, header_file, header_block, blocks
2 from dba_segments
3 where segment_name = 'tb _ TMP 'and owner = 'Scott ';
SEGMENT_NAME HEADER_FILE HEADER_BLOCK BLOCKS
---------------------------------------------------------------
TB_TMP 6 130 1152
-- Use rman to back up the corresponding data file
$ ORACLE_HOME/bin/rman target/
RMAN> backup datafile 6 tag = health;
Starting backup at 2013/08/28 17:03:15
Allocated channel: ORA_DISK_1
Channel ORA_DISK_1: SID = 24 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 = 00006 name =/u02/database/usbo/oradata/tbs_tmp.dbf
Channel ORA_DISK_1: starting piece 1 at 2013/08/28 17:03:16
Channel ORA_DISK_1: finished piece 1 at 2013/08/28 17:03:17
Piece handle =/u02/database/usbo/fr_area/USBO/backupset/2013_08_28/o1_mf_nnndf_HEALTH_91vh6ntb _. bkp tag = HEALTH comment = NONE
Channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2013/08/28 17:03:17
RMAN> exit
2. restoration of damaged data blocks
-- The following uses the dd command in linux to damage a single data block.
[Oracle @ linux1 ~] $ Dd of =/u02/database/usbo/oradata/tbs_tmp.dbf bs = 8192 conv = notrunc seek = 130 <
> Upted block!
> EOF
0 + 1 records in
0 + 1 records out
17 bytes (17 B) copied, 0.000184519 seconds, 92.1 kB/s
-- Clear buffer cache
SQL> alter system flush buffer_cache;
-- Query table pair tb_tmp, receive ORA-01578
SQL> select count (*) from tb_tmp;
Select count (*) from tb_tmp
*
ERROR at line 1:
ORA-01578: ORACLE data block upted (file #6, block #130)
ORA-01110: data file 6: '/u02/database/usbo/oradata/tbs_tmp.dbf'
-- Query the view v $ database_block_partition uption, prompting that there are bad blocks. Note that this view may not return any data. If no data is returned, run backup validate first.
SQL> select * from v $ database_block_corruption;
FILE # BLOCK # BLOCKS upload uption_change # upload uptio
---------------------------------------------------------
6 129 1 0 slave upt
-- You can also use the dbv tool to verify Bad blocks. For details, refer:
-- Block recover is used to restore the damaged block.
RMAN> blockrecover datafile 6 blocks 130;
Starting recover at 2013/08/28 17:22:25
Using target database control file instead of recovery catalog
Allocated channel: ORA_DISK_1
Channel ORA_DISK_1: SID = 24 device type = DISK
Channel ORA_DISK_1: restoring block (s)
Channel ORA_DISK_1: specifying block (s) to restore from backup set
Restoring blocks of datafile 00006
Channel ORA_DISK_1: reading from backup piece/u02/database/usbo/fr_area/USBO/backupset/2013_08_28/o1_mf_nnndf_HEALTH_91vh6ntb _. bkp
Channel ORA_DISK_1: piece handle =/u02/database/usbo/fr_area/USBO/backupset/2013_08_28/o1_mf_nnndf_HEALTH_91vh6ntb _. bkp tag = HEALTH
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 17:22:31
-- Query the table tb_emp again.
SQL> select count (*) from tb_tmp;
COUNT (*)
----------
72449