一,介紹
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@oracle01 oracle01]$ dbv file=test01.dbf --最好是絕對路徑,這里是進入到對應目錄下,所以用相對路徑 DBVERIFY: Release 11.2.0.4.0 - Production on Mon May 13 15:21:42 2019 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. DBVERIFY - Verification starting : FILE = /u01/app/oracle/oradata/oracle01/test01.dbf DBVERIFY - Verification complete Total Pages Examined : 1280 --( 檢查總頁數) Total Pages Processed (Data) : 5 --(處理的總頁數(數據)) Total Pages Failing (Data) : 0 --(總頁數失敗(數據)) Total Pages Processed (Index): 0 --(處理的總頁數(索引)) Total Pages Failing (Index): 0 --(總頁面失敗(索引)) Total Pages Processed (Other): 136 --(處理的總頁數(其他)) Total Pages Processed (Seg) : 0 --(處理的總頁數(Seg)) Total Pages Failing (Seg) : 0 --(總頁數失敗(Seg) Total Pages Empty : 1139 --(總頁數空) Total Pages Marked Corrupt : 0 --(總頁數標記為損壞) Total Pages Influx : 0 --(總頁面數量) Total Pages Encrypted : 0 --(加密總頁數) Highest block SCN : 11638862 (0.11638862) --(最高塊SCN)
這個工具報告使用的是page作為單位,含義和data block相同。從上面的檢查結果Total Pages Marked Corrupt : 0可以看出文件沒有壞塊。
除了檢查數據文件,這個工具還允許檢查單獨的Segment,這時參數值的格式為<tsn.segfile.segblock>
查看對象的tsn,segfile,segblock屬性:
SQL> select t.ts#,s.header_file,s.header_block from v$tablespace t,dba_segments s where s.segment_name='T' and t.name=s.tablespace_name; 2 3 4 0 1 96544
從上面的查詢結果可行參數值為0.1.96544。檢查Segment:
[oracle@oracle01 oracle01]$ dbv userid=system/123456 segment_id=0.1.96544 DBVERIFY: Release 11.2.0.4.0 - Production on Mon May 13 15:27:53 2019 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. DBVERIFY - Verification starting : SEGMENT_ID = 0.1.96544 DBVERIFY - Verification complete Total Pages Examined : 2 Total Pages Processed (Data) : 1 Total Pages Failing (Data) : 0 Total Pages Processed (Index): 0 Total Pages Failing (Index): 0 Total Pages Processed (Other): 0 Total Pages Processed (Seg) : 1 Total Pages Failing (Seg) : 0 Total Pages Empty : 0 Total Pages Marked Corrupt : 0 Total Pages Influx : 0 Total Pages Encrypted : 0 Highest block SCN : 11645088 (0.11645088)
三,創建壞塊
創建數據:
SQL> create table bbed (id number,name varchar2(20)) tablespace TT1; Table created. SQL> insert into bbed values(1,'zhaoxu'); 1 row created. SQL> commit; Commit complete. SQL> insert into bbed values(1,'kingle'); 1 row created. [oracle@oracle01 oracle01]$ dbv file=test01.dbf DBVERIFY: Release 11.2.0.4.0 - Production on Mon May 13 15:40:14 2019 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. DBVERIFY - Verification starting : FILE = /u01/app/oracle/oradata/oracle01/test01.dbf DBVERIFY - Verification complete Total Pages Examined : 1280 Total Pages Processed (Data) : 5 Total Pages Failing (Data) : 0 Total Pages Processed (Index): 0 Total Pages Failing (Index): 0 Total Pages Processed (Other): 136 Total Pages Processed (Seg) : 0 Total Pages Failing (Seg) : 0 Total Pages Empty : 1139 Total Pages Marked Corrupt : 0 Total Pages Influx : 0 Total Pages Encrypted : 0 Highest block SCN : 11638862 (0.11638862)
尋找數據塊位置:
SQL> select id,name,dbms_rowid.rowid_relative_fno(rowid)file#,dbms_rowid.rowid_block_number(rowid) block# from bbed; 1 zhaoxu 6 157 1 kingle 6 157
BBED連接數據庫
[oracle@oracle01 BBED]$ bbed password=blockedit parfile=par.bbd BBED: Release 2.0.0.0.0 - Limited Production on Mon May 13 15:47:32 2019 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. ************* !!! For Oracle Internal Use only !!! *************** BBED> set filename '/u01/app/oracle/oradata/oracle01/test01.dbf' FILENAME /u01/app/oracle/oradata/oracle01/test01.dbf BBED> map File: /u01/app/oracle/oradata/oracle01/test01.dbf (6) Block: 1 Dba:0x01800001 ------------------------------------------------------------ Data File Header struct kcvfh, 860 bytes @0 ub4 tailchk @8188 BBED> show all FILE# 6 BLOCK# 1 OFFSET 0 DBA 0x01800001 (25165825 6,1) FILENAME /u01/app/oracle/oradata/oracle01/test01.dbf BIFILE bifile.bbd LISTFILE bbed.txt BLOCKSIZE 8192 MODE Edit EDIT Unrecoverable IBASE Dec OBASE Dec WIDTH 80 COUNT 512 LOGFILE log.bbd SPOOL No BBED> map File: /u01/app/oracle/oradata/oracle01/test01.dbf (6) Block: 1 Dba:0x01800001 ------------------------------------------------------------ Data File Header struct kcvfh, 860 bytes @0 ub4 tailchk @8188 BBED> set dba 6,157 DBA 0x0180009d (25165981 6,157) BBED> find /c kingle --這就是我們找到的字符位置 File: /u01/app/oracle/oradata/oracle01/test01.dbf (6) Block: 157 Offsets: 8169 to 8191 Dba:0x0180009d ------------------------------------------------------------------------ 6b696e67 6c652c01 0202c102 067a6861 6f787501 06c3cd <32 bytes per line>
更改數據:
BBED> dump /v dba 6,157 offset 8169 count 32 File: /u01/app/oracle/oradata/oracle01/test01.dbf (6) Block: 157 Offsets: 8169 to 8191 Dba:0x0180009d ------------------------------------------------------- 6b696e67 6c652c01 0202c102 067a6861 l kingle,....zha 6f787501 06c3cd l oxu..č <16 bytes per line> BBED> modify 100 dba 6,157; Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) Y File: /u01/app/oracle/oradata/oracle01/test01.dbf (6) Block: 157 Offsets: 8169 to 8191 Dba:0x0180009d ------------------------------------------------------------------------ 64696e67 6c652c01 0202c102 067a6861 6f787501 06c3cd <32 bytes per line> BBED> dump /v dba 6,157 offset 8169 count 32 File: /u01/app/oracle/oradata/oracle01/test01.dbf (6) Block: 157 Offsets: 8169 to 8191 Dba:0x0180009d ------------------------------------------------------- 64696e67 6c652c01 0202c102 067a6861 l dingle,....zha 6f787501 06c3cd l oxu..č <16 bytes per line> BBED> exit
查看數據塊:
[oracle@oracle01 oracle01]$ dbv file=test01.dbf DBVERIFY: Release 11.2.0.4.0 - Production on Mon May 13 15:54:14 2019 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. DBVERIFY - Verification starting : FILE = /u01/app/oracle/oradata/oracle01/test01.dbf Page 157 is marked corrupt Corrupt block relative dba: 0x0180009d (file 6, block 157) Bad check value found during dbv: Data in bad block: type: 6 format: 2 rdba: 0x0180009d last change scn: 0x0000.00b1cdc3 seq: 0x1 flg: 0x04 spare1: 0x0 spare2: 0x0 spare3: 0x0 consistency value in tail: 0xcdc30601 check value in block header: 0x81c0 computed block checksum: 0xf00 DBVERIFY - Verification complete Total Pages Examined : 1280 Total Pages Processed (Data) : 9 Total Pages Failing (Data) : 0 Total Pages Processed (Index): 0 Total Pages Failing (Index): 0 Total Pages Processed (Other): 139 Total Pages Processed (Seg) : 0 Total Pages Failing (Seg) : 0 Total Pages Empty : 1131 Total Pages Marked Corrupt : 1 -- !!!!!!!!!!--表示存在壞塊 Total Pages Influx : 0 Total Pages Encrypted : 0 Highest block SCN : 11652516 (0.11652516) [oracle@oracle01 oracle01]$
有問題了已經。
查詢數據驗證問題:
SQL> select * from bbed; 1 zhaoxu 1 kingle --查詢正常,因為在buffer_cache中緩存了塊,而修改的是文件中的塊。兩個塊現在不一致,清空buffer cache后再次查詢測試表。 SQL> alter system flush buffer_cache; System altered. SQL> select * from bbed; select * from bbed * ERROR at line 1: ORA-01578: ORACLE data block corrupted (file # 6, block # 157) ORA-01110: data file 6: '/u01/app/oracle/oradata/oracle01/test01.dbf'
校驗壞塊:
SQL> analyze table bbed validate structure cascade online 2 ; analyze table bbed validate structure cascade online * ERROR at line 1: ORA-01578: ORACLE data block corrupted (file # 6, block # 157) ORA-01110: data file 6: '/u01/app/oracle/oradata/oracle01/test01.dbf'
rman校驗壞塊:
[oracle@oracle01 ~]$ rman target / Recovery Manager: Release 11.2.0.4.0 - Production on Mon May 13 16:04:06 2019 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. connected to target database: ORACLE01 (DBID=2594375557) RMAN> backup check logical validate database; Starting backup at 13-MAY-19 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=27 device type=DISK allocated channel: ORA_DISK_2 channel ORA_DISK_2: SID=149 device type=DISK allocated channel: ORA_DISK_3 channel ORA_DISK_3: SID=18 device type=DISK allocated channel: ORA_DISK_4 channel ORA_DISK_4: SID=153 device type=DISK allocated channel: ORA_DISK_5 channel ORA_DISK_5: SID=30 device type=DISK allocated channel: ORA_DISK_6 channel ORA_DISK_6: SID=152 device type=DISK allocated channel: ORA_DISK_7 channel ORA_DISK_7: SID=20 device type=DISK allocated channel: ORA_DISK_8 channel ORA_DISK_8: SID=125 device type=DISK allocated channel: ORA_DISK_9 channel ORA_DISK_9: SID=29 device type=DISK allocated channel: ORA_DISK_10 channel ORA_DISK_10: SID=146 device type=DISK allocated channel: ORA_DISK_11 channel ORA_DISK_11: SID=26 device type=DISK allocated channel: ORA_DISK_12 channel ORA_DISK_12: SID=154 device type=DISK channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00002 name=/u01/app/oracle/oradata/oracle01/sysaux01.dbf channel ORA_DISK_2: starting compressed full datafile backup set channel ORA_DISK_2: specifying datafile(s) in backup set input datafile file number=00001 name=/u01/app/oracle/oradata/oracle01/system01.dbf channel ORA_DISK_3: starting compressed full datafile backup set channel ORA_DISK_3: specifying datafile(s) in backup set input datafile file number=00005 name=/u01/app/oracle/oradata/oracle01/example01.dbf channel ORA_DISK_4: starting compressed full datafile backup set channel ORA_DISK_4: specifying datafile(s) in backup set input datafile file number=00003 name=/u01/app/oracle/oradata/oracle01/undotbs01.dbf channel ORA_DISK_5: starting compressed full datafile backup set channel ORA_DISK_5: specifying datafile(s) in backup set including current control file in backup set channel ORA_DISK_6: starting compressed full datafile backup set channel ORA_DISK_6: specifying datafile(s) in backup set input datafile file number=00006 name=/u01/app/oracle/oradata/oracle01/test01.dbf channel ORA_DISK_7: starting compressed full datafile backup set channel ORA_DISK_7: specifying datafile(s) in backup set input datafile file number=00007 name=/u01/app/oracle/oradata/oracle01/test101.dbf channel ORA_DISK_8: starting compressed full datafile backup set channel ORA_DISK_8: specifying datafile(s) in backup set input datafile file number=00004 name=/u01/app/oracle/oradata/oracle01/users01.dbf channel ORA_DISK_9: starting compressed full datafile backup set channel ORA_DISK_9: specifying datafile(s) in backup set including current SPFILE in backup set channel ORA_DISK_9: backup set complete, elapsed time: 00:00:00 List of Control File and SPFILE =============================== File Type Status Blocks Failing Blocks Examined ------------ ------ -------------- --------------- SPFILE OK 0 2 channel ORA_DISK_5: backup set complete, elapsed time: 00:00:01 List of Control File and SPFILE =============================== File Type Status Blocks Failing Blocks Examined ------------ ------ -------------- --------------- Control File OK 0 2166 channel ORA_DISK_7: backup set complete, elapsed time: 00:00:03 List of Datafiles ================= File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 7 OK 0 1142 1280 10234981 File Name: /u01/app/oracle/oradata/oracle01/test101.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 0 5 Index 0 0 Other 0 133 channel ORA_DISK_8: backup set complete, elapsed time: 00:00:03 List of Datafiles ================= File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 4 OK 0 18 673 4459656 File Name: /u01/app/oracle/oradata/oracle01/users01.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 0 91 Index 0 44 Other 0 487 channel ORA_DISK_6: backup set complete, elapsed time: 00:00:07 List of Datafiles ================= File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 6 FAILED 0 1131 1280 11652516 File Name: /u01/app/oracle/oradata/oracle01/test01.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 1 10 Index 0 0 Other 0 139 validate found one or more corrupt blocks See trace file /u01/app/oracle/diag/rdbms/oracle01_oracle01/oracle01/trace/oracle01_ora_32029.trc for details channel ORA_DISK_3: backup set complete, elapsed time: 00:00:27 List of Datafiles ================= File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 5 OK 0 33725 44321 10634562 File Name: /u01/app/oracle/oradata/oracle01/example01.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 0 6602 Index 0 1149 Other 0 2844 channel ORA_DISK_4: backup set complete, elapsed time: 00:00:37 List of Datafiles ================= File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 3 OK 0 1 37120 11655690 File Name: /u01/app/oracle/oradata/oracle01/undotbs01.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 0 0 Index 0 0 Other 0 37119 channel ORA_DISK_1: backup set complete, elapsed time: 00:00:57 List of Datafiles ================= File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 2 OK 0 23694 144688 11655688 File Name: /u01/app/oracle/oradata/oracle01/sysaux01.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 0 49306 Index 0 41475 Other 0 30165 channel ORA_DISK_2: backup set complete, elapsed time: 00:00:57 List of Datafiles ================= File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 1 OK 0 15655 103751 11655690 File Name: /u01/app/oracle/oradata/oracle01/system01.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 0 65027 Index 0 13867 Other 0 9131 Finished backup at 13-MAY-19 RMAN> backup check logical validate datafile 6; Starting backup at 13-MAY-19 using channel ORA_DISK_1 using channel ORA_DISK_2 using channel ORA_DISK_3 using channel ORA_DISK_4 using channel ORA_DISK_5 using channel ORA_DISK_6 using channel ORA_DISK_7 using channel ORA_DISK_8 using channel ORA_DISK_9 using channel ORA_DISK_10 using channel ORA_DISK_11 using channel ORA_DISK_12 channel ORA_DISK_1: starting compressed full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00006 name=/u01/app/oracle/oradata/oracle01/test01.dbf channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 List of Datafiles ================= File Status Marked Corrupt Empty Blocks Blocks Examined High SCN ---- ------ -------------- ------------ --------------- ---------- 6 FAILED 0 1131 1280 11652516 File Name: /u01/app/oracle/oradata/oracle01/test01.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 1 10 Index 0 0 Other 0 139 validate found one or more corrupt blocks See trace file /u01/app/oracle/diag/rdbms/oracle01_oracle01/oracle01/trace/oracle01_ora_32010.trc for details Finished backup at 13-MAY-19 RMAN> ------RMAN的檢查結果放在v$database_block_corruption SQL> select file#,block#,blocks from v$database_block_corruption; 6 157 1
BBED驗證:
[oracle@oracle01 BBED]$ bbed password=blockedit parfile=par.bbd BBED: Release 2.0.0.0.0 - Limited Production on Mon May 13 16:10:39 2019 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. ************* !!! For Oracle Internal Use only !!! *************** BBED> verify dba 6,157; DBVERIFY - Verification starting FILE = /u01/app/oracle/oradata/oracle01/test01.dbf BLOCK = 157 Block 157 is corrupt Corrupt block relative dba: 0x0180009d (file 0, block 157) Bad check value found during verification Data in bad block: type: 6 format: 2 rdba: 0x0180009d last change scn: 0x0000.00b1cdc3 seq: 0x1 flg: 0x04 spare1: 0x0 spare2: 0x0 spare3: 0x0 consistency value in tail: 0xcdc30601 check value in block header: 0x81c0 computed block checksum: 0xf00 DBVERIFY - Verification complete Total Blocks Examined : 1 Total Blocks Processed (Data) : 0 Total Blocks Failing (Data) : 0 Total Blocks Processed (Index): 0 Total Blocks Failing (Index): 0 Total Blocks Empty : 0 Total Blocks Marked Corrupt : 1 Total Blocks Influx : 0 Message 531 not found; product=RDBMS; facility=BBED
EXPDP驗證:
(需要備份文件)
--格式 exp system/123456 file=/home/oracle/ltest.dmp tables=bbed 需要開始對單表備份才能操作出結果
四,壞塊恢復:
有備份的情況下:
RMAN> blockrecover datafile 6 block 157 from backupset; Starting recover at 13-MAY-19 using channel ORA_DISK_1 using channel ORA_DISK_2 using channel ORA_DISK_3 using channel ORA_DISK_4 using channel ORA_DISK_5 using channel ORA_DISK_6 using channel ORA_DISK_7 using channel ORA_DISK_8 using channel ORA_DISK_9 using channel ORA_DISK_10 using channel ORA_DISK_11 using channel ORA_DISK_12 searching flashback logs for block images finished flashback log search, restored 0 blocks RMAN-00571: =========================================================== RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS =============== RMAN-00571: =========================================================== RMAN-03002: failure of recover command at 05/13/2019 16:32:13 RMAN-06026: some targets not found - aborting restore RMAN-06023: no backup or copy of datafile 6 found to restore RMAN-06023: no backup or copy of datafile 6 found to restore
沒有備份:
查詢定位壞塊:
SQL> select segment_name,partition_name,segment_type,owner,tablespace_name from sys.dba_extents where file_id=&AFN and &bad_block_id between block_id and block_id + blocks-1; 2 3 4 Enter value for afn: 6 old 3: where file_id=&AFN new 3: where file_id=6 Enter value for bad_block_id: 157 old 4: and &bad_block_id between block_id and block_id + blocks-1 new 4: and 157 between block_id and block_id + blocks-1 SEGMENT_NAME -------------------------------------------------------------------------------- PARTITION_NAME SEGMENT_TYPE OWNER ------------------------------ ------------------ ------------------------------ TABLESPACE_NAME ------------------------------ BBED TABLE SYS TT1
----算了跳過壞塊吧
重建