首页 > 代码库 > DBV工具的使用

DBV工具的使用

  DBV是一个外部命令,能够执行物理数据结构的完整性检查。DBV只能检查可缓存管理的块(数据块),所以只能用于数据文件,不支持控制文件和重做日志文件的块检查。DBV使用于offline或者online的数据文件,也可也验证备份文件,但是备份文件只能是rman的copy命令或者操作系统的cp(win下是copy)命令备份的数据文件。控制文件和重做日志文件的检查可以用DBMS_HM包完成。
    DBV有两种命令行接口,一是验证数据文件的数据块,二是验证段。下面分别做测试:
    一、验证数据文件的数据块
    在这种模式下数据库可处在打开或关闭状态。
SYS@orcl>create table scott.test as select * from dba_objects where rownum <=100;
Table created.

---查出test表所在的数据文件和开始的块id以及块数量
SYS@orcl>select a.file_id,a.block_id,a.blocks,b.name
  2  from dba_extents a,v$datafile b
  3  where a.file_id=b.file# and a.owner=‘SCOTT‘ and a.segment_name=‘TEST‘;
FILE_ID   BLOCK_ID      BLOCKS NAME
---------- ---------- ---------- ---------------------------------------------
     4      520           8 /u01/app/oracle/oradata/orcl/users01.dbf

---查出表中记录所在的块
SYS@orcl>select distinct dbms_rowid.rowid_block_number(rowid) from scott.test;
DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)
------------------------------------
                 523
                 524

---破坏有记录的数据块
[oracle@ora ~]$ dd of=/u01/app/oracle/oradata/orcl/users01.dbf bs=8192 conv=notrunc seek=524 <<EOF
> abcdefghicklmn
> EOF
0+1 records in
0+1 records out
15 bytes (15 B) copied, 3.1499e-05 s, 476 kB/s

---执行dbv命令检查数据文件
[oracle@ora ~]$ dbv file=/u01/app/oracle/oradata/orcl/users01.dbf blocksize=8192
DBVERIFY: Release 11.2.0.3.0 - Production on Sat Jan 12 14:45:56 2013

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

DBVERIFY - Verification starting : FILE = /u01/app/oracle/oradata/orcl/users01.dbf
Page 524 is marked corrupt                    ---数据块524标记为坏块
Corrupt block relative dba: 0x0100020c (file 4, block 524)
Bad header found during dbv: 
Data in bad block:
 type: 97 format: 2 rdba: 0x68676665
 last change scn: 0x6e6d.6c6b6369 seq: 0xa flg: 0x04
 spare1: 0x63 spare2: 0x64 spare3: 0x0
 consistency value in tail: 0x65790602
 check value in block header: 0x2f5b
 computed block checksum: 0xad06

DBVERIFY - Verification complete

Total Pages Examined         : 1920
Total Pages Processed (Data) : 1161
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 39
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 398
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 321
Total Pages Marked Corrupt   : 1
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 1205628 (0.1205628)

Pages--表示数据块
Total Pages Examined --表示文件中的数据块总数量
Total Pages Processed--表示已检查数据块的数量
Total Pages Failing--表示检查失败的数据块数量
Total Pages Marked Corrupt--表示数据块已损坏
Total Pages Influx--表示同一时间正在读和写的数据块数量。如果数据库是打开状态,当DBV运行时多次读数据块得到一个一致的映像,但是因为数据库是打开的,可能同一数据块在读的时候又有写入的动作,DBV不能得到一个一致的数据块映像

    DBV除了能检查有内容的数据块,可以检查空数据块,这充分证明了dbv是从物理层面上验证数据块的完整性。
[oracle@ora ~]$ dd of=/u01/app/oracle/oradata/orcl/users01.dbf bs=8192 conv=notrunc seek=526 <<EOF
> abcdefghijklmn
> EOF
0+1 records in
0+1 records out
15 bytes (15 B) copied, 3.0521e-05 s, 491 kB/s

[oracle@ora ~]$ dbv file=/u01/app/oracle/oradata/orcl/users01.dbf blocksize=8192
 
DBVERIFY: Release 11.2.0.3.0 - Production on Sat Jan 12 15:11:51 2013

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

DBVERIFY - Verification starting : FILE = /u01/app/oracle/oradata/orcl/users01.dbf
Page 524 is marked corrupt                ---数据块524标记为坏块
Corrupt block relative dba: 0x0100020c (file 4, block 524)
Bad header found during dbv: 
Data in bad block:
 type: 97 format: 2 rdba: 0x68676665
 last change scn: 0x6e6d.6c6b6369 seq: 0xa flg: 0x04
 spare1: 0x63 spare2: 0x64 spare3: 0x0
 consistency value in tail: 0x65790602
 check value in block header: 0x2f5b
 computed block checksum: 0xad06

Page 526 is marked corrupt                ---空数据块526也标记为坏块
Corrupt block relative dba: 0x0100020e (file 4, block 526)
Bad header found during dbv: 
Data in bad block:
 type: 97 format: 2 rdba: 0x68676665
 last change scn: 0x6e6d.6c6b6a69 seq: 0xa flg: 0x04
 spare1: 0x63 spare2: 0x64 spare3: 0x0
 consistency value in tail: 0x64b30601
 check value in block header: 0x54c2
 computed block checksum: 0xa5cd

DBVERIFY - Verification complete

