Oracle DBVERIFY是一个可以用来查看数据库物理文件正确性的外部命令工具,由Oracle软件自带。可以在线/离线情况下对数据库进行检查,甚至可以对数据库的备份文件进行检查。并可以在数据发生错误或破坏时对数据库进行诊断,以帮助进行恢复。当然数据库可以直接使用DBMS_REPAIR来实现这个功能,但是两者还是有所区别的,所以有必要来学习一下。
首先给出Oracle官方对DBVERIFY的介绍:
DBVERIFY: Offline Database Verification Utility
DBVERIFY is an external
command-line utility that performs a physical data structure integrity
check. It can be used on offline or online databases, as well on backup
files. You use DBVERIFY primarily when you need to ensure that a backup
database (or datafile) is valid before it is restored, or as a
diagnostic aid when you have encountered data corruption problems.
Because DBVERIFY can be run against an offline database, integrity checks are significantly faster.
DBVERIFY checks are limited to
cache-managed blocks (that is, data blocks). Because DBVERIFY is only
for use with datafiles, it will not work against control files or redo
logs.
接下来讲一下DBVERIFY的用法。DBVERIFY可以有2种用法,一种是对datafile进行检查,另一种是对segment进行检查。两者都是使用“dev”命令进行,但是所用的格式和结果都有所差异,下面看一下:
一、使用DBVERIFY检查单个datafile的Disk Blocks
在这个模式下面,DBVERIFY扫描某个datafile中的一个或者多个Disk
Blocks,并生成一份结果。需要注意的是:如果datafile使用ASM(Automatic Storage
Management)进行文件存储,则需要提供一个USERID,因为DBVERIFY需要连接到这个ASM文件。
对datafile的DBVERIFY命令语法如下:
dbv [ USERID=username/password ]
FILE = filename
| { START = block_address | END = block_address }
| BLOCKSIZE = integer
| LOGFILE = filename
| FEEDBACK = integer
| HELP = { Y | N }
| PARFILE = filename
对语法做一些说明:
USERID: 指定用户名/密码,在ASM存储环境下使用;
FILE: 提供需要检测的datafile名(需要指定文件的完整路径);
START: 指定verify开始的block地址。如果没有指定,则默认从第一个block开始;
END: 指定verify结束的block地址。如果没有指定,则默认为最后一个block;
BLOCKSIZE:如果你的block size不是2k,那么必须指定这个参数,否则返回DBV-00103错误;
LOGFILE: 指定最终结果的输出文本。如果不定义,则直接在执行终端显示;
FEEDBACK: 回馈DBVERIFY在检查过程中的信息,跟的参数n代表n页。如果n=0则表示买有;
HELP: 提供在线帮助;
PARFILE: 使用parameter file来存储设定的参数,然后每次直接调用执行
下面就是一个最简单的例子来使用DBVERIFY:
% dbv FILE=t_db1.dbf FEEDBACK=100
DBVERIFY: Release 10.2.0.3.0 - Production on Mon Aug 17 12:21:58 2009
Copyright (c) 1982, 2005, Oracle. All rights reserved.
DBVERIFY - Verification starting : FILE = t_db1.dbf
................................................................................
DBVERIFY - Verification complete
Total Pages Examined : 9216
Total Pages Processed (Data) : 2044
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 733
Total Pages Failing (Index): 0
Total Pages Empty : 5686
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
说明:
Pages = Blocks
Total Pages Examined = number of blocks in the file
Total Pages Processed = number of blocks that were verified (formatted blocks)
Total Pages Failing (Data) = number of blocks that failed the data block checking routine
Total Pages Failing (Index) = number of blocks that failed the index block checking routine
Total Pages Marked
Corrupt = number of blocks for which the cache header is invalid,
thereby making it impossible for DBVERIFY to identify the block type
Total Pages Influx =
number of blocks that are being read and written to at the same time.
If the database is open when DBVERIFY is run, DBVERIFY reads blocks
multiple times to get a consistent image. But because the database is
open, there may be blocks that are being read and written to at the same
time (INFLUX). DBVERIFY cannot get a consistent image of pages that are
in flux.
二、使用DBVERIFY检查Segment
在这个模式下面,可以使用DBVERIFY来检测一个表or索引的segment的可用性。指定segment的所有链表均会被检测。需要注意的是,该模式下需要提供一个SYSDBA的用户和密码,因为需要从数据库中获取的segment的信息。
当使用这个模式时,针对的那个segment会被加锁。如果是一个索引的segment,则所在的父表被加锁。(IOT没有父表)
对segment的DBVERIFY命令语法如下:
dbverify_seg ::=
dbv USERID = username/password
| SEGMENT_ID = tsn.segfile.segblock
| LOGFILE = filename
| FEEDBACK = integer
| HELP = { Y | N }
| PARFILE = filename
对语法做一些说明:
USERID: 必须指定用户名和密码;
SEGMENT_ID:需要指定segment id;
这个ID由3部分组成,分别是Tablespace_ID、Segment_Header_File_Number、Segment_Header_Block_Number
3者中间用'.'隔开。可以用这段SQL来直接查询得到:
select a.ts# || '.' || b.header_file || '.' || b.header_block
from v$tablespace a, dba_segments b
where a.name = b.tablespace_name
and b.segment_name = 'segment_name';
LOGFILE: 指定最终结果的输出文本。如果不定义,则直接在执行终端显示;
FEEDBACK: 回馈DBVERIFY在检查过程中的信息,跟的参数n代表n页。如果n=0则表示买有;
HELP: 提供在线帮助;
PARFILE: 使用parameter file来存储设定的参数,然后每次直接调用执行
举个例子:
% dbv USERID=hr/hr SEGMENT_ID=1.2.67
DBVERIFY - Verification starting : SEGMENT_ID = 1.2.67
DBVERIFY - Verification complete
Total Pages Examined : 8
Total Pages Processed (Data) : 0
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 1
Total Pages Failing (Index): 0
Total Pages Processed (Other): 2
Total Pages Processed (Seg) : 1
Total Pages Failing (Seg) : 0
Total Pages Empty : 4
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Highest block SCN : 7358 (0.7358)
信息含义与上同。
转自: http://www.blogjava.net/decode360/archive/2009/03/19/291855.html