TOMSYAN 发表于 2011-12-22 08:54

利用数据库闪回来处理坏块

<P><FONT face=宋体>ORACLE数据库闪回可以把整个数据库闪回到过去的某一个时间点。<BR>数据库闪回类似于不完全恢复,但和不完全恢复又有很多区别。<BR>数据库闪回可以恢复数据删除、表删除等用户错误,但是闪回却不能解决物理损坏,譬如文件删除等。<BR>虽然ORACLE的数据库闪回不能解决物理损坏等错误,但有时候可以解决数据库坏块。<BR>当然处理数据库坏块最方便的方法莫过于RMAN的BLOCKRECOVER命令,而且如果闪回日志中不存在相关坏块的前映像的话,<BR>这个方法也行不通了。</FONT></P>
<P><FONT face=宋体>有关数据库的闪回配置可以参考metalink 文档 NOTE:ID 249319.1。</FONT></P>
<P><FONT face=宋体>以下是一个简单的利用数据库闪回修复坏块的例子:</FONT></P>
<P><FONT face=宋体>C:\Documents and Settings\shoupeng.yan&gt;sqlplus test/test</FONT></P>
<P><FONT face=宋体>SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 8月 22 14:13:37 2011</FONT></P>
<P><FONT face=宋体>Copyright (c) 1982, 2005, Oracle.&nbsp; All rights reserved.</FONT></P>
<P><BR><FONT face=宋体>连接到:<BR>Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production<BR>With the Partitioning, OLAP and Data Mining options</FONT></P>
<P><FONT face=宋体>SQL&gt; SHOW PARAMETER DB_BLOCK_SIZE</FONT></P>
<P><FONT face=宋体>NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TYPE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALUE<BR>------------------------------------ ----------- ------------------------------<BR>db_block_size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; integer&nbsp;&nbsp;&nbsp;&nbsp; 8192</FONT></P>
<P><FONT face=宋体>SQL&gt; CREATE TABLE T(ID INT,COL1 CHAR(2000),COL2 CHAR(2000),COL3 CHAR(2000));</FONT></P>
<P><FONT face=宋体>表已创建。</FONT></P>
<P><FONT face=宋体>首先创建表T,定义3个长度是2000的列,BLOC大小K是8K的,为了方便起见,这样每个块只能存放一条记录。</FONT></P>
<P><FONT face=宋体>然后往表里插入6条记录:</FONT></P>
<P><FONT face=宋体>SQL&gt; INSERT INTO T VALUES(1,RPAD('1',2000,'1'),RPAD('1',2000,'1'),RPAD('1',2000,'1'));</FONT></P>
<P><FONT face=宋体>已创建 1 行。</FONT></P>
<P><FONT face=宋体>SQL&gt; INSERT INTO T VALUES(2,RPAD('2',2000,'2'),RPAD('2',2000,'2'),RPAD('2',2000,'2'));</FONT></P>
<P><FONT face=宋体>已创建 1 行。</FONT></P>
<P><FONT face=宋体>SQL&gt; INSERT INTO T VALUES(3,RPAD('3',2000,'3'),RPAD('3',2000,'3'),RPAD('3',2000,'3'));</FONT></P>
<P><FONT face=宋体>已创建 1 行。</FONT></P>
<P><FONT face=宋体>SQL&gt; INSERT INTO T VALUES(4,RPAD('4',2000,'4'),RPAD('4',2000,'4'),RPAD('4',2000,'4'));</FONT></P>
<P><FONT face=宋体>已创建 1 行。</FONT></P>
<P><FONT face=宋体>SQL&gt; INSERT INTO T VALUES(5,RPAD('5',2000,'5'),RPAD('5',2000,'5'),RPAD('5',2000,'5'));</FONT></P>
<P><FONT face=宋体>已创建 1 行。</FONT></P>
<P><FONT face=宋体>SQL&gt; INSERT INTO T VALUES(6,RPAD('6',2000,'6'),RPAD('6',2000,'6'),RPAD('6',2000,'6'));</FONT></P>
<P><FONT face=宋体>已创建 1 行。</FONT></P>
<P><FONT face=宋体>SQL&gt; COMMIT;</FONT></P>
<P><FONT face=宋体>提交完成。</FONT></P>
<P><FONT face=宋体>SQL&gt; SELECT ID,DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) FILE#,<BR>&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) BLOCK#<BR>&nbsp; 3&nbsp; FROM T<BR>&nbsp; 4&nbsp; ORDER BY ID;</FONT></P>
<P><FONT face=宋体>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FILE#&nbsp;&nbsp;&nbsp;&nbsp; BLOCK#<BR>---------- ---------- ----------<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1568<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1564<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1565<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1566<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1567<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1570</FONT></P>
<P><FONT face=宋体>已选择6行。</FONT></P>
<P><FONT face=宋体>SQL&gt; CONN / AS SYSDBA<BR>已连接。<BR>SQL&gt; SELECT FLASHBACK_ON,LOG_MODE FROM V$DATABASE;</FONT></P>
<P><FONT face=宋体>FLASHBACK_ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LOG_MODE<BR>------------------ ------------<BR>NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ARCHIVELOG</FONT></P>
<P><FONT face=宋体>SQL&gt; SHUTDOWN IMMEDIATE<BR>数据库已经关闭。<BR>已经卸载数据库。<BR>ORACLE 例程已经关闭。<BR>SQL&gt; STARTUP MOUNT<BR>ORACLE 例程已经启动。</FONT></P>
<P><FONT face=宋体>Total System Global Area&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1073741824 bytes<BR>Fixed Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1250044 bytes<BR>Variable Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 746589444 bytes<BR>Database Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 318767104 bytes<BR>Redo Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7135232 bytes<BR>数据库装载完毕。<BR>SQL&gt; ALTER DATABASE FLASHBACK ON;</FONT></P>
<P><FONT face=宋体>数据库已更改。</FONT></P>
<P><FONT face=宋体>SQL&gt; ALTER DATABASE OPEN;</FONT></P>
<P><FONT face=宋体>数据库已更改。</FONT></P>
<P><FONT face=宋体>SQL&gt; SELECT FLASHBACK_ON,LOG_MODE FROM V$DATABASE;</FONT></P>
<P><FONT face=宋体>FLASHBACK_ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LOG_MODE<BR>------------------ ------------<BR>YES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ARCHIVELOG</FONT></P>
<P><FONT face=宋体>数据库已经处于闪回状态,这样每当我们修改记录的时候,ORACLE将相关记录的BLOCK复制到闪回日志中。<BR>准备工作已经完成。</FONT></P>
<P><BR><FONT face=宋体>我们修改ID=5的记录,这样ORACLE会把ID=5的记录所在的块1567的块复制到闪回日志中。</FONT></P>
<P><BR><FONT face=宋体>SQL&gt; ALTER SESSION SET NLS_DATE_FORMAT='YYYY/MM/DD HH24:MI:SS';</FONT></P>
<P><FONT face=宋体>会话已更改。</FONT></P>
<P><FONT face=宋体>SQL&gt; SELECT DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER,SYSDATE FROM DUAL;</FONT></P>
<P><FONT face=宋体>GET_SYSTEM_CHANGE_NUMBER SYSDATE<BR>------------------------ -------------------<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 9063211692914 2011/08/22 15:37:01</FONT></P>
<P><FONT face=宋体>SQL&gt; ALTER SYSTEM SWITCH LOGFILE;</FONT></P>
<P><FONT face=宋体>系统已更改。</FONT></P>
<P><FONT face=宋体>SQL&gt; UPDATE T<BR>&nbsp; 2&nbsp; SET COL1=RPAD('A',2000,'A')<BR>&nbsp; 3&nbsp; WHERE ID=5;</FONT></P>
<P><FONT face=宋体>已更新 1 行。</FONT></P>
<P><FONT face=宋体>SQL&gt; COMMIT;</FONT></P>
<P><FONT face=宋体>提交完成。</FONT></P>
<P><FONT face=宋体>SQL&gt; ALTER SYSTEM SWITCH LOGFILE;</FONT></P>
<P><FONT face=宋体>系统已更改。</FONT></P>
<P><FONT face=宋体>SQL&gt;&nbsp; SELECT DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER,SYSDATE FROM DUAL;</FONT></P>
<P><FONT face=宋体>GET_SYSTEM_CHANGE_NUMBER SYSDATE<BR>------------------------ -------------------<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 9063211692951 2011/08/22 15:38:37</FONT></P>
<P><FONT face=宋体></FONT>&nbsp;</P>
<P><FONT face=宋体>用UtralEdit打开数据文件将记录5和6修改,以模拟坏块。</FONT></P>
<P><BR><FONT face=宋体>SQL&gt; SELECT TO_CHAR(1567*8192,'XXXXXXXX') FROM DUAL;</FONT></P>
<P><FONT face=宋体>TO_CHAR(1<BR>---------<BR>&nbsp;&nbsp; C3E000</FONT></P>
<P><FONT face=宋体>SQL&gt; SELECT TO_CHAR(1568*8192,'XXXXXXXX') FROM DUAL;</FONT></P>
<P><FONT face=宋体>TO_CHAR(1<BR>---------<BR>&nbsp;&nbsp; C40000</FONT></P>
<P><FONT face=宋体>根据块号的块大小可以确定记录5位于文件位置的C3E000-C40000之间。</FONT></P>
<P><FONT face=宋体>SQL&gt; SELECT TO_CHAR(1570*8192,'XXXXXXXX') FROM DUAL;</FONT></P>
<P><FONT face=宋体>TO_CHAR(1<BR>---------<BR>&nbsp;&nbsp; C44000</FONT></P>
<P><FONT face=宋体>SQL&gt; SELECT TO_CHAR(1571*8192,'XXXXXXXX') FROM DUAL;</FONT></P>
<P><FONT face=宋体>TO_CHAR(1<BR>---------<BR>&nbsp;&nbsp; C46000</FONT></P>
<P><FONT face=宋体>记录6位于文件位置的C44000-C46000之间。</FONT></P>
<P><FONT face=宋体>&nbsp;关闭数据库修改数据文件,修改完毕打开数据库。</FONT></P>
<P><FONT face=宋体>SQL&gt; SHUTDOWN IMMEDIATE<BR>ORA-01031: 权限不足<BR>SQL&gt; CONN / AS SYSDBA<BR>已连接。<BR>SQL&gt; SHUTDOWN IMMEDIATE<BR>数据库已经关闭。<BR>已经卸载数据库。<BR>ORACLE 例程已经关闭。<BR>SQL&gt; STARTUP<BR>ORACLE 例程已经启动。</FONT></P>
<P><FONT face=宋体>Total System Global Area&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1073741824 bytes<BR>Fixed Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1250044 bytes<BR>Variable Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 738200836 bytes<BR>Database Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 327155712 bytes<BR>Redo Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7135232 bytes<BR>数据库装载完毕。<BR>数据库已经打开。</FONT></P>
<P><BR><FONT face=宋体>SQL&gt; CONN TEST/TEST<BR>已连接。<BR>SQL&gt;&nbsp; SELECT ID FROM T;<BR>ERROR:<BR>ORA-01578: ORACLE 数据块损坏 (文件号 7, 块号 1567)<BR>ORA-01110: 数据文件 7:<BR>'C:\U01\ORACLE\PRODUCT\10.2.0\ORADATA\YANSP\YANSP\TEST02.DBF'</FONT></P>
<P><FONT face=宋体></FONT>&nbsp;</P>
<P><FONT face=宋体>未选定行</FONT></P>
<P><FONT face=宋体>SQL&gt;&nbsp; ALTER SESSION SET EVENTS '10231 TRACE NAME CONTEXT FOREVER,LEVEL 10';</FONT></P>
<P><FONT face=宋体>会话已更改。</FONT></P>
<P><FONT face=宋体>SQL&gt; SELECT ID FROM T ORDER BY ID;</FONT></P>
<P><FONT face=宋体>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ID<BR>--------------------<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4</FONT></P>
<P><BR><FONT face=宋体>设置10231事件可以让ORACLE跳过坏块,可以看到,ID=5和ID=6的记录已经跳过了。</FONT></P>
<P><FONT face=宋体>通过DBV也可以看出块1567和1570已经是坏块:</FONT></P>
<P><FONT face=宋体>Microsoft Windows XP [版本 5.1.2600]<BR>(C) 版权所有 1985-2001 Microsoft Corp.</FONT></P>
<P><FONT face=宋体>C:\Documents and Settings\shoupeng.yan&gt;dbv file=C:\U01\ORACLE\PRODUCT\10.2.0\ORADATA\YANSP\YANSP\TEST02.DBF</FONT></P>
<P><FONT face=宋体>DBVERIFY: Release 10.2.0.1.0 - Production on 星期一 8月 22 15:47:38 2011</FONT></P>
<P><FONT face=宋体>Copyright (c) 1982, 2005, Oracle.&nbsp; All rights reserved.</FONT></P>
<P><FONT face=宋体>DBVERIFY - 开始验证: FILE = C:\U01\ORACLE\PRODUCT\10.2.0\ORADATA\YANSP\YANSP\TES<BR>T02.DBF<BR>页 1567 标记为损坏<BR>Corrupt block relative dba: 0x01c0061f (file 7, block 1567)<BR>Bad check value found during dbv:<BR>Data in bad block:<BR>&nbsp;type: 6 format: 2 rdba: 0x01c0061f<BR>&nbsp;last change scn: 0x083e.3183738d seq: 0x1 flg: 0x06<BR>&nbsp;spare1: 0x0 spare2: 0x0 spare3: 0x0<BR>&nbsp;consistency value in tail: 0x738d0601<BR>&nbsp;check value in block header: 0xf345<BR>&nbsp;computed block checksum: 0xe29b</FONT></P>
<P><FONT face=宋体>页 1570 标记为损坏<BR>Corrupt block relative dba: 0x01c00622 (file 7, block 1570)<BR>Bad check value found during dbv:<BR>Data in bad block:<BR>&nbsp;type: 6 format: 2 rdba: 0x01c00622<BR>&nbsp;last change scn: 0x083e.318371a6 seq: 0x1 flg: 0x04<BR>&nbsp;spare1: 0x0 spare2: 0x0 spare3: 0x0<BR>&nbsp;consistency value in tail: 0x71a60601<BR>&nbsp;check value in block header: 0x884<BR>&nbsp;computed block checksum: 0x301</FONT></P>
<P><FONT face=宋体></FONT>&nbsp;</P>
<P><FONT face=宋体>DBVERIFY - 验证完成</FONT></P>
<P><FONT face=宋体>检查的页总数: 6400<BR>处理的页总数 (数据): 3212<BR>失败的页总数 (数据): 0<BR>处理的页总数 (索引): 134<BR>失败的页总数 (索引): 0<BR>处理的页总数 (其它): 145<BR>处理的总页数 (段)&nbsp; : 0<BR>失败的总页数 (段)&nbsp; : 0<BR>空的页总数: 2907<BR>标记为损坏的总页数: 2<BR>流入的页总数: 0<BR>最高块 SCN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 830697894 (2110.830697894)</FONT></P>
<P><FONT face=宋体></FONT>&nbsp;</P>
<P><FONT face=宋体></FONT>&nbsp;</P>
<P><FONT face=宋体>此时我们将数据库闪回到UPDATE语句后我们记录的那个时间点。</FONT></P>
<P><FONT face=宋体>SQL&gt; CONN / AS SYSDBA<BR>已连接。<BR>SQL&gt; SHUTDOWN IMMEDIATE<BR>数据库已经关闭。<BR>已经卸载数据库。<BR>ORACLE 例程已经关闭。<BR>SQL&gt; STARTUP MOUNT<BR>ORACLE 例程已经启动。</FONT></P>
<P><FONT face=宋体>Total System Global Area&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1073741824 bytes<BR>Fixed Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1250044 bytes<BR>Variable Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 746589444 bytes<BR>Database Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 318767104 bytes<BR>Redo Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7135232 bytes<BR>数据库装载完毕。<BR>SQL&gt; FLASHBACK DATABASE TO SCN 9063211692951;</FONT></P>
<P><FONT face=宋体>闪回完成。</FONT></P>
<P><FONT face=宋体>SQL&gt; ALTER DATABASE OPEN READ ONLY;</FONT></P>
<P><FONT face=宋体>数据库已更改。</FONT></P>
<P><FONT face=宋体>SQL&gt; SELECT ID FROM TEST.T;<BR>ERROR:<BR>ORA-01578: ORACLE 数据块损坏 (文件号 7, 块号 1570)<BR>ORA-01110: 数据文件 7:<BR>'C:\U01\ORACLE\PRODUCT\10.2.0\ORADATA\YANSP\YANSP\TEST02.DBF'</FONT></P>
<P><FONT face=宋体></FONT>&nbsp;</P>
<P><FONT face=宋体>未选定行</FONT></P>
<P><FONT face=宋体>SQL&gt;&nbsp; ALTER SESSION SET EVENTS '10231 TRACE NAME CONTEXT FOREVER,LEVEL 10';</FONT></P>
<P><FONT face=宋体>会话已更改。</FONT></P>
<P><FONT face=宋体>SQL&gt; SELECT ID FROM TEST.T;</FONT></P>
<P><FONT face=宋体>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ID<BR>--------------------<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>可以看到块1567已经修复了,但是块1570没有被修复,这是由于这个BLOCK在闪回日志中不存在,无法覆盖掉原来的坏块。</FONT></P>
<P><FONT face=宋体>从DBV的输出中也可以看出块1567已经修复:</FONT></P>
<P><FONT face=宋体>C:\Documents and Settings\shoupeng.yan&gt;dbv file=C:\U01\ORACLE\PRODUCT\10.2.0\ORADATA\YANSP\YANSP\TEST02.DBF</FONT></P>
<P><FONT face=宋体>DBVERIFY: Release 10.2.0.1.0 - Production on 星期一 8月 22 15:57:58 2011</FONT></P>
<P><FONT face=宋体>Copyright (c) 1982, 2005, Oracle.&nbsp; All rights reserved.</FONT></P>
<P><FONT face=宋体>DBVERIFY - 开始验证: FILE = C:\U01\ORACLE\PRODUCT\10.2.0\ORADATA\YANSP\YANSP\TES<BR>T02.DBF<BR>页 1570 标记为损坏<BR>Corrupt block relative dba: 0x01c00622 (file 7, block 1570)<BR>Bad check value found during dbv:<BR>Data in bad block:<BR>&nbsp;type: 6 format: 2 rdba: 0x01c00622<BR>&nbsp;last change scn: 0x083e.318371a6 seq: 0x1 flg: 0x04<BR>&nbsp;spare1: 0x0 spare2: 0x0 spare3: 0x0<BR>&nbsp;consistency value in tail: 0x71a60601<BR>&nbsp;check value in block header: 0x884<BR>&nbsp;computed block checksum: 0x301</FONT></P>
<P><FONT face=宋体></FONT>&nbsp;</P>
<P><FONT face=宋体>DBVERIFY - 验证完成</FONT></P>
<P><FONT face=宋体>检查的页总数: 6400<BR>处理的页总数 (数据): 3213<BR>失败的页总数 (数据): 0<BR>处理的页总数 (索引): 134<BR>失败的页总数 (索引): 0<BR>处理的页总数 (其它): 145<BR>处理的总页数 (段)&nbsp; : 0<BR>失败的总页数 (段)&nbsp; : 0<BR>空的页总数: 2907<BR>标记为损坏的总页数: 1<BR>流入的页总数: 0<BR>最高块 SCN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 830698378 (2110.830698378)</FONT></P>
<P><BR><FONT face=宋体>剩下的工作是将数据库恢复到最新状态。</FONT></P>
<P><FONT face=宋体>SQL&gt; SHUTDOWN IMMEDIATE;<BR>数据库已经关闭。<BR>已经卸载数据库。<BR>ORACLE 例程已经关闭。<BR>SQL&gt; STARTUP MOUNT<BR>ORACLE 例程已经启动。</FONT></P>
<P><FONT face=宋体>Total System Global Area&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1073741824 bytes<BR>Fixed Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1250044 bytes<BR>Variable Size&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 746589444 bytes<BR>Database Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 318767104 bytes<BR>Redo Buffers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 7135232 bytes<BR>数据库装载完毕。<BR>SQL&gt; RECOVER DATABASE;<BR>完成介质恢复。<BR>SQL&gt; ALTER DATABASE OPEN;</FONT></P>
<P><FONT face=宋体>数据库已更改。</FONT></P>
<P><FONT face=宋体>SQL&gt; SELECT ID FROM TEST.T;<BR>ERROR:<BR>ORA-01578: ORACLE 数据块损坏 (文件号 7, 块号 1570)<BR>ORA-01110: 数据文件 7:<BR>'C:\U01\ORACLE\PRODUCT\10.2.0\ORADATA\YANSP\YANSP\TEST02.DBF'</FONT></P>
<P><FONT face=宋体></FONT>&nbsp;</P>
<P><FONT face=宋体>未选定行</FONT></P>
<P><FONT face=宋体>当然数据块1570还是坏块。</FONT></P>
<P><FONT face=宋体>&nbsp;&nbsp;&nbsp; 这个只能利用备份来修复了。</FONT></P>
<P><FONT face=宋体>SQL&gt; host rman target /</FONT></P>
<P><FONT face=宋体>恢复管理器: Release 10.2.0.1.0 - Production on 星期一 8月 22 16:11:14 2011</FONT></P>
<P><FONT face=宋体>Copyright (c) 1982, 2005, Oracle.&nbsp; All rights reserved.</FONT></P>
<P><FONT face=宋体>连接到目标数据库: YANSP (DBID=969718535)</FONT></P>
<P><FONT face=宋体>RMAN&gt; BLOCKRECOVER DATAFILE 7 BLOCK 1570;</FONT></P>
<P><FONT face=宋体>启动 blockrecover 于 22-8月 -11<BR>使用目标数据库控制文件替代恢复目录<BR>分配的通道: ORA_DISK_1<BR>通道 ORA_DISK_1: sid=498 devtype=DISK</FONT></P>
<P><FONT face=宋体>通道 ORA_DISK_1: 正在恢复块<BR>通道 ORA_DISK_1: 正在指定要从备份集恢复的块<BR>正在恢复数据文件 00007 的块<BR>通道 ORA_DISK_1: 正在读取备份段 C:\ORACLE_BACKUP\INCREMENT_0JMDMU8R_1_1.BAK<BR>通道 ORA_DISK_1: 已从备份段 1 恢复块<BR>段句柄 = C:\ORACLE_BACKUP\INCREMENT_0JMDMU8R_1_1.BAK 标记 = TAG20110531T1014<BR>通道 ORA_DISK_1: 块恢复完成, 用时: 00:00:03</FONT></P>
<P><FONT face=宋体>正在开始介质的恢复<BR>介质恢复完成, 用时: 00:00:15</FONT></P>
<P><FONT face=宋体>完成 blockrecover 于 22-8月 -11</FONT></P>
<P><FONT face=宋体>RMAN&gt; EXIT</FONT></P>
<P><BR><FONT face=宋体>恢复管理器完成。</FONT></P>
<P><FONT face=宋体>SQL&gt; SELECT ID FROM TEST.T;</FONT></P>
<P><FONT face=宋体>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ID<BR>--------------------<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 6</FONT></P>
<P><FONT face=宋体>已选择6行。</FONT></P>
<P><FONT face=宋体></FONT>&nbsp;</P>
页: [1]
查看完整版本: 利用数据库闪回来处理坏块