Total Pages Examined         : 1920
Total Pages Processed (Data) : 1160
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 39
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 398
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 321
Total Pages Marked Corrupt   : 2
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 1205628 (0.1205628)


    DBV可以检查ASM管理的数据文件,但是数据库要求是open状态,同时要使用选项USERID,例如:
    dbv userid=system/oracle file=+DATAa/orcl/datafile/users01.dbf blocksize=8192

    DBV验证rman的backup as copy命令备份的数据文件,例如:
RMAN> backup as copy datafile 5;

Starting backup at 12-JAN-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=15 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf
output file name=/u01/app/oracle/fast_recovery_area/ORCL/datafile/o1_mf_example_8h22vb6m_.dbf tag=TAG20130112T150617 RECID=2 STAMP=804524793
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
Finished backup at 12-JAN-13

[oracle@ora ~]$ dbv file=/u01/app/oracle/fast_recovery_area/ORCL/datafile/o1_mf_example_8h22vb6m_.dbf

DBVERIFY: Release 11.2.0.3.0 - Production on Sat Jan 12 15:08:08 2013

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

DBVERIFY - Verification starting : FILE = /u01/app/oracle/fast_recovery_area/ORCL/datafile/o1_mf_example_8h22vb6m_.dbf

DBVERIFY - Verification complete

Total Pages Examined         : 44240
Total Pages Processed (Data) : 6600
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 1148
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 2841
Total Pages Processed (Seg)  : 0
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 33651
Total Pages Marked Corrupt   : 0
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 1126464 (0.1126464)

    二、验证段
    验证段的时候要求数据库必须处在open状态,还需要提供拥有SYSDBA权限的帐号进行查询,查询段的命令格式例如:
    dbv userid=system/oracle segment_id=tsn.segfile.segblock
    tsn--表示表空间id
    segfile--表示段头所在数据文件号
    segblock--表示段头数据块号
    这三个值可以通过数据字典sys_dba_segs获取,相关的列分别是TABLESPACE_ID、 HEADER_FILE和HEADER_BLOCK

SYS@orcl>select tablespace_id,header_file,header_block
  2  from sys_dba_segs
  3  where owner=‘SCOTT‘ and segment_name=‘TEST‘;

TABLESPACE_ID HEADER_FILE HEADER_BLOCK
------------- ----------- ------------
        4        4       522

[oracle@ora ~]$ dbv userid=system/oracle segment_id=4.4.522

DBVERIFY: Release 11.2.0.3.0 - Production on Sat Jan 12 15:26:30 2013

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

DBVERIFY - Verification starting : SEGMENT_ID = 4.4.522
Page 524 is marked corrupt
Corrupt block relative dba: 0x0100020c (file 4, block 524)
Bad header found during dbv: 
Data in bad block:
 type: 97 format: 2 rdba: 0x68676665
 last change scn: 0x6e6d.6c6b6369 seq: 0xa flg: 0x04
 spare1: 0x63 spare2: 0x64 spare3: 0x0
 consistency value in tail: 0x65790602
 check value in block header: 0x2f5b
 computed block checksum: 0xad06

Page 526 is marked corrupt
Corrupt block relative dba: 0x0100020e (file 4, block 526)
Bad header found during dbv: 
Data in bad block:
 type: 97 format: 2 rdba: 0x68676665
 last change scn: 0x6e6d.6c6b6a69 seq: 0xa flg: 0x04
 spare1: 0x63 spare2: 0x64 spare3: 0x0
 consistency value in tail: 0x64b30601
 check value in block header: 0x54c2
 computed block checksum: 0xa5cd

DBVERIFY - Verification complete

Total Pages Examined         : 8
Total Pages Processed (Data) : 3
Total Pages Failing   (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing   (Index): 0
Total Pages Processed (Other): 2
Total Pages Processed (Seg)  : 1
Total Pages Failing   (Seg)  : 0
Total Pages Empty            : 0
Total Pages Marked Corrupt   : 2
Total Pages Influx           : 0
Total Pages Encrypted        : 0
Highest block SCN            : 1205628 (0.1205628)

    三、其他
    dbv命令帮助:
[oracle@ora ~]$ dbv

DBVERIFY: Release 11.2.0.3.0 - Production on Sat Jan 12 15:48:28 2013

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Keyword     Description                    (Default)
----------------------------------------------------
FILE        File to Verify                 (NONE)
START       Start Block                    (First Block of File)
END         End Block                      (Last Block of File)
BLOCKSIZE   Logical Block Size             (8192)
LOGFILE     Output Log                     (NONE)
FEEDBACK    Display Progress               (0)
PARFILE     Parameter File                 (NONE)
USERID      Username/Password              (NONE)
SEGMENT_ID  Segment ID (tsn.relfile.block) (NONE)
HIGH_SCN    Highest Block SCN To Verify    (NONE)
            (scn_wrap.scn_base OR scn)

    编写脚本一次检查多个数据文件
    保存下列脚本为dbv_all.sh文件。
#!/bin/bash
DATADIR=$1
BLOCKSIZE=$2
cd $DATADIR
ls -1 *.dbf | while read FILE
do
    dbv file=$FILE blocksize=$BLOCKSIZE
done

    给脚本执行的权限。
[oracle@ora ~]$ chmod +x dbv_all.sh

    执行脚本。
[oracle@ora ~]$ ./dbv_all.sh /u01/app/oracle/oradata/orcl 8192 >> dbv_all.log 2>&1

    查看执行结果。
[oracle@ora ~]$ more dbv_all.log

 
 转:http://blog.csdn.net/seertan/article/details/8496445

DBV工具的使用