DBV(DBVERIFY)是Oracle提供的一个命令行工具,它可以对数据文件物理和逻辑两种一致性检查。但是这个工具不会检查索引记录和数据记录的匹配关系,这种检查必须使用analyze validate structure命令。
这个工具有如下特点:
这个工具可以检查ASM文件,但数据库必须Open状态,并且需要通过USERID指定用户,比如:dbv file=+DG1/ORCL/datafile/system01.dbf userid=system/sys
在许多UNIX平台下,DBV要求数据文件有扩展名,如果没有可以通过建立链接的方法,然后对链接的方法,然后对链接文件进行操作,比如:ls -n /dev/rdsk/mydevice /tmp/mydevice.dbf
某些平台,DBV工具不能检查超过2GB的文件,如果碰到DBV-100错误,请先检查文件大小,MOS Bug 710888对这个问题有描述。
DBV只会检查数据块的正确性,但不会关系数据块是否属于哪个对象。
对于�设备建议指定END参数,避免超出数据文件范围。比如:dbv FILE=/dev/rdsk/r1.dbf END=<last_block_number>。可以在v$datafile视图中用bytes字段除以块大小来获得END值。
参数 | 含义 | 缺省值 |
FILE | 要检查的数据文件名 | 没有缺省值 |
START | 检查起始数据块号 | 数据文件的第一个数据块 |
END | 检查的最后一个数据块号 | 数据文件的最后一个数据块 |
BLOCKSIZE | 数据块大小,这个值要和数据库的DB_BLOCK_SIZE参数值一致 | 缺省值8192 |
LOGFILE | 检查结果日志文件 | 没有缺省值 |
FeedBAK | 显示进度 | 0 |
PARFILE | 参数文件名 | 没有缺省值 |
USERID | 用户名、密码 | 没有缺省值 |
SEGMENT_ID | 段ID,参数格式<tsn.segfile.segblock> | 没有缺省值 |
使用示例:
[oracle@rhel6~]$dbvfile=/u01/app/oracle/oradata/test/users01.dbf DBVERIFY:Release11.2.0.1.0-ProductiononMonMay2216:42:262017 Copyright(c)1982,2009,Oracleand/oritsaffiliates.Allrightsreserved. DBVERIFY-Verificationstarting:FILE=/u01/app/oracle/oradata/test/users01.dbf DBVERIFY-Verificationcomplete TotalPagesExamined:155520 TotalPagesProcessed(Data):144530 TotalPagesFailing(Data):0 TotalPagesProcessed(Index):52 TotalPagesFailing(Index):0 TotalPagesProcessed(Other):1248 TotalPagesProcessed(Seg):0 TotalPagesFailing(Seg):0 TotalPagesEmpty:9690 TotalPagesMarkedCorrupt:0 TotalPagesInflux:0 TotalPagesEncrypted:0 HighestblockSCN:3559792(0.3559792)
这个工具报告使用的是page作为单位,含义和data block相同。从上面的检查结果TotalPagesMarkedCorrupt:0可以看出文件没有坏块。
除了检查数据文件,这个工具还允许检查单独的Segment,这时参数值的格式为<tsn.segfile.segblock>
查看对象的tsn,segfile,segblock属性:
zx@TEST>selectt.ts#,s.header_file,s.header_block 2fromv$tablespacet,dba_segmentss 3wheres.segment_name='T' 4andt.name=s.tablespace_name; TS#HEADER_FILEHEADER_BLOCK --------------------------------- 4445834
从上面的查询结果可行参数值为4.4.45834。检查Segment:
[oracle@rhel6~]$dbvuserid=system/123456segment_id=4.4.45834 DBVERIFY:Release11.2.0.1.0-ProductiononMonMay2220:58:332017 Copyright(c)1982,Oracleand/oritsaffiliates.Allrightsreserved. DBVERIFY-Verificationstarting:SEGMENT_ID=4.4.45834 DBVERIFY-Verificationcomplete TotalPagesExamined:8 TotalPagesProcessed(Data):5 TotalPagesFailing(Data):0 TotalPagesProcessed(Index):0 TotalPagesFailing(Index):0 TotalPagesProcessed(Other):2 TotalPagesProcessed(Seg):1 TotalPagesFailing(Seg):0 TotalPagesEmpty:0 TotalPagesMarkedCorrupt:0 TotalPagesInflux:0 TotalPagesEncrypted:0 HighestblockSCN:3518579(0.3518579)
下面人为创造一个坏块,用dbv来检查。
创建一个测试表
zx@TEST>createtablebbed(idnumber,namevarchar2(20))tablespaceusers; Tablecreated. zx@TEST>insertintobbedvalues(1,'zhaoxu'); 1rowcreated. zx@TEST>commit; Commitcomplete.
当前数据文件没有坏块
[oracle@rhel6~]$dbvfile=/u01/app/oracle/oradata/test/users01.dbf DBVERIFY:Release11.2.0.1.0-ProductiononMonMay2221:03:402017 Copyright(c)1982,Oracleand/oritsaffiliates.Allrightsreserved. DBVERIFY-Verificationstarting:FILE=/u01/app/oracle/oradata/test/users01.dbf DBVERIFY-Verificationcomplete TotalPagesExamined:155520 TotalPagesProcessed(Data):66397 TotalPagesFailing(Data):0 TotalPagesProcessed(Index):52 TotalPagesFailing(Index):0 TotalPagesProcessed(Other):88898 TotalPagesProcessed(Seg):0 TotalPagesFailing(Seg):0 TotalPagesEmpty:173 TotalPagesMarkedCorrupt:0 TotalPagesInflux:0 TotalPagesEncrypted:0 HighestblockSCN:3764775(0.3764775)
zx@TEST>setserveroutputon zx@TEST>declarerfnonumber; 2rtypenumber; 3ononumber; 4blknonumber; 5rownonumber; 6ridvarchar2(30); 7begin 8selectrowidintoridfrombbed; 9dbms_rowid.rowid_info(ROWID_IN=>rid,RELATIVE_FNO=>rfno,BLOCK_NUMBER=>blkno,ROW_NUMBER=>rowno,ROWID_TYPE=>rtype,OBJECT_NUMBER=>ono); 10dbms_output.put_line(rfno||','||blkno||','||rowno); 11end; 12/ 4,45844,0 PL/sqlproceduresuccessfullycompleted.
使用bbed修改块信息
[oracle@rhel6bbed]$bbedparfile=bbed.par Password: BBED:Release2.0.0.0.0-LimitedProductiononMonMay2221:17:182017 Copyright(c)1982,Oracleand/oritsaffiliates.Allrightsreserved. *************!!!ForOracleInternalUSEOnly!!!*************** BBED>setdba4,45844 DBA0x0100b314(168230604,45844) BBED>find/czhaoxu File:/u01/app/oracle/oradata/test/users01.dbf(4) Block:45844Offsets:8182to8191Dba:0x0100b314 ------------------------------------------------------------------------ 7a68616f787501065873 <32bytesperline> BBED>dump/vdba4,45844offset8182count32 File:/u01/app/oracle/oradata/test/users01.dbf(4) Block:45844Offsets:8182to8191Dba:0x0100b314 ------------------------------------------------------- 7a68616f787501065873lzhaoxu..Xs <16bytesperline> BBED>modify100dba4,45844 Warning:contentsofprevIoUsBIFILEwillbelost.Proceed?(Y/N)y File:/u01/app/oracle/oradata/test/users01.dbf(4) Block:45844Offsets:8182to8191Dba:0x0100b314 ------------------------------------------------------------------------ 6468616f787501065873 <32bytesperline> BBED>dump/vdba4,45844offset8182count32 File:/u01/app/oracle/oradata/test/users01.dbf(4) Block:45844Offsets:8182to8191Dba:0x0100b314 ------------------------------------------------------- 6468616f787501065873ldhaoxu..Xs <16bytesperline> BBED>exit
再次使用dbv检查文件
[oracle@rhel6bbed]$dbvfile=/u01/app/oracle/oradata/test/users01.dbf DBVERIFY:Release11.2.0.1.0-ProductiononMonMay2221:18:462017 Copyright(c)1982,Oracleand/oritsaffiliates.Allrightsreserved. DBVERIFY-Verificationstarting:FILE=/u01/app/oracle/oradata/test/users01.dbf Page45844ismarkedcorrupt Corruptblockrelativedba:0x0100b314(file4,block45844) Badcheckvaluefoundduringdbv: Datainbadblock: type:6format:2rdba:0x0100b314 lastchangescn:0x0000.00397358seq:0x1flg:0x04 spare1:0x0spare2:0x0spare3:0x0 consistencyvalueintail:0x73580601 checkvalueinblockheader:0x7c2d computedblockchecksum:0x1e DBVERIFY-Verificationcomplete TotalPagesExamined:155520 TotalPagesProcessed(Data):66396 TotalPagesFailing(Data):0 TotalPagesProcessed(Index):52 TotalPagesFailing(Index):0 TotalPagesProcessed(Other):88898 TotalPagesProcessed(Seg):0 TotalPagesFailing(Seg):0 TotalPagesEmpty:173 TotalPagesMarkedCorrupt:1 TotalPagesInflux:0 TotalPagesEncrypted:0 HighestblockSCN:3764775(0.3764775)
报告一个坏块,Total Pages Marked Corrupt : 1
再次查询测试表:
sys@TEST>select*fromzx.bbed; IDNAME ---------------------------------------------------------------------- 1zhaoxu
查询正常,因为在buffer_cache中缓存了块,而修改的是文件中的块。两个块现在不一致,清空buffer cache后再次查询测试表。
zx@TEST>altersystemflushbuffer_cache; Systemaltered. zx@TEST>select*frombbed; select*frombbed * ERRORatline1: ORA-01578:ORACLEdatablockcorrupted(file#4,block#45844) ORA-01110:datafile4:'/u01/app/oracle/oradata/test/users01.dbf'
使用dbv检查ASM文件中的数据文件,需要指定userid参数
[oracle@rac1~]$dbvfile=+DATA/orcl/datafile/users.259.925306091userid=sys/123456 DBVERIFY:Release11.2.0.4.0-ProductiononMonMay2216:48:222017 Copyright(c)1982,2011,Oracleand/oritsaffiliates.Allrightsreserved. DBVERIFY-Verificationstarting:FILE=+DATA/orcl/datafile/users.259.925306091 DBVERIFY-Verificationcomplete TotalPagesExamined:640 TotalPagesProcessed(Data):16 TotalPagesFailing(Data):0 TotalPagesProcessed(Index):2 TotalPagesFailing(Index):0 TotalPagesProcessed(Other):593 TotalPagesProcessed(Seg):0 TotalPagesFailing(Seg):0 TotalPagesEmpty:29 TotalPagesMarkedCorrupt:0 TotalPagesInflux:0 TotalPagesEncrypted:0 HighestblockSCN:0(0.0)
参考:《大话Oracle RAC》
MOS文档:文档 ID 35512.1