塊損壞的恢復
一、沒有備份的情況下,塊損壞,并且塊所存儲的是數據
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 行出現錯誤:
ORA-01653: 表 OLIVE.T 無法通過 8 (在表空間 BLOCK 中) 擴展
SQL> commit;
提交完成。
SQL> select count(*)from t;
COUNT(*)
----------
7168
SQL> conn olive/olive
已連接。
SQL> select count(*) from t;
select count(*) from t
*
第 1 行出現錯誤:
ORA-01578: ORACLE 數據塊損壞 (文件號 6, 塊號 116)
ORA-01110: 數據文件 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檢查數據文件
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 - 開始驗證: FILE = block.dbf
頁 116 標記為損壞
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 - 驗證完成
檢查的頁總數: 128
處理的頁總數 (數據): 109
失敗的頁總數 (數據): 0
處理的頁總數 (索引): 0
失敗的頁總數 (索引): 0
處理的頁總數 (其它): 18
處理的總頁數 (段) : 0
失敗的總頁數 (段) : 0
空的頁總數: 0
標記為損壞的總頁數: 1
流入的頁總數: 0
最高塊 SCN : 582511 (0.582511)
準備導出該表
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
已導出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集
即將導出指定的表通過常規(guī)路徑...
. . 正在導出表 T
EXP-00056: 遇到 ORACLE 錯誤 1578
ORA-01578: ORACLE 數據塊損壞 (文件號 6, 塊號 116)
ORA-01110: 數據文件 6: 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\BLOCK.DBF'
EXP-00011: OLIVE.; 不存在
導出成功終止, 但出現警告。
D:\oracle\product\10.2.0\oradata\orcl>
5.恢復步驟
當然,對于不同的情況需要區(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ā)現是表中數據損壞
我們可以設置內部事件,使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' ;
內部事件,設置在全表掃描時跳過損壞的數據塊.
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
已導出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集
即將導出指定的表通過常規(guī)路徑...
. . 正在導出表 T導出了 7102 行
EXP-00011: OLIVE.; 不存在
導出成功終止, 但出現警告。
D:\oracle\product\10.2.0\oradata\orcl>
損失數據 7168-7102=66條
刪除表并從備份中導入
SQL> conn olive/olive
已連接。
SQL> drop table t;
表已刪除。
SQL> host
Microsoft Windows 2000 [Version 5.00.2195]
(C) 版權所有 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
經由常規(guī)路徑由 EXPORT:V10.02.01 創(chuàng)建的導出文件
已經完成 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集中的導入
. 正在將 OLIVE 的對象導入到 OLIVE
. 正在將 OLIVE 的對象導入到 OLIVE
. . 正在導入表 "T"導入了 7102 行
IMP-00033: 警告: 在導出文件中未找到表 ";"
成功終止導入, 但出現警告。
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>
二、通過備份進行修復被損壞的塊,blockrecover
1、數據總計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>
人為損壞數據塊
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 行出現錯誤:
ORA-01578: ORACLE 數據塊損壞 (文件號 6, 塊號 71)
ORA-01110: 數據文件 6: 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\BLOCK.DBF'
SQL>
使用rman檢驗數據文件
RMAN> backup validate datafile 6;
啟動 backup 于 26-1月 -07
分配的通道: ORA_DISK_1
通道 ORA_DISK_1: sid=142 devtype=DISK
通道 ORA_DISK_1: 啟動全部數據文件備份集
通道 ORA_DISK_1: 正在指定備份集中的數據文件
輸入數據文件 fno=00006 name=D:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\BLOCK.DBF
通道 ORA_DISK_1: 備份集已完成, 經過時間:00:00:03
完成 backup 于 26-1月 -07
發(fā)現壞塊
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檢驗數據文件發(fā)現壞塊v$database_block_corruption才有數據。
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: 正在恢復塊
通道 ORA_DISK_1: 正在指定要從備份集恢復的塊
正在恢復數據文件 00006 的塊
通道 ORA_DISK_1: 正在讀取備份段 D:\FULL.BAK
通道 ORA_DISK_1: 已從備份段 1 恢復塊
段句柄 = D:\FULL.BAK 標記 = 20070126
通道 ORA_DISK_1: 塊恢復完成, 用時: 00:00:01
正在開始介質的恢復
介質恢復完成, 用時: 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í)行檢驗數據文件后才清除
呵呵,DBA 的基本知識,制造壞塊的方法很多的
可以用ultraedit,也可以用dd命令
同時也呆以用orapatch工具
$orapatch open tools001.dbf write
patch>set hex --要用十六進制
patch>display 177 --orapatch以512字節(jié)為工作模式,假定想破壞第11個block即為:8k/512*11+1(file header)
patch>find 00400003 --選一個要編輯的點
patch>modify 00400002 --破壞
patch>exit