[Oracle工程师手记] 目前未被使用的块中包含坏块的对应方法

 
      如果数据库中,检查出了 坏块,但是这些个坏块并不属于任何的对象,其实是不必处理的。等到数据库中建立一个新的对象,或旧的对象扩张,用到了这个Free 的坏块,它应该会被重新初始化或者说格式化的。
     
     但是,此时如果用 RMAN 进行检查 (rman valiate),还是会报出错来,有的客户会觉得不爽。那么我们可以利用 RMAN 备份时,跳过Free 的块的特点,建立这个数据文件的备份,再用这个不包含坏块的备份,刷掉数据文件中的Free 坏块。

下面我做一个模拟,来说明这个过程: 比如我建立了一个 表空间,它的数据文件是 5 号数据文件:

SQL> create tablespace tbs001 datafile '/myopt/datafile/df001.dbf' size 200M;

SQL> grant dba to u1 identified by u1;
SQL> alter user u1 default tablespace tbs001;


SQL> conn u1/u1
SQL> create table tab001 as select * from dba_objects;
SQL> insert into tab001 select * from tab001;
SQL> commit;


SQL> set linesize 200
SQL> col name for a60
SQL> select file#, name from v$datafile;

     FILE# NAME
---------- ------------------------------------------------------------
         1 /myopt/<myorclpath>/system01
           .dbf

         3 /myopt/<myorclpath>/sysaux01
           .dbf

         4 /myopt/<myorclpath>/undotbs0
           1.dbf

         5 /myopt/datafile/df001.dbf
         7 /myopt/<myorclpath>/users01.

     FILE# NAME
---------- ------------------------------------------------------------
           dbf

 假定我现在的5号数据文件上有一个第150个块,它不属于任何一个object,但是是一个坏块。我可以如此操作,来格式化它。

先做出这个数据文件的备份:

RMAN> backup check logical datafile 5 format '/myopt/back/%U' tag 'CORRUPT_BLK_FILE_BKP';

Starting backup at 09-APR-21
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=00005 name=/myopt/datafile/df001.dbf
channel ORA_DISK_1: starting piece 1 at 09-APR-21
channel ORA_DISK_1: finished piece 1 at 09-APR-21
piece handle=/myopt/back/08vrrckk_1_1 tag=CORRUPT_BLK_FILE_BKP comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 09-APR-21
...

RMAN> list copy;

specification does not match any datafile copy in the repository
specification does not match any control file copy in the repository
specification does not match any archived log in the repository

RMAN> list backup;


List of Backup Sets
===================


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
6       Full    23.92M     DISK        00:00:00     09-APR-21
        BP Key: 6   Status: AVAILABLE  Compressed: NO  Tag: CORRUPT_BLK_FILE_BKP
        Piece Name: /myopt/back/08vrrckk_1_1
  List of Datafiles in backup set 6
  File LV Type Ckp SCN    Ckp Time  Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- --------- ----------- ------ ----
  5       Full 1852746    09-APR-21              NO    /myopt/datafile/df001.dbf


RMAN>

 如果我的这个备份动作没有出错,那么就还有得玩。继续下面的步骤:

把刚才这个数据文件的备份,恢复到某一个新目录下:

RMAN> run {
 set newname for datafile 5 to '/myopt/dfcopy/mytst_RESTORED.dbf';
 restore datafile 5 from tag 'CORRUPT_BLK_FILE_BKP';
 }

 此时,可以看到产生了一个 copy:

RMAN> list copy;

specification does not match any control file copy in the repository
specification does not match any archived log in the repository
List of Datafile Copies
=======================

Key     File S Completion Time Ckp SCN    Ckp Time        Sparse
------- ---- - --------------- ---------- --------------- ------
1       5    A 09-APR-21       1852746    09-APR-21       NO
        Name: /myopt/dfcopy/mytst_RESTORED.dbf


RMAN> list backup;


BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
6       Full    23.92M     DISK        00:00:00     09-APR-21
        BP Key: 6   Status: AVAILABLE  Compressed: NO  Tag: CORRUPT_BLK_FILE_BKP
        Piece Name: /myopt/back/08vrrckk_1_1
  List of Datafiles in backup set 6
  File LV Type Ckp SCN    Ckp Time  Abs Fuz SCN Sparse Name
  ---- -- ---- ---------- --------- ----------- ------ ----
  5       Full 1852746    09-APR-21              NO    /myopt/datafile/df001.dbf

 然后,可以用这个copy,来执行 block recover ,来刷掉坏块:

RMAN> blockrecover datafile 5 block 150 FROM DATAFILECOPY;

Starting recover at 09-APR-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=70 device type=DISK

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 09-APR-21

RMAN>

 接下来,再次用 RMAN validate 检查,看看坏块是否消失。如果不再报坏块了,就可以删除掉这一份copy 了:

RMAN> delete datafilecopy '/myopt/dfcopy/mytst_RESTORED.dbf';

using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=70 device type=DISK
List of Datafile Copies
=======================

Key     File S Completion Time Ckp SCN    Ckp Time        Sparse
------- ---- - --------------- ---------- --------------- ------
1       5    A 09-APR-21       1852746    09-APR-21       NO
        Name: /myopt/dfcopy/mytst_RESTORED.dbf


Do you really want to delete the above objects (enter YES or NO)? yes
deleted datafile copy
datafile copy file name=/myopt/dfcopy/mytst_RESTORED.dbf RECID=1 STAMP=1069396865
Deleted 1 objects

RMAN>

 


  

posted @ 2021-04-09 13:54  健哥的数据花园  阅读(162)  评论(0编辑  收藏  举报