[20121011]file header reset--bbed学习.txt

[20121011]file header reset--bbed学习.txt
    如果数据库数据文件损坏,并且archivelog损坏,这样无法完全恢复,如果仅仅某个数据文件的scn与其他文件不同步,导致该数据文件无法mount.
正常可以像odu之类的工具恢复.但是在实际上如果修改数据文件的scn保持同步,这样数据库可以正常打开,选择常规的方法imp/exp以及expdp/impdp
方式恢复,这样虽然丢失一部分数据,至少一定程度减少损失.
自己做一个试验测试看看:
1.首先做冷备份test01.dbf数据文件:
$ cd /u01/app/oracle11g/oradata/test/
$ cp test01.dbf /data/testtest/

SQL> startup
ORACLE instance started.
Total System Global Area 2137886720 bytes
Fixed Size                  2215064 bytes
Variable Size            1728054120 bytes
Database Buffers          402653184 bytes
Redo Buffers                4964352 bytes
Database mounted.
Database opened.

SQL> select rowid ,dbms_rowid.rowid_relative_fno(rowid) rfile#,dbms_rowid.ROWID_BLOCK_NUMBER(rowid) block#,dbms_rowid.ROWID_ROW_NUMBER(rowid) row#,dept1.* from scott.dept1;
ROWID                  RFILE#     BLOCK#       ROW#     DEPTNO DNAME          LOC
------------------ ---------- ---------- ---------- ---------- -------------- -------------
AAAcC1AAIAAAACDAAA          8        131          0         50 TEST           AAAA
AAAcC1AAIAAAACDAAB          8        131          1         10 ACCOUNTING     NEW YORK
AAAcC1AAIAAAACDAAC          8        131          2         20 RESEARCH       DALLAS
AAAcC1AAIAAAACDAAD          8        131          3         30 SALES          CHICAGO
AAAcC1AAIAAAACDAAE          8        131          4         40 OPERATIONS     BOSTON
SQL> insert into scott.dept1 values(60,'AAAA','BBBB');
1 row created.
SQL> commit ;
Commit complete.
SQL> alter system archive log current ;
System altered.
SQL> alter system archive log current ;
System altered.
SQL> alter system archive log current ;
System altered.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
--移动archivelog到另外的目录:
$ mv /u01/app/oracle11g/flash_recovery_area/TEST/archivelog/2012_10_11 /data/testtest/
$ cd /u01/app/oracle11g/oradata/test
$ mv test01.dbf test01.dbf.ORG
$ cp /data/testtest/test01.dbf .
--这样test01.dbf数据文件与其他数据文件的scn不一致.看看如何恢复.
SQL> startup
ORACLE instance started.
Total System Global Area 2137886720 bytes
Fixed Size                  2215064 bytes
Variable Size            1728054120 bytes
Database Buffers          402653184 bytes
Redo Buffers                4964352 bytes
Database mounted.
ORA-01113: file 8 needs media recovery
ORA-01110: data file 8: '/u01/app/oracle11g/oradata/test/test01.dbf'

2.检查各个scn的状态:
在关闭数据库前看看各个scn的状态:
SELECT 'controlfile' "SCN location", 'SYSTEM checkpoint' NAME, checkpoint_change#
  FROM v$database
UNION
SELECT 'file in controlfile', NAME, checkpoint_change#
  FROM v$datafile
 WHERE NAME LIKE '%test01%'
UNION
SELECT 'file header', NAME, checkpoint_change#
  FROM v$datafile_header
 WHERE NAME LIKE '%test01%';
SCN location        NAME                                                         CHECKPOINT_CHANGE#
------------------- ------------------------------------------------------------ ------------------
controlfile         SYSTEM checkpoint                                                    3010130713
file header         /u01/app/oracle11g/oradata/test/test01.dbf                           3010121681
file in controlfile /u01/app/oracle11g/oradata/test/test01.dbf                           3010130713

SQL> select * from v$recover_file ;
     FILE# ONLINE  ONLINE_ ERROR                                                                CHANGE# TIME
---------- ------- ------- ----------------------------------------------------------------- ---------- -------------------
         8 ONLINE  ONLINE                                                                    3010121681 2012-10-10 18:01:12

