26 Aralık 2012 Çarşamba

                           Recovery Block Corruption   
   Burada media corruption gerçekleştirdiğimiz bir data bloğu rman ile nasıl recovery edebileceğimize bakacağız.İlk olarak block corruption içinde bulunduran datafile bulunduğu bir Rman backup sahip olmalıyız.Corruption işlemini gerçekleştirmeden database full backup almalıyız.

[oracle@demodb /]$ /u01/app/oracle/product/11.2.0/db_1/bin/rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on Tue Dec 25 17:03:47 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
connected to target database: DEMODB (DBID=3798707679)
RMAN> backup database plus archivelog;
Starting backup at 25-DEC-12
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=40 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=22 RECID=21 STAMP=802884109
input archived log thread=1 sequence=23 RECID=22 STAMP=802885427
input archived log thread=1 sequence=24 RECID=23 STAMP=802885462
input archived log thread=1 sequence=25 RECID=24 STAMP=802886055
input archived log thread=1 sequence=26 RECID=25 STAMP=802886084
input archived log thread=1 sequence=27 RECID=26 STAMP=802889219
input archived log thread=1 sequence=28 RECID=27 STAMP=802889237
input archived log thread=1 sequence=29 RECID=28 STAMP=802889565
input archived log thread=1 sequence=30 RECID=29 STAMP=802889594
input archived log thread=1 sequence=31 RECID=30 STAMP=802908041
input archived log thread=1 sequence=32 RECID=31 STAMP=802952378
input archived log thread=1 sequence=33 RECID=32 STAMP=802953349
input archived log thread=1 sequence=34 RECID=33 STAMP=802976637
channel ORA_DISK_1: starting piece 1 at 25-DEC-12
channel ORA_DISK_1: finished piece 1 at 25-DEC-12
piece handle=/u01/app/oracle/fast_recovery_area/DEMODB/backupset/2012_12_25/o1_mf_annnn_TAG20121225T170357_8fmj2xxo_.bkp tag=TAG20121225T170357 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 25-DEC-12
Starting backup at 25-DEC-12
using channel ORA_DISK_1
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=/u01/app/oracle/oradata/demodb/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/demodb/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/demodb/test.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/demodb/ex.dbf
input datafile file number=00007 name=/u01/app/oracle/oradata/demodb/example.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/demodb/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/demodb/users01.dbf
channel ORA_DISK_1: starting piece 1 at 25-DEC-12
channel ORA_DISK_1: finished piece 1 at 25-DEC-12
piece handle=/u01/app/oracle/fast_recovery_area/DEMODB/backupset/2012_12_25/o1_mf_nnndf_TAG20121225T170400_8fmj31gc_.bkp tag=TAG20121225T170400 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 25-DEC-12
channel ORA_DISK_1: finished piece 1 at 25-DEC-12
piece handle=/u01/app/oracle/fast_recovery_area/DEMODB/backupset/2012_12_25/o1_mf_ncsnf_TAG20121225T170400_8fmj3vb8_.bkp tag=TAG20121225T170400 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 25-DEC-12
Starting backup at 25-DEC-12
current log archived
using channel ORA_DISK_1
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=35 RECID=34 STAMP=802976668
channel ORA_DISK_1: starting piece 1 at 25-DEC-12
channel ORA_DISK_1: finished piece 1 at 25-DEC-12
piece handle=/u01/app/oracle/fast_recovery_area/DEMODB/backupset/2012_12_25/o1_mf_annnn_TAG20121225T170428_8fmj3wk2_.bkp tag=TAG20121225T170428 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 25-DEC-12


Block corruption gerçekleştireceğimiz bir tablo oluşturuyoruz.
SQL> create table not1(id number) tablespace example;
Table created.
SQL> insert into not1 values(76);
1 row created.
SQL> insert into not1 values(99);
1 row created.
SQL>
SQL>
SQL> commit;
Commit complete.

SQL> select * from not1;

        ID
----------
        76
        99


Oluşturulan tablonun aşağıdaki sorgu ile datafile içinde  hangi block ta bulunduğuna bakarız.
SQL> select * from
  2  (select distinct dbms_rowid.rowid_block_number(rowid) from not1)
  3  where rownum<6 br="br">
DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
------------------------------------
                                 143

Linux dd komutuyla datanın bulunduğu data bloğunun corrupt olması sağlanır.
oracle@demodb /]$ dd of=/u01/app/oracle/oradata/demodb/example.dbf bs=8192 seek=143 conv=notrunc count=1 if=/dev/zero
1+0 records in
1+0 records out
8192 bytes (8.2 kB) copied, 6.683e-05 seconds, 123 MB/s
 

Corruption işlemini gerçekleştrdikten sonra data ya ulaşıp ulaşmadığımızı kontrol ederiz.
SQL> select * from not1;
        ID
----------
        76
        99


 Tabloda bulunan data ya  ulaşabiliyoruz.Fakat bu sonuç database den değilde buffer dan  geliyor. Bunun için buffer temizlemeliyiz.
SQL> alter system flush buffer_cache;
System altered.


Tekrar dataya ulaşmaya çalıştığımızda aşağıdaki gibi corruption hatası alırız.
SQL> select * from not1;
select * from not1
*
ERROR at line 1:
ORA-01578: ORACLE data block corrupted (file # 7, block # 143)
ORA-01110: data file 7: '/u01/app/oracle/oradata/demodb/example.dbf'


Ayrıca database oluşan media corruption ları görmek için v$database_block_corruption view  ve dbverify tool kullanabiliriz.
SQL> select * from v$database_block_corruption;

     FILE#     BLOCK#     BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ ---------
         7        143          1                  0 ALL ZERO

oracle@demodb /]$ /u01/app/oracle/product/11.2.0/db_1/bin/dbv file=/u01/app/oracle/oradata/demodb/example.dbf
DBVERIFY: Release 11.2.0.3.0 - Production on Tue Dec 25 17:16:00 2012
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
DBVERIFY - Verification starting : FILE = /u01/app/oracle/oradata/demodb/example.dbf
Page 143 is marked corrupt
Corrupt block relative dba: 0x01c0008f (file 7, block 143)
Completely zero block found during dbv:
DBVERIFY - Verification complete
Total Pages Examined         : 12800
Total Pages Processed (Data) : 9
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 133
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 12657
Total Pages Marked Corrupt   : 1
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 1475505 (0.1475505)


Daha sonra rman ile corrupt olan data blockları için recover işlemini gerçekleştiririz
[oracle@demodb /]$ /u01/app/oracle/product/11.2.0/db_1/bin/rman target /
RMAN> blockrecover corruption list;
Starting recover at 25-DEC-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=37 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 00007
channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/DEMODB/backupset/2012_12_25/o1_mf_nnndf_TAG20121225T170400_8fmj31gc_.bkp
channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/DEMODB/backupset/2012_12_25/o1_mf_nnndf_TAG20121225T170400_8fmj31gc_.bkp tag=TAG20121225T170400
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 25-DEC-12


v$database_block_corruption view tekrar sorgularız.
SQL> select * from v$database_block_corruption;
no rows selected
SQL> select * from not1;

        ID
----------
        76
        99

Hiç yorum yok: