This document will detail a block media recovery scenario using a RMAN disk based backup. If you need a document for configuring RMAN see the post Setting up RMAN for backup and recovery using Database Control
Scenario:
You receive an email from a user reporting the error below when attempting to access a table.
SQL> select * from payroll; select * from payroll * ERROR at line 1: ORA-01578: ORACLE data block corrupted (file # 6, block # 1291) ORA-01110: data file 6: '/u02/app/oracle/oradata/orcl/test.dbf' SQL>
Action:
Since we have the file number and the corrupted block number we can use RMAN to perform block media recovery on the file. Note that the database can remain open during block media recovery. Below is the output from using the blockrecover
command in RMAN.
[oracle@ora1 ~]$ rman Recovery Manager: Release 11.2.0.1.0 - Production on Wed Apr 21 10:23:11 2010 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. RMAN> connect target / connected to target database: ORCL (DBID=1239150297) RMAN> blockrecover datafile 6 block 1291; Starting recover at 21-APR-10 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=40 device type=DISK allocated channel: ORA_DISK_2 channel ORA_DISK_2: SID=38 device type=DISK searching flashback logs for block images until SCN 1339488 finished flashback log search, restored 0 blocks 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 /u03/app/oracle/oradata/orcl/backup/1clblq5q_1_1 channel ORA_DISK_1: piece handle=/u03/app/oracle/oradata/orcl/backup/1clblq5q_1_1 tag=TAG20100421T084546 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:01 Finished recover at 21-APR-10 RMAN>
Now we can check the table again and see that the corrupt block has been fixed.
SQL> select count(*) from payroll; COUNT(*) ---------- 5 SQL>
Note: When you discover a corrupted block you should check all datafiles for corruption as there could be other corrupted blocks. You can use the dbverify utility or perform a RMAN backup of the entire database. RMAN will exit with an error when a corrupt block is found.
[oracle@ora1 ~]$ rman Recovery Manager: Release 11.2.0.1.0 - Production on Wed Apr 21 10:32:19 2010 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. RMAN> connect target / connected to target database: ORCL (DBID=1239150297) RMAN> backup database plus archivelog delete input; Starting backup at 21-APR-10 current log archived using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=47 device type=DISK allocated channel: ORA_DISK_2 channel ORA_DISK_2: SID=38 device type=DISK channel ORA_DISK_1: starting archived log backup set channel ORA_DISK_1: specifying archived log(s) in backup set input archived log thread=1 sequence=10 RECID=18 STAMP=716898757 channel ORA_DISK_1: starting piece 1 at 21-APR-10 channel ORA_DISK_1: finished piece 1 at 21-APR-10 piece handle=/u03/app/oracle/oradata/orcl/backup/1hlbm0e6_1_1 tag=TAG20100421T103238 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 channel ORA_DISK_1: deleting archived log(s) archived log file name=/u02/app/oracle/oradata/orcl/arch/1_10_716298144.dbf RECID=18 STAMP=716898757 Finished backup at 21-APR-10 Starting backup at 21-APR-10 using channel ORA_DISK_1 using channel ORA_DISK_2 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=/u02/app/oracle/oradata/orcl/system01.dbf input datafile file number=00007 name=/u03/app/oracle/oradata/orcl/dbfs01.dbf input datafile file number=00002 name=/u02/app/oracle/oradata/orcl/sysaux01.dbf channel ORA_DISK_1: starting piece 1 at 21-APR-10 channel ORA_DISK_2: starting full datafile backup set channel ORA_DISK_2: specifying datafile(s) in backup set input datafile file number=00003 name=/u02/app/oracle/oradata/orcl/undotbs01.dbf input datafile file number=00005 name=/u02/app/oracle/oradata/orcl/example01.dbf input datafile file number=00006 name=/u02/app/oracle/oradata/orcl/test.dbf channel ORA_DISK_2: starting piece 1 at 21-APR-10 RMAN-03009: failure of backup command on ORA_DISK_2 channel at 04/21/2010 10:32:55 ORA-19566: exceeded limit of 0 corrupt blocks for file /u02/app/oracle/oradata/orcl/test.dbf continuing other job steps, job failed will not be re-run channel ORA_DISK_2: starting full datafile backup set channel ORA_DISK_2: specifying datafile(s) in backup set input datafile file number=00004 name=/u02/app/oracle/oradata/orcl/users01.dbf channel ORA_DISK_2: starting piece 1 at 21-APR-10 channel ORA_DISK_2: finished piece 1 at 21-APR-10 piece handle=/u03/app/oracle/oradata/orcl/backup/1klbm0eo_1_1 tag=TAG20100421T103240 comment=NONE channel ORA_DISK_2: backup set complete, elapsed time: 00:00:15 channel ORA_DISK_1: finished piece 1 at 21-APR-10 piece handle=/u03/app/oracle/oradata/orcl/backup/1ilbm0e8_1_1 tag=TAG20100421T103240 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:01:51 RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of backup plus archivelog command at 04/21/2010 10:34:31 RMAN-03009: failure of backup command on ORA_DISK_2 channel at 04/21/2010 10:32:55 ORA-19566: exceeded limit of 0 corrupt blocks for file /u02/app/oracle/oradata/orcl/test.dbf RMAN> RMAN>
The backup failed because RMAN detected at least 1 corrupt block in the file /u02/app/oracle/oradata/orcl/test.dbf
. That is the only file that has corrupt blocks. Unfortunately RMAN does not tell us how many blocks or which blocks are corrupt. The dbverify
utility will tell you how many blocks are corrupt and identify the block numbers.
[oracle@ora1 ~]$ dbv file=/u02/app/oracle/oradata/orcl/test.dbf DBVERIFY: Release 11.2.0.1.0 - Production on Wed Apr 21 10:50:59 2010 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. DBVERIFY - Verification starting : FILE = /u02/app/oracle/oradata/orcl/test.dbf Page 1292 is marked corrupt Corrupt block relative dba: 0x0180050c (file 6, block 1292) Bad header found during dbv: Data in bad block: type: 67 format: 7 rdba: 0x6e697470 last change scn: 0x7369.68742067 seq: 0x20 flg: 0x62 spare1: 0x72 spare2: 0x75 spare3: 0x6b63 consistency value in tail: 0x00000001 check value in block header: 0x6f6c block checksum disabled Page 1296 is marked corrupt Corrupt block relative dba: 0x01800510 (file 6, block 1296) Bad header found during dbv: Data in bad block: type: 99 format: 7 rdba: 0x69747075 last change scn: 0x6968.7420676e seq: 0x73 flg: 0x20 spare1: 0x72 spare2: 0x72 spare3: 0x636f consistency value in tail: 0x00000001 check value in block header: 0x6c62 block checksum disabled DBVERIFY - Verification complete Total Pages Examined : 1440 Total Pages Processed (Data) : 1037 Total Pages Failing (Data) : 0 Total Pages Processed (Index): 0 Total Pages Failing (Index): 0 Total Pages Processed (Other): 249 Total Pages Processed (Seg) : 0 Total Pages Failing (Seg) : 0 Total Pages Empty : 152 Total Pages Marked Corrupt : 2 Total Pages Influx : 0 Total Pages Encrypted : 0 Highest block SCN : 1341204 (0.1341204) [oracle@ora1 ~]$
Here we see the two blocks that are corrupt and we can easily perform block media recovery on those blocks using the procedure outlined earlier.