--可以发现file header记录的是3010121681,file in controlfile记录的是3010130713.
--只要恢复一致,就可以骗过oracle,正常加载数据文件.
3.bbed修复操作:
摘抄一段:
The file header is stored in the first block cf the data file. We can use bbed tc examine the blcck and show
the block map. The header blocks contain a single data structure — kcvfh. Oracle considers four attributes
of this data structure when determining if a data file is sync with the other data files of the database:

kscnbas  (at offset 484) -- SCN of last change to the datafile.
kcvcptim (at offset 492) -- Time of the last change to the datafile.
kcvfhcpc (at offset 140) -- Checkpoint count.
kcvfhccc (at offset 148) -- Unknown, but is always l less than the checkpoint point count.
    The first two attributes are stored in the kcvfhckp sub-structure. The second two are attributes in their own
right. We can use the print command to display them all for the file that requires recovery:
=====================
BBED> set file 1
        FILE#           1
BBED>  map /v
 File: /u01/app/oracle11g/oradata/test/system01.dbf (1)
 Block: 1                                     Dba:0x00400001
------------------------------------------------------------
 Data File Header
 struct kcvfh, 860 bytes                    @0
    struct kcvfhbfh, 20 bytes               @0
    struct kcvfhhdr, 76 bytes               @20
    ub4 kcvfhrdb                            @96
    struct kcvfhcrs, 8 bytes                @100
    ub4 kcvfhcrt                            @108
    ub4 kcvfhrlc                            @112
    struct kcvfhrls, 8 bytes                @116
    ub4 kcvfhbti                            @124
    struct kcvfhbsc, 8 bytes                @128
    ub2 kcvfhbth                            @136
    ub2 kcvfhsta                            @138
    struct kcvfhckp, 36 bytes               @484
    ub4 kcvfhcpc                            @140
    ub4 kcvfhrts                            @144
    ub4 kcvfhccc                            @148
    struct kcvfhbcp, 36 bytes               @152
    ub4 kcvfhbhz                            @312
    struct kcvfhxcd, 16 bytes               @316
    sword kcvfhtsn                          @332
    ub2 kcvfhtln                            @336
    text kcvfhtnm[30]                       @338
    ub4 kcvfhrfn                            @368
    struct kcvfhrfs, 8 bytes                @372
    ub4 kcvfhrft                            @380
    struct kcvfhafs, 8 bytes                @384
    ub4 kcvfhbbc                            @392
    ub4 kcvfhncb                            @396
    ub4 kcvfhmcb                            @400
    ub4 kcvfhlcb                            @404
    ub4 kcvfhbcs                            @408
    ub2 kcvfhofb                            @412
    ub2 kcvfhnfb                            @414
    ub4 kcvfhprc                            @416
    struct kcvfhprs, 8 bytes                @420
    struct kcvfhprfs, 8 bytes               @428
    ub4 kcvfhtrt                            @444
 ub4 tailchk                                @8188
-------------------------------------------------------------------
BBED> p kcvfhckp.kcvcpscn.kscnbas
ub4 kscnbas                                 @484      0xb36af319
BBED> p kcvfhckp.kcvcptim
ub4 kcvcptim                                @492      0x2f782495
BBED> p kcvfhcpc
ub4 kcvfhcpc                                @140      0x00000757
BBED> p kcvfhccc
ub4 kcvfhccc                                @148      0x00000756
--注意位置与文档讲的不同,以实际为主.
BBED> set dba 8,1
        DBA             0x02000001 (33554433 8,1)
BBED> show
        FILE#           8
        BLOCK#          1
        OFFSET          492
        DBA             0x02000001 (33554433 8,1)
        FILENAME        /u01/app/oracle11g/oradata/test/test01.dbf
        BIFILE          bifile.bbd
        LISTFILE        /home/oracle11g/bbed/filelist.txt
        BLOCKSIZE       8192
        MODE            Edit
        EDIT            Unrecoverable
        IBASE           Dec
        OBASE           Dec
        WIDTH           210
        COUNT           8192
        LOGFILE         log.bbd
        SPOOL           No
BBED> p kcvfhckp.kcvcpscn.kscnbas
ub4 kscnbas                                 @484      0xb36acfd1
BBED>  p kcvfhckp.kcvcptim
ub4 kcvcptim                                @492      0x2f76fd68
BBED>  p kcvfhcpc
ub4 kcvfhcpc                                @140      0x00000326
BBED> p kcvfhccc
ub4 kcvfhccc                                @148      0x00000325
BBED> host bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
ibase=16
b36af319
0
B36AF319
3010130713
B36ACFD1
3010121681
quit
--可以发现与视图看到的基本一致.
BBED> set dba 1,1
        DBA             0x00400001 (4194305 1,1)
BBED> dump /v offset 484
 File: /u01/app/oracle11g/oradata/test/system01.dbf (1)
 Block: 1                                                           Offsets:  484 to  487                                                      Dba:0x00400001
---------------------------------------------------------------------------------------------------------------------------------------------------------------
 19f36ab3                                                                                                    l ..j.
 
BBED> dump /v offset 492
 File: /u01/app/oracle11g/oradata/test/system01.dbf (1)
 Block: 1                                                           Offsets:  492 to  495                                                      Dba:0x00400001
---------------------------------------------------------------------------------------------------------------------------------------------------------------
 9524782f                                                                                                    l .$x/
 
BBED> dump /v offset 140
 File: /u01/app/oracle11g/oradata/test/system01.dbf (1)
 Block: 1                                                           Offsets:  140 to  143                                                      Dba:0x00400001
---------------------------------------------------------------------------------------------------------------------------------------------------------------
 57070000                                                                                                    l W...
 
BBED> dump /v offset 148
 File: /u01/app/oracle11g/oradata/test/system01.dbf (1)
 Block: 1                                                           Offsets:  148 to  151                                                      Dba:0x00400001
---------------------------------------------------------------------------------------------------------------------------------------------------------------
 56070000                                                                                                    l V...
 
--因为intel cpu采用little在前,显示正确的再修改方便一些.
BBED> set dba 8,1
        DBA             0x02000001 (33554433 8,1)
BBED> modify /x 19f36ab3  offset 484
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
 File: /u01/app/oracle11g/oradata/test/test01.dbf (8)
 Block: 1                                                                      Offsets:  484 to  487                                                                 Dba:0x02000001
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 19f36ab3
 

BBED> modify /x 9524782f  offset 492
BBED-00209: invalid number (9524782f)
--奇怪!不行,有时候可以,不知道为什么?分成2段修改
BBED> modify /x 9524 offset 492
 File: /u01/app/oracle11g/oradata/test/test01.dbf (8)
 Block: 1                                                                      Offsets:  492 to  495                                                                 Dba:0x02000001
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 9524762f
 
BBED> set offset +2
        OFFSET          494
BBED> modify /x 782f
 File: /u01/app/oracle11g/oradata/test/test01.dbf (8)
 Block: 1                                                                      Offsets:  494 to  497                                                                 Dba:0x02000001
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 782f0100
 
BBED> modify /x  5707 offset 140
 File: /u01/app/oracle11g/oradata/test/test01.dbf (8)
 Block: 1                                                                      Offsets:  140 to  143                                                                 Dba:0x02000001
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 57070000
 
BBED> modify /x  5607 offset 148
 File: /u01/app/oracle11g/oradata/test/test01.dbf (8)
 Block: 1                                                                      Offsets:  148 to  151                                                                 Dba:0x02000001
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 56070000
 
--OK,修改完成!现在一致了.
BBED> sum
Check value for File 8, Block 1:
current = 0x9caf, required = 0x7996
BBED> sum apply
Check value for File 8, Block 1:
current = 0x7996, required = 0x7996
BBED> verify
DBVERIFY - Verification starting
FILE = /u01/app/oracle11g/oradata/test/test01.dbf
BLOCK = 1

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   : 0
Total Blocks Influx           : 0
Message 531 not found;  product=RDBMS; facility=BBED
--正常!

4.启动数据库检查:
--不行!
SQL> startup open read only ;
ORACLE instance started.
Total System Global Area 2137886720 bytes
Fixed Size                  2215064 bytes
Variable Size            1728054120 bytes
Database Buffers          402653184 bytes
Redo Buffers                4964352 bytes
Database mounted.
ORA-01122: database file 8 failed verification check
ORA-01110: data file 8: '/u01/app/oracle11g/oradata/test/test01.dbf'
ORA-01207: file is more recent than control file - old control file
--不知道有遗漏了什么,做一个对比看看,跳过第1块OS header.
$ dd if=test01.dbf.ORG  count=1 bs=8192 skip=1 | xxd -c 16 > /tmp/aa.good
$ dd if=test01.dbf      count=1 bs=8192 skip=1 | xxd -c 16 > /tmp/aa.bad
$ diff -Nur aa.bad aa.good
--- aa.bad      2012-10-11 15:28:37.000000000 +0800
+++ aa.good     2012-10-11 15:28:24.000000000 +0800
@@ -1,13 +1,13 @@
 0000000: 0ba2 0000 0100 0002 0000 0000 0000 0104  ................
-0000010: 9679 0000 0000 0000 0000 200b d258 7f7b  .y........ .襒.{
-0000020: 5445 5354 0000 0000 3fb4 0200 0020 0000  TEST....?.... ..
+0000010: 432e 0000 0000 0000 0000 200b d258 7f7b  C......... .襒.{
+0000020: 5445 5354 0000 0000 d1b4 0200 0020 0000  TEST....?... ..
====> 位置0x10,0x11(十进制16,17) 检查和,先可以不管它. 0x28,0x29(十进制40,41) 不同 
====> 查询对应   ub4 kccfhcsq   @40       0x0002b43f
 0000030: 0020 0000 0800 0300 0000 0000 0000 0000  . ..............
 0000040: 5441 4732 3031 3230 3931 3654 3039 3335  TAG20120916T0935
 0000050: 3338 0000 0000 0000 0000 0000 0000 0000  38..............
 0000060: 0000 0000 d4f2 c800 0000 0000 2081 e82e  ....则?.... .?
 0000070: a7de 242f ad36 f100 0000 0000 0000 0000  .?/.6?........
-0000080: 0000 0000 0000 0000 0000 0000 5707 0000  ............W...
-0000090: 2cdf 762f 5607 0000 0000 0000 0000 0000  ,遶/V...........
+0000080: 0000 0000 0000 0000 0000 0000 2c03 0000  ............,...
+0000090: 2cdf 762f 2b03 0000 0000 0000 0000 0000  ,遶/+...........
====> 位置0x8b,0x8c(140). 0x94,0x95(148) 
====> ub4 kcvfhcpc  @140      0x00000757
====> ub4 kcvfhccc  @148      0x00000756
 00000a0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
 00000b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
 00000c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
@@ -29,7 +29,7 @@
 00001c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
 00001d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
 00001e0: 0000 0000 19f3 6ab3 0000 0000 9524 782f  .....骿......$x/
-00001f0: 0100 0000 9001 0000 041c 0000 1000 21d7  ..............!.
+00001f0: 0100 0000 9301 0000 3a4b 0000 1000 21d7  ........:K....!.
====> 位置0x1f4,0x1f5 ,0x1f8,0x1f9
====> 十进制500,501,504,505 (map命令也没有说明)
 0000200: 0200 0000 0000 0000 0000 0000 0000 0000  ................
 0000210: 0000 0000 0000 0000 0000 0000 0000 0000  ................
 0000220: 0000 0000 0000 0000 0000 0000 0000 0000  ................

--经过多次测试,发现
ub4 kcvfhcpc  @140,ub4 kcvfhccc  @148 两处修改,原来如下:
BBED>  p kcvfhcpc
ub4 kcvfhcpc                                @140      0x00000326
BBED> p kcvfhccc
ub4 kcvfhccc                                @148      0x00000325
修改为这样就OK了.
BBED> p kcvfhcpc
ub4 kcvfhcpc                                @140      0x0000032c
BBED> p kcvfhccc
ub4 kcvfhccc                                @148      0x0000032b
--这个增长并不是各个一样的,如果数据文件建立出现有先后,数量应该不会各个相等的.
BBED> set file 7
        FILE#           7
BBED> p kcvfhcpc
ub4 kcvfhcpc                                @140      0x00000629
BBED> p kcvfhccc
ub4 kcvfhccc                                @148      0x00000628
0x32C-0x326=6
--难道要1点1点增加来测试.先暂时学到这里!!累!!
--控制文件有记录吗?

				
时间: 2024-10-31 15:18:57

[20121011]file header reset--bbed学习.txt的相关文章

[20121011]global_name为空的恢复(new)-bbed学习.txt

[20121011]global_name为空的恢复(new)-bbed学习.txt 前面已经提到如果global_name为空,数据库会起来. 下次开机时,出现如下提示: SQL> startup ORACLE instance started. Total System Global Area 2137886720 bytes Fixed Size                  2215064 bytes Variable Size            1728054120 bytes

[20120228]IOT索引组织表相关信息的学习.txt

[20120228]IOT索引组织表相关信息的学习.txt IOT 是一种特殊的索引结构,使用它能够解决特定场合的应用问题,但是在许多应用中很少使用,更多的是使用堆表.我仅仅在生产系统中对3个表使用,我偏向使用静态以及"只读"的小表. 如果IOT表存在除主键外的第2索引,如果使用它存在物理猜"physical guess",我以前的理解一直是第2索引记录了主键信息,通过这个信息就可以定位IOT表中对应的数据,一直没有很好的测试与理解.我最近也看了两个链接,介绍了IO

[20130217]11GR2 adrci的学习.txt

[20130217]11GR2 adrci的学习.txt 春节放假,学习一下adrci的使用.adrci (Automatic Diagnostic Repository Command Interpreter). ADRCI: Release 11.2.0.1.0 - Production on Tue Aug 21 16:35:06 2012Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved

[20130530]OS block header破坏以及恢复.txt

[20130530]OS block header破坏以及恢复.txt oracle文件的第一个块(block 0)是OS block header,在数据库中查询不到信息,记录的是OS信息,以及文件大小的等信息: 如果损坏,应该对数据文件影响大吗? 自己做一个测试看看. 1.介绍OS block header:@verSQL> @verBANNER--------------------------------------------------------------------------

[20130409]Data file init write等待事件.txt

[20130409]Data file init write等待事件.txt 清明前几天帮别人解决数据库问题,就是高峰的时候有点慢. 仔细看awr报表,除了发现几条sql语句没有建立索引外,发现等待事件里Data file init write.很明显主要数据文件next设置太小,当我看数据文件发现next竟然是8k,将它修改128M后问题消失. 我自己感到奇怪的是无论如何前面的安装人员都不应该把next设置为8k(难道是笔误应该是8M还有可能). 今天自己在11G上做一个测试,原来问题在于建立

Watch gcc at ubuntu 12,See ELF file header

first write article at my ubuntu 12. ELF is very important file format.

[20121015]探索索引-学习bbed.txt

[20121015]探索索引-学习bbed.txt 参考链接:http://www.adellera.it/blog/2009/05/24/order-keys-inside-index-blocks/ 1.探索索引 SQL> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Ent

[20150522]bbed与数据块检查和.txt

[20150522]bbed与数据块检查和.txt --我现在基本拿bbed学习,基本是拿bbed查看,而使用bvi修改数据.我感觉这种方便1写. --实际上使用bbed的好处就是修改数据块检查和不一致,而使用bbed修改很简单仅仅需要执行sum apply就ok了. --对比dbv与bbed确定检查和位置. 1.建立测试环境: SCOTT@test> @ &r/ver1 PORT_STRING                    VERSION        BANNER -------

[20150527]bbed与数据块检查和2.txt

[20150527]bbed与数据块检查和2.txt http://blog.itpub.net/267265/viewspace-1666781/ --我现在基本拿bbed学习,基本是拿bbed查看,而使用bvi修改数据.我感觉这种方便1写. --实际上使用bbed的好处就是修改数据块检查和不一致,而使用bbed修改很简单仅仅需要执行sum apply就ok了. --对比dbv与bbed确定检查和位置. --实际上既然检查和在16,17字节,只要清零,加上dbv就很容易确定要修改的内容. 1.