塊損壞的恢復(fù)
一、沒有備份的情況下,塊損壞,并且塊所存儲的是數(shù)據(jù)
SQL> conn olive/olive 已連接。 SQL> create table t as select * from dba_users; 表已創(chuàng)建。
SQL> select count(*)from t;
COUNT(*)
---------- 28 SQL> /
COUNT(*)
---------- 28 SQL> /
COUNT(*)
---------- 28 SQL> insert into t select * from t;
已創(chuàng)建28行。
SQL> /
已創(chuàng)建56行。
SQL> /
已創(chuàng)建112行。
SQL> /
已創(chuàng)建224行。
SQL> /
已創(chuàng)建448行。
SQL> /
已創(chuàng)建896行。
SQL> /
已創(chuàng)建1792行。
SQL> /
已創(chuàng)建3584行。
SQL> /
insert into t select * from t * 第 1 行出現(xiàn)錯誤: ORA-01653: 表 OLIVE.T 無法通過 8 (在表空間 BLOCK 中) 擴(kuò)展 SQL> commit; 提交完成。
SQL> select count(*)from t;
COUNT(*)
---------- 7168 SQL> conn olive/olive
已連接。 SQL> select count(*) from t; select count(*) from t * 第 1 行出現(xiàn)錯誤: ORA-01578: ORACLE 數(shù)據(jù)塊損壞 (文件號 6, 塊號 116) ORA-01110: 數(shù)據(jù)文件 6: 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\BLOCK.DBF' alert.log中
Hex dump of (file 6, block 116) in trace file d:\oracle\product\10.2.0\admin\orcl\udump\orcl_ora_1424.trc Corrupt block relative dba: 0x01800074 (file 6, block 116) Bad check value found during buffer read Data in bad block: type: 6 format: 2 rdba: 0x01800074 last change scn: 0x0000.0008e356 seq: 0x1 flg: 0x06 spare1: 0x0 spare2: 0x0 spare3: 0x0 consistency value in tail: 0xe3560601 check value in block header: 0x8f60 computed block checksum: 0x281e Reread of rdba: 0x01800074 (file 6, block 116) found same corrupted data Fri Jan 26 13:22:59 2007 Corrupt Block Found TSN = 7, TSNAME = BLOCK RFN = 6, BLK = 116, RDBA = 25165940 OBJN = 52546, OBJD = 52546, OBJECT = T, SUBOBJECT = SEGMENT OWNER = OLIVE, SEGMENT TYPE = Table Segment 使用dbv檢查數(shù)據(jù)文件 D:\oracle\product\10.2.0\oradata\orcl>dbv file=block.dbf blocksize=8192
DBVERIFY: Release 10.2.0.1.0 - Production on 星期五 1月 26 13:27:12 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
DBVERIFY - 開始驗(yàn)證: FILE = block.dbf
頁 116 標(biāo)記為損壞 Corrupt block relative dba: 0x01800074 (file 6, block 116) Bad check value found during dbv: Data in bad block: type: 6 format: 2 rdba: 0x01800074 last change scn: 0x0000.0008e356 seq: 0x1 flg: 0x06 spare1: 0x0 spare2: 0x0 spare3: 0x0 consistency value in tail: 0xe3560601 check value in block header: 0x8f60 computed block checksum: 0x281e DBVERIFY - 驗(yàn)證完成
檢查的頁總數(shù): 128
處理的頁總數(shù) (數(shù)據(jù)): 109 失敗的頁總數(shù) (數(shù)據(jù)): 0 處理的頁總數(shù) (索引): 0 失敗的頁總數(shù) (索引): 0 處理的頁總數(shù) (其它): 18 處理的總頁數(shù) (段) : 0 失敗的總頁數(shù) (段) : 0 空的頁總數(shù): 0 標(biāo)記為損壞的總頁數(shù): 1 流入的頁總數(shù): 0 最高塊 SCN : 582511 (0.582511) 準(zhǔn)備導(dǎo)出該表
D:\oracle\product\10.2.0\oradata\orcl>exp olive/olive file=d:\t.dmp tables=(T);
Export: Release 10.2.0.1.0 - Production on 星期五 1月 26 13:31:34 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
連接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options 已導(dǎo)出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集 即將導(dǎo)出指定的表通過常規(guī)路徑...
. . 正在導(dǎo)出表 T EXP-00056: 遇到 ORACLE 錯誤 1578 ORA-01578: ORACLE 數(shù)據(jù)塊損壞 (文件號 6, 塊號 116) ORA-01110: 數(shù)據(jù)文件 6: 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\BLOCK.DBF' EXP-00011: OLIVE.; 不存在 導(dǎo)出成功終止, 但出現(xiàn)警告。 D:\oracle\product\10.2.0\oradata\orcl>
5.恢復(fù)步驟 當(dāng)然,對于不同的情況需要區(qū)別對待
首先你需要檢查損壞的對象,使用以下SQL:
SQL> SELECT tablespace_name, segment_type, owner, segment_name,block_id,blocks FROM dba_extents 2 WHERE file_id = 6 3 and 116 between block_id AND block_id + blocks -1 4 ; TABLESPACE_NAME SEGMENT_TYPE OWNER SEGMENT_NAME BLOCK_ID BLOCKS
------------------ -------------- ------------- ------------- --------- ---------- BLOCK TABLE OLIVE T 113 8 發(fā)現(xiàn)是表中數(shù)據(jù)損壞 我們可以設(shè)置內(nèi)部事件,使exp跳過這些損壞的block
SQL> ALTER SYSTEM SET EVENTS='10231 trace name context forever,level 10';
系統(tǒng)已更改。
SQL>
ALTER SYSTEM SET EVENTS='10231 trace name context forever,level 10' ;
內(nèi)部事件,設(shè)置在全表掃描時跳過損壞的數(shù)據(jù)塊. D:\oracle\product\10.2.0\oradata\orcl>exp olive/olive file=d:\t.dmp tables=(T);
Export: Release 10.2.0.1.0 - Production on 星期五 1月 26 13:49:20 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
連接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options 已導(dǎo)出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集 即將導(dǎo)出指定的表通過常規(guī)路徑...
. . 正在導(dǎo)出表 T導(dǎo)出了 7102 行 EXP-00011: OLIVE.; 不存在 導(dǎo)出成功終止, 但出現(xiàn)警告。 D:\oracle\product\10.2.0\oradata\orcl>
損失數(shù)據(jù) 7168-7102=66條 刪除表并從備份中導(dǎo)入 SQL> conn olive/olive
已連接。 SQL> drop table t; 表已刪除。
SQL> host
Microsoft Windows 2000 [Version 5.00.2195] (C) 版權(quán)所有 1985-2000 Microsoft Corp. C:\Documents and Settings\Administrator.XY>imp olive/olive file=d:\t.dmp tables=
(t); Import: Release 10.2.0.1.0 - Production on 星期五 1月 26 13:53:31 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
連接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options 經(jīng)由常規(guī)路徑由 EXPORT:V10.02.01 創(chuàng)建的導(dǎo)出文件
已經(jīng)完成 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集中的導(dǎo)入 . 正在將 OLIVE 的對象導(dǎo)入到 OLIVE . 正在將 OLIVE 的對象導(dǎo)入到 OLIVE . . 正在導(dǎo)入表 "T"導(dǎo)入了 7102 行 IMP-00033: 警告: 在導(dǎo)出文件中未找到表 ";" 成功終止導(dǎo)入, 但出現(xiàn)警告。 C:\Documents and Settings\Administrator.XY>sqlplus olive/olive
SQL*Plus: Release 10.2.0.1.0 - Production on 星期五 1月 26 13:53:58 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
連接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options SQL> select count(*) from t;
COUNT(*)
---------- 7102 SQL>
二、通過備份進(jìn)行修復(fù)被損壞的塊,blockrecover
1、數(shù)據(jù)總計(jì)7102條
C:\Documents and Settings\Administrator.XY>sqlplus olive/olive SQL*Plus: Release 10.2.0.1.0 - Production on 星期五 1月 26 13:53:58 2007
Copyright (c) 1982, 2005, Oracle. All rights reserved.
連接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options SQL> select count(*) from t;
COUNT(*)
---------- 7102 SQL>
人為損壞數(shù)據(jù)塊 alert.log Hex dump of (file 6, block 71) in trace file d:\oracle\product\10.2.0\admin\orcl\udump\orcl_ora_8336.trc
Corrupt block relative dba: 0x01800047 (file 6, block 71) Bad check value found during buffer read Data in bad block: type: 6 format: 2 rdba: 0x01800047 last change scn: 0x0000.0009e8ba seq: 0x1 flg: 0x06 spare1: 0x0 spare2: 0x0 spare3: 0x0 consistency value in tail: 0xe8ba0601 check value in block header: 0x725b computed block checksum: 0xab79 SQL> select count(*) from t;
select count(*) from t * 第 1 行出現(xiàn)錯誤: ORA-01578: ORACLE 數(shù)據(jù)塊損壞 (文件號 6, 塊號 71) ORA-01110: 數(shù)據(jù)文件 6: 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\BLOCK.DBF' SQL> 使用rman檢驗(yàn)數(shù)據(jù)文件
RMAN> backup validate datafile 6; 啟動 backup 于 26-1月 -07
分配的通道: ORA_DISK_1 通道 ORA_DISK_1: sid=142 devtype=DISK 通道 ORA_DISK_1: 啟動全部數(shù)據(jù)文件備份集 通道 ORA_DISK_1: 正在指定備份集中的數(shù)據(jù)文件 輸入數(shù)據(jù)文件 fno=00006 name=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\BLOCK.DBF 通道 ORA_DISK_1: 備份集已完成, 經(jīng)過時間:00:00:03 完成 backup 于 26-1月 -07 發(fā)現(xiàn)壞塊
Hex dump of (file 6, block 71) in trace file d:\oracle\product\10.2.0\admin\orcl\udump\orcl_ora_8484.trc Corrupt block relative dba: 0x01800047 (file 6, block 71) Bad check value found during backing up datafile Data in bad block: type: 6 format: 2 rdba: 0x01800047 last change scn: 0x0000.0009e8ba seq: 0x1 flg: 0x06 spare1: 0x0 spare2: 0x0 spare3: 0x0 consistency value in tail: 0xe8ba0601 check value in block header: 0x725b computed block checksum: 0xab79 Reread of blocknum=71, file=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\BLOCK.DBF. found same corrupt data Reread of blocknum=71, file=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\BLOCK.DBF. found same corrupt data Reread of blocknum=71, file=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\BLOCK.DBF. found same corrupt data Reread of blocknum=71, file=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\BLOCK.DBF. found same corrupt data Reread of blocknum=71, file=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\BLOCK.DBF. found same corrupt data Reread of rdba: 0x01800047 (file 6, block 71) found same corrupted data
只有使用rman檢驗(yàn)數(shù)據(jù)文件發(fā)現(xiàn)壞塊v$database_block_corruption才有數(shù)據(jù)。 SQL> select * from v$database_block_corruption where file#=6; FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ --------- 6 71 1 0 CHECKSUM SQL>
RMAN> blockrecover datafile 6 block 71 from backupset;
啟動 blockrecover 于 26-1月 -07
使用通道 ORA_DISK_1 通道 ORA_DISK_1: 正在恢復(fù)塊
通道 ORA_DISK_1: 正在指定要從備份集恢復(fù)的塊 正在恢復(fù)數(shù)據(jù)文件 00006 的塊 通道 ORA_DISK_1: 正在讀取備份段 D:\FULL.BAK 通道 ORA_DISK_1: 已從備份段 1 恢復(fù)塊 段句柄 = D:\FULL.BAK 標(biāo)記 = 20070126 通道 ORA_DISK_1: 塊恢復(fù)完成, 用時: 00:00:01 正在開始介質(zhì)的恢復(fù)
介質(zhì)恢復(fù)完成, 用時: 00:00:08 完成 blockrecover 于 26-1月 -07
RMAN>
SQL> select count(*) from olive.t; COUNT(*)
---------- 7102 SQL> select * from v$database_block_corruption where file#=6; FILE# BLOCK# BLOCKS CORRUPTION_CHANGE# CORRUPTIO
---------- ---------- ---------- ------------------ --------- 6 71 1 0 CHECKSUM v$database_block_corruption中的信息只有下次執(zhí)行檢驗(yàn)數(shù)據(jù)文件后才清除 呵呵,DBA 的基本知識,制造壞塊的方法很多的
可以用ultraedit,也可以用dd命令 同時也呆以用orapatch工具 $orapatch open tools001.dbf write patch>set hex --要用十六進(jìn)制 patch>display 177 --orapatch以512字節(jié)為工作模式,假定想破壞第11個block即為:8k/512*11+1(file header) patch>find 00400003 --選一個要編輯的點(diǎn) patch>modify 00400002 --破壞 patch>exit |
|