[20160704]Block recover using RMAN.txt
--总结一下使用rman恢复坏块.
1.环境:
SCOTT@book> @ &r/ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
SCOTT@book> create table emp2 tablespace tea as select * from emp ;
Table created.
SCOTT@book> select rowid from emp2 where rownum<=1;
ROWID
------------------
AAAXKZAAHAAAACDAAA
SCOTT@book> @ &r/rowid AAAXKZAAHAAAACDAAA
OBJECT FILE BLOCK ROW DBA TEXT
---------- ---------- ---------- ---------- -------------------- ----------------------------------------
94873 7 131 0 7,131 alter system dump datafile 7 block 131 ;
2.备份:
RMAN> backup datafile 7 format '/home/oracle/backup/datafile_7_20160704.bak';
Starting backup at 2016-07-04 09:53:39
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=123 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=134 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=145 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=00007 name=/mnt/ramdisk/book/tea01.dbf
channel ORA_DISK_1: starting piece 1 at 2016-07-04 09:53:40
channel ORA_DISK_1: finished piece 1 at 2016-07-04 09:53:41
piece handle=/home/oracle/backup/datafile_7_20160704.bak tag=TAG20160704T095340 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2016-07-04 09:53:41
Starting Control File and SPFILE Autobackup at 2016-07-04 09:53:41
piece handle=/u01/app/oracle/fast_recovery_area/BOOK/autobackup/2016_07_04/o1_mf_s_916307621_cqmjf5o4_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2016-07-04 09:53:42
3.破坏使用dd命令:
$ dd if=/dev/null of=/mnt/ramdisk/book/tea01.dbf bs=8192 count=1 seek=131 conv=notrunc
0+0 records in
0+0 records out
0 bytes (0 B) copied, 1.5781e-05 seconds, 0.0 kB/s
--注意if使用/dev/null 不行.另外注意加conv=notrunc,不要在生产系统做这个测试.
$ dd if=/dev/zero of=/mnt/ramdisk/book/tea01.dbf bs=8192 count=1 seek=131 conv=notrunc
1+0 records in
1+0 records out
8192 bytes (8.2 kB) copied, 3.4219e-05 seconds, 239 MB/s
SCOTT@book> select * from emp2 where rownum<=2;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
7369 SMITH CLERK 7902 1980-12-17 00:00:00 800 20
7499 ALLEN SALESMAN 7698 1981-02-20 00:00:00 1600 300 30
--//因为数据还在缓存中,如果清除缓存,就报错了.
SCOTT@book> alter system flush buffer_cache;
System altered.
SCOTT@book> select * from emp2 where rownum<=2;
select * from emp2 where rownum<=2
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 7, block # 131)
ORA-01110: data file 7: '/mnt/ramdisk/book/tea01.dbf'
SCOTT@book> select * from v$database_block_corruption;
FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
7 131 1 0 ALL ZERO
--//使用rman检查:
RMAN> validate datafile 7;
Starting validate at 2016-07-04 10:02:24
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00007 name=/mnt/ramdisk/book/tea01.dbf
channel ORA_DISK_1: validation complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
7 FAILED 0 169 2305 13243764038
File Name: /mnt/ramdisk/book/tea01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 1924
Index 0 0
Other 1 211
validate found one or more corrupt blocks
See trace file /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_59407.trc for details
Finished validate at 2016-07-04 10:02:25
$ dbv file=/mnt/ramdisk/book/tea01.dbf
DBVERIFY: Release 11.2.0.4.0 - Production on Mon Jul 4 10:03:19 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
DBVERIFY - Verification starting : FILE = /mnt/ramdisk/book/tea01.dbf
Page 131 is marked corrupt
Corrupt block relative dba: 0x01c00083 (file 7, block 131)
Completely zero block found during dbv:
DBVERIFY - Verification complete
Total Pages Examined : 2304
Total Pages Processed (Data) : 1924
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing (Index): 0
Total Pages Processed (Other): 210
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 169
Total Pages Marked Corrupt : 1
Total Pages Influx : 0
Total Pages Encrypted : 0
Highest block SCN : 358862150 (3.358862150)
4.使用rman修复:
RMAN> blockrecover datafile 7 block 131;
Starting recover at 2016-07-04 10:04:24
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00007
channel ORA_DISK_1: reading from backup piece /home/oracle/backup/datafile_7_20160704.bak
channel ORA_DISK_1: piece handle=/home/oracle/backup/datafile_7_20160704.bak tag=TAG20160704T095340
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:01
Finished recover at 2016-07-04 10:04:26
SCOTT@book> select * from emp2 where rownum<=2;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
7369 SMITH CLERK 7902 1980-12-17 00:00:00 800 20
7499 ALLEN SALESMAN 7698 1981-02-20 00:00:00 1600 300 30
--如果坏块很多,可以使用blockrecover corruption list;
--重复测试:
$ dd if=/dev/zero of=/mnt/ramdisk/book/tea01.dbf bs=8192 count=1 seek=131 conv=notrunc
--//注意一个细节,dbv可以检查文件,但是错误不会出现视图v$database_block_corruption;
--//同样select * from emp2 where rownum<=2;报ORA-01578,有时候也不出现在视图v$database_block_corruption中.
SCOTT@book> select * from emp2 where rownum<=2;
select * from emp2 where rownum<=2
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 7, block # 131)
ORA-01110: data file 7: '/mnt/ramdisk/book/tea01.dbf'
SCOTT@book> select * from v$database_block_corruption;
no rows selected
--//仅仅在rman下使用validate datafile 7;或者validate database或者validate tablespace才可以.
RMAN> validate tablespace tea;
Starting validate at 2016-07-04 10:09:50
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: starting validation of datafile
channel ORA_DISK_1: specifying datafile(s) for validation
input datafile file number=00007 name=/mnt/ramdisk/book/tea01.dbf
channel ORA_DISK_1: validation complete, elapsed time: 00:00:01
List of Datafiles
=================
File Status Marked Corrupt Empty Blocks Blocks Examined High SCN
---- ------ -------------- ------------ --------------- ----------
7 FAILED 0 169 2305 13243764038
File Name: /mnt/ramdisk/book/tea01.dbf
Block Type Blocks Failing Blocks Processed
---------- -------------- ----------------
Data 0 1924
Index 0 0
Other 1 211
validate found one or more corrupt blocks
See trace file /u01/app/oracle/diag/rdbms/book/book/trace/book_ora_59407.trc for details
Finished validate at 2016-07-04 10:09:51
SCOTT@book> select * from v$database_block_corruption;
FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
7 131 1 0 ALL ZERO
--//这个测试blockrecover corruption list;忽略.
SCOTT@book> @ &r/convrdba 7 131
RDBA16 RDBA
-------------- ----------
1c00083 29360259
--还可以直接使用rdba地址.
--recover datafile 7 29360259; 不行
--recover tablespace tea dba 0x1c00083 ; 不行,必须使用十进制数.
RMAN> recover tablespace tea dba 29360259 ;
Starting recover at 2016-07-04 10:15:15
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00007
channel ORA_DISK_1: reading from backup piece /home/oracle/backup/datafile_7_20160704.bak
channel ORA_DISK_1: piece handle=/home/oracle/backup/datafile_7_20160704.bak tag=TAG20160704T095340
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:01
Finished recover at 2016-07-04 10:15:18
SCOTT@book> select * from v$database_block_corruption;
no rows selected
SCOTT@book> select * from emp2 where rownum<=2;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
7369 SMITH CLERK 7902 1980-12-17 00:00:00 800 20
7499 ALLEN SALESMAN 7698 1981-02-20 00:00:00 1600 300 30
--实际上还可以这样写:
RMAN> recover datafile 7 block 131;
Starting recover at 2016-07-04 10:18:01
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
channel ORA_DISK_1: restoring block(s)
channel ORA_DISK_1: specifying block(s) to restore from backup set
restoring blocks of datafile 00007
channel ORA_DISK_1: reading from backup piece /home/oracle/backup/datafile_7_20160704.bak
channel ORA_DISK_1: piece handle=/home/oracle/backup/datafile_7_20160704.bak tag=TAG20160704T095340
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
--//感觉这个更加人性化.
5.总结:
blockrecover datafile &file# block &block#
blockrecover corruption list;
recover tablespace tea dba 29360259;
recover datafile &file# block &block#
--//注意一个问题就是仅仅在rman下使用命令validate ,有问题的块才会记录在v$database_block_corruption视图中.
--//以此做一个全面总结.