博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[20161111]数据库文件头的修复.txt
阅读量:6609 次
发布时间:2019-06-24

本文共 13169 字,大约阅读时间需要 43 分钟。

[20161111]数据库文件头的修复.txt

--这里指文件头实际上数据文件第1块(从0算起)。

--找到一个链接,

--要修改的信息相对较多。

1 .改动数据的DBA,rdba_kcbh

2 .改动文件的大小,kccfhfsz
3 .改动文件号,kccfhfno
4 .改动文件创建时SCN,kcvfhcrs
5 .改动文件创建时间,kcvfhcrt
6 .改动表空间号,kcvfhtsn
7 .改动相对文件号,kcvfhrfn
8 .改动表空间的名称, kcvfhtnm
9 .改动表空间的长度,kcvfhtln
10.改动检查点的SCN,kcvfhckp
11.改动检查点的时间,kcvcptim
12.改动检查点的计数器,kcvfhcpc
13.改动检查点的控制文件备份的计数器, kcvfhccc
14.假设你改动是1号文件的1号块他的root rdba针指向bootstrap$

--实际上修改没有这么多,不过还是按照这个过程操作修改内容。

1.环境:

SCOTT@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

CREATE TABLESPACE SUGAR DATAFILE

  '/mnt/ramdisk/book/sugar01.dbf' SIZE 40M AUTOEXTEND ON NEXT 16M MAXSIZE UNLIMITED
LOGGING
ONLINE
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;

create table t1 tablespace sugar as select rownum id ,lpad('A',32,'A') name from dual connect by level<=1e5;

--建立大小5M的表。

alter system checkpoint;

alter system checkpoint;
...
alter system checkpoint;

CREATE TABLESPACE TEA DATAFILE

  '/mnt/ramdisk/book/tea01.dbf' SIZE 40M AUTOEXTEND ON NEXT 16M MAXSIZE UNLIMITED
LOGGING
ONLINE
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;

alter system checkpoint;

--建立的数据文件大小一致,可以减少一些修改内容。执行alter system checkpoint;这样可以导致2个文件的改动检查点的计数器不同。

SCOTT@book> alter database  datafile 6 offline ;
Database altered.

SCOTT@book> alter database  datafile 7 offline ;

Database altered.

--做这种offline,最好顺手做一个recover datafile N,避免时间上了online时要recover没有归档文件。当然这里测试不需要。

SCOTT@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name  FROM v$datafile_header;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT FUZ NAME                            TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- ------------------------------- ----------------
    1            6317588 2016-11-11 15:08:38                7           2002065 ONLINE               419 YES /mnt/ramdisk/book/system01.dbf  SYSTEM
    2            6317588 2016-11-11 15:08:38             1834           2002065 ONLINE               416 YES /mnt/ramdisk/book/sysaux01.dbf  SYSAUX
    3            6317588 2016-11-11 15:08:38           923328           2002065 ONLINE               337 YES /mnt/ramdisk/book/undotbs01.dbf UNDOTBS1
    4            6317588 2016-11-11 15:08:38            16143           2002065 ONLINE               415 YES /mnt/ramdisk/book/users01.dbf   USERS
    5            6317588 2016-11-11 15:08:38           952916           2002065 ONLINE               335 YES /mnt/ramdisk/book/example01.dbf EXAMPLE
    6            6317503 2016-11-11 15:07:28          6316871           2002065 OFFLINE                3 NO  /mnt/ramdisk/book/sugar01.dbf   SUGAR
    7            6317588 2016-11-11 15:08:38          6317214           2002065 OFFLINE               11 YES /mnt/ramdisk/book/tea01.dbf     TEA
7 rows selected.

2.备份数据文件6.

$ cp /mnt/ramdisk/book/sugar01.dbf /u01/backup/sugar01.dbf_20161110

$ bvi -b 8192 -s 8192 /mnt/ramdisk/book/sugar01.dbf
--全部置为0

$ dd if=/dev/zero of=/mnt/ramdisk/book/sugar01.dbf count=1 bs=8192 conv=notrunc seek=1

1+0 records in
1+0 records out
8192 bytes (8.2 kB) copied, 4.0611e-05 seconds, 202 MB/s

BBED> copy dba 7,1 to dba 6,1

Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: /mnt/ramdisk/book/sugar01.dbf (6)
Block: 1                                                    Offsets:    0 to  255                                               Dba:0x01800001
------------------------------------------------------------------------------------------------------------------------------------------------
0ba20000 0100c001 00000000 00000104 c54f0000 00000000 0004200b 6e21b74f 424f4f4b 00000000 fc6b0000 00140000 00200000 07000300 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 9e646000 00000000 68bc4a37 e6702c37 918c1e00 00000000 00000000
00000000 00000000 00000400 0b000000 cabc4a37 0a000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
<64 bytes per line>

--这样使用数据文件7的文件头替换了数据文件6的文件头。

3.开始修改。

1.改动数据的DBA,rdba_kcbh

BBED> set dba 6,1

        DBA             0x01800001 (25165825 6,1)

BBED> p dba 6,1 kcvfh.kcvfhbfh.rdba_kcbh

ub4 rdba_kcbh                               @4        0x01c00001

BBED> assign dba 6,1 kcvfh.kcvfhbfh.rdba_kcbh = 0x01800001

ub4 rdba_kcbh                               @4        0x01800001
--查看执行set dba 6,1的输出就知道dba地址。

2 .改动文件的大小,kccfhfsz

--这个忽略,大小一样。

BBED> p dba 6,1 kcvfh.kcvfhhdr.kccfhfsz

ub4 kccfhfsz                                @44       0x00001400
-- 0x1400 = 5120, 5120*8192/1024/1024=40M

3 .改动文件号,kccfhfno

BBED> p dba 6,1 kcvfh.kcvfhhdr.kccfhfno
ub2 kccfhfno                                @52       0x0007

BBED> assign dba 6,1 kcvfh.kcvfhhdr.kccfhfno=0x0006

ub2 kccfhfno                                @52       0x0006

4 .改动文件创建时SCN,kcvfhcrs

SCOTT@book> SELECT CREATION_CHANGE#,CREATION_TIME ,file#,NAME from v$datafile where file#=6 or file#=7;
CREATION_CHANGE# CREATION_TIME       FILE# NAME
---------------- ------------------- ----- --------------------------------------------------
         6316871 2016-11-11 15:05:44     6 /mnt/ramdisk/book/sugar01.dbf
         6317214 2016-11-11 15:06:16     7 /mnt/ramdisk/book/tea01.dbf

BBED> p /d dba 6,1 kcvfh.kcvfhhdr.kcvfhcrs

struct kcvfhcrs, 8 bytes                    @100
   ub4 kscnbas                              @100      6317214
   ub2 kscnwrp                              @104      0

BBED> assign dba 6,1 kcvfh.kcvfhhdr.kcvfhcrs.kscnbas=6316871

ub4 kscnbas                                 @100      0x00606347

5 .改动文件创建时间,kcvfhcrt

SCOTT@book> SELECT CREATION_CHANGE#,CREATION_TIME ,file#,NAME from v$datafile where file#=6 or file#=7;
CREATION_CHANGE# CREATION_TIME       FILE# NAME
---------------- ------------------- ----- --------------------------------------------------
         6316871 2016-11-11 15:05:44     6 /mnt/ramdisk/book/sugar01.dbf
         6317214 2016-11-11 15:06:16     7 /mnt/ramdisk/book/tea01.dbf

BBED> p /d dba 6,1 kcvfh.kcvfhhdr.kcvfhcrt

ub4 kcvfhcrt                                @108      927644776
--注意现在file#=7的时间。

SCOTT@book> select (to_date('2016-11-11 15:06:16','yyyy-mm-dd hh24:mi:ss')-to_date('2016-11-11 15:05:44','yyyy-mm-dd hh24:mi:ss'))*86400 N10 from dual;

                  N10
---------------------
                   32

-- 927644776-32=927644744

BBED> assign  dba 6,1 kcvfh.kcvfhhdr.kcvfhcrt=927644744

ub4 kcvfhcrt                                @108      0x374abc48

--补充说明:第4,5步我开始忽略,我认为可以不改。但是实际上在recover时报错。

SCOTT@book> recover datafile 6;
ORA-00283: recovery session canceled due to errors
ORA-01110: data file 6: '/mnt/ramdisk/book/sugar01.dbf'
ORA-01122: database file 6 failed verification check
ORA-01110: data file 6: '/mnt/ramdisk/book/sugar01.dbf'
ORA-01202: wrong incarnation of this file - wrong creation time

6 .改动表空间号,kcvfhtsn

SCOTT@book> select ts#,name from sys.ts$ where name in ('SUGAR','TEA');

         TS# NAME
------------ --------------------------------------------------
           7 SUGAR
           8 TEA

BBED> p dba 6,1 kcvfh.kcvfhhdr.kcvfhtsn

sword kcvfhtsn                              @332      8

BBED> assign  dba 6,1 kcvfh.kcvfhhdr.kcvfhtsn=7

sword kcvfhtsn                              @332      7

7 .改动相对文件号,kcvfhrfn

BBED> p dba 6,1 kcvfh.kcvfhhdr.kcvfhrfn
ub4 kcvfhrfn                                @368      0x00000007

BBED> assign  dba 6,1 kcvfh.kcvfhhdr.kcvfhrfn=0x00000006

ub4 kcvfhrfn                                @368      0x00000006

8 .改动表空间的名称, kcvfhtnm

BBED> p /c dba 6,1 kcvfh.kcvfhhdr.kcvfhtnm
text kcvfhtnm[0]                            @338     T
text kcvfhtnm[1]                            @339     E
text kcvfhtnm[2]                            @340     A
text kcvfhtnm[3]                            @341     .
text kcvfhtnm[4]                            @342     .

SCOTT@book> select dump('S',16) from dual ;

DUMP('S',16)
----------------
Typ=96 Len=1: 53

BBED> assign dba 6,1 kcvfh.kcvfhhdr.kcvfhtnm[0]=0x53

text kcvfhtnm[0]                            @338     S

BBED> assign dba 6,1 kcvfh.kcvfhhdr.kcvfhtnm[1]=0x55

text kcvfhtnm[0]                            @339     U

BBED> assign dba 6,1 kcvfh.kcvfhhdr.kcvfhtnm[2]=0x47

text kcvfhtnm[0]                            @340     G

BBED> assign dba 6,1 kcvfh.kcvfhhdr.kcvfhtnm[3]=0x41

text kcvfhtnm[0]                            @341     A

BBED> assign dba 6,1 kcvfh.kcvfhhdr.kcvfhtnm[4]=0x52

text kcvfhtnm[0]                            @343     R

--检查略。

9 .改动表空间的长度,kcvfhtln

BBED> p  dba 6,1 kcvfh.kcvfhhdr.kcvfhtln

ub2 kcvfhtln                                @336      0x0003

BBED> assign  dba 6,1 kcvfh.kcvfhhdr.kcvfhtln=0x0005

ub2 kcvfhtln                                @336      0x0005
--修改长度5,SUGAR占5个字符。

10.改动检查点的SCN,kcvfh.kcvfhhdr.kcvfhckp.kcvcpscn

SCOTT@book>  SELECT file#, CHECKPOINT_CHANGE#,CHECKPOINT_TIME,UNRECOVERABLE_CHANGE#,UNRECOVERABLE_TIME,LAST_CHANGE#,LAST_TIME, OFFLINE_CHANGE#, ONLINE_CHANGE#,status,name FROM v$datafile where file#=6;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     UNRECOVERABLE_CHANGE# UNRECOVERABLE_TIME  LAST_CHANGE# LAST_TIME           OFFLINE_CHANGE# ONLINE_CHANGE# STATUS  NAME
----- ------------------ ------------------- --------------------- ------------------- ------------ ------------------- --------------- -------------- ------- --------------------------------------------------
    6            6317503 2016-11-11 15:07:28                     0                          6317503 2016-11-11 15:07:28               0              0 OFFLINE /mnt/ramdisk/book/sugar01.dbf

BBED> p /d dba 6,1 kcvfh.kcvfhhdr.kcvfhckp.kcvcpscn

struct kcvcpscn, 8 bytes                    @484
   ub4 kscnbas                              @484      6317588
   ub2 kscnwrp                              @488      0

BBED> assign  /d dba 6,1 kcvfh.kcvfhhdr.kcvfhckp.kcvcpscn.kscnbas=6317503

ub4 kscnbas                                 @484      0x006065bf

11.改动检查点的时间,kcvcptim

BBED> p /d dba 6,1 kcvfh.kcvfhhdr.kcvfhckp.kcvcptim
ub4 kcvcptim                                @492      927644918

SCOTT@book> SELECT file#, CHECKPOINT_CHANGE#,CHECKPOINT_TIME,UNRECOVERABLE_CHANGE#,UNRECOVERABLE_TIME,LAST_CHANGE#,LAST_TIME, OFFLINE_CHANGE#, ONLINE_CHANGE#,status,name FROM v$datafile where file# in (6,7);

FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     UNRECOVERABLE_CHANGE# UNRECOVERABLE_TIME  LAST_CHANGE# LAST_TIME           OFFLINE_CHANGE# ONLINE_CHANGE# STATUS  NAME
----- ------------------ ------------------- --------------------- ------------------- ------------ ------------------- --------------- -------------- ------- --------------------------------------------------
    6            6317503 2016-11-11 15:07:28                     0                          6317503 2016-11-11 15:07:28               0              0 OFFLINE /mnt/ramdisk/book/sugar01.dbf
    7            6317588 2016-11-11 15:08:38                     0                          6317624 2016-11-11 15:10:02               0              0 RECOVER /mnt/ramdisk/book/tea01.dbf
--注意现在file#=7的时间。

SCOTT@book> select (to_date('2016-11-11 15:08:38','yyyy-mm-dd hh24:mi:ss')-to_date('2016-11-11 15:07:28','yyyy-mm-dd hh24:mi:ss'))*86400 N10 from dual;

                  N10
---------------------
                   70

--927644918-70=927644848

BBED> assign /d dba 6,1 kcvfh.kcvfhhdr.kcvfhckp.kcvcptim=927644848

ub4 kcvcptim                                @492      0x374abcb0

12.改动检查点的计数器,kcvfhcpc

--如果你看前面的查询v$datafile_header;CHECKPOINT_COUNT=3,现在是11.

BBED> p /d dba 6,1 kcvfh.kcvfhrdb.kcvfhcpc
ub4 kcvfhcpc                                @140      11

--这个信息来源于控制文件,你可以转储alter session set events 'immediate trace name controlf level 12';

DATA FILE #6:
  name #10: /mnt/ramdisk/book/sugar01.dbf
creation size=5120 block size=8192 status=0xc head=10 tail=10 dup=1
tablespace 7, index=7 krfil=6 prev_file=0
unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
Checkpoint cnt:3 scn: 0x0000.006065bf 11/11/2016 15:07:28
Stop scn: 0x0000.006065bf 11/11/2016 15:07:28
Creation Checkpointed at scn:  0x0000.00606347 11/11/2016 15:05:44
thread:1 rba:(0x9f.5897.10)
enabled  threads:  01000000 00000000 00000000 00000000 00000000 00000000
  00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

BBED> p /d dba 6,1 kcvfh.kcvfhrdb.kcvfhcpc

ub4 kcvfhcpc                                @140      11

BBED> assign /d dba 6,1 kcvfh.kcvfhrdb.kcvfhcpc=2

ub4 kcvfhcpc                                @140      0x00000002

13.改动检查点的控制文件备份的计数器, kcvfhccc

--就是比减少kcvfhcpc-1

BBED> p /d dba 6,1 kcvfh.kcvfhrdb.kcvfhccc

ub4 kcvfhccc                                @148      10

BBED> assign /d dba 6,1 kcvfh.kcvfhrdb.kcvfhccc=1

ub4 kcvfhccc                                @148      0x00000001
--先这样修改看看。
--补充说明,我开始没改,但是执行recover时报错。估计这个是11太大,我设置比原来的3小就ok了。
SCOTT@book> recover datafile 6;
ORA-00283: recovery session canceled due to errors
ORA-01122: database file 6 failed verification check
ORA-01110: data file 6: '/mnt/ramdisk/book/sugar01.dbf'
ORA-01207: file is more recent than control file - old control file

14.假设你改动是1号文件的1号块他的root rdba针指向bootstrap$

--不是系统文件,这个不修改了。
BBED> p dba 1,1 kcvfh.kcvfhrdb
ub4 kcvfhrdb                                @96       0x00400208

BBED> p dba 6,1 kcvfh.kcvfhrdb

ub4 kcvfhrdb                                @96       0x00000000

BBED> set dba 0x00400208

        DBA             0x00400208 (4194824 1,520)
--这个位置在dba=1,520,大家可以自行验证。
SCOTT@book> @ &r/which_obj 1 520
OWNER  SEGMENT_NAME          SEGMENT_TYPE       TABLESPACE_NAME                   EXTENT_ID      FILE_ID     BLOCK_ID        BYTES       BLOCKS RELATIVE_FNO
------ --------------------  ------------------ ------------------------------ ------------ ------------ ------------ ------------ ------------ ------------
SYS    BOOTSTRAP$            TABLE              SYSTEM                                    0            1          520        65536            8            1

15.计算检查和。

BBED> sum apply dba 6,1

Check value for File 6, Block 1:
current = 0x1edf, required = 0x1edf

SCOTT@book> recover datafile 6;

ORA-00283: recovery session canceled due to errors
ORA-01110: data file 6: '/mnt/ramdisk/book/sugar01.dbf'
ORA-01122: database file 6 failed verification check
ORA-01110: data file 6: '/mnt/ramdisk/book/sugar01.dbf'
ORA-01203: wrong incarnation of this file - wrong creation SCN

16.执行恢复

SCOTT@book> recover datafile 6;

Media recovery complete.

--ok.

SCOTT@book> alter database datafile 6 online ;

Database altered.

SCOTT@book> select count(*) from t1;

    COUNT(*)
------------
      100000

-- 总结:

1 .改动数据的DBA,rdba_kcbh                                     kcvfh.kcvfhbfh.rdba_kcbh
2 .改动文件的大小,kccfhfsz                                    kcvfh.kcvfhhdr.kccfhfsz
3 .改动文件号,kccfhfno                                        kcvfh.kcvfhhdr.kccfhfno
4 .改动文件创建时SCN,kcvfhcrs                                 kcvfh.kcvfhhdr.kcvfhcrs
5 .改动文件创建时间,kcvfhcrt                                  kcvfh.kcvfhhdr.kcvfhcrt
6 .改动表空间号,kcvfhtsn                                      kcvfh.kcvfhhdr.kcvfhtsn
7 .改动相对文件号,kcvfhrfn                                    kcvfh.kcvfhhdr.kcvfhrfn
8 .改动表空间的名称, kcvfhtnm                                 kcvfh.kcvfhhdr.kcvfhtnm
9 .改动表空间的长度,kcvfhtln                                  kcvfh.kcvfhhdr.kcvfhtln
10.改动检查点的SCN,kcvfhckp                                   kcvfh.kcvfhhdr.kcvfhckp.kcvcpscn
11.改动检查点的时间,kcvcptim                                  kcvfh.kcvfhhdr.kcvfhckp.kcvcptim
12.改动检查点的计数器,kcvfhcpc                                kcvfh.kcvfhrdb.kcvfhcpc
13.改动检查点的控制文件备份的计数器, kcvfhccc                 kcvfh.kcvfhrdb.kcvfhccc
14.假设你改动是1号文件的1号块他的root rdba针指向bootstrap$     kcvfh.kcvfhrdb
15.计算检查和。
16.千万不要在生产系统做这个测试!!

转载地址:http://zesso.baihongyu.com/

你可能感兴趣的文章
Programming Computer Vision with Python (学习笔记十)
查看>>
URL传值带加号“+”的问题的解决方法
查看>>
Redis存储总是心里没底?你大概漏了这些数据结构原理 ...
查看>>
如何用纯 CSS 创作一个没有 DOM 元素的动画
查看>>
开发函数计算的正确姿势——网页截图服务
查看>>
Flink 1.7.2 dataset transformation 示例
查看>>
金三银四背后,一个 Android 程序员的面试心得
查看>>
智能设备安全提供商“瓶钵TrustKernel”获数千万元A轮融资,领投方为启赋资本 ...
查看>>
confluence的初步认识和了解
查看>>
企业服务行业如何试水 Istio | Service Mesh Meetup 分享实录 ...
查看>>
使用kubeadm安装k8s-1.11版本
查看>>
Apache Flink,流计算?不仅仅是流计算!
查看>>
IPO获得超额认购,Lyft估值或超230亿美元
查看>>
掌握多少门编程语言才能成为优秀程序员?
查看>>
Node.js之Stream双工流
查看>>
用迁云工具自建遗留系统镜像
查看>>
python爬虫js加密解密系列文章合集
查看>>
河南申请高新技术企业需要多少个专利?智为知识产权为您解答! ...
查看>>
怎样让GPS定位系统应用开发变得简单,选择底子很关键
查看>>
dubbo2.5-spring4-mybastis3.2-springmvc4-mongodb3.4-redis3.2整合(五)Spring中spring-data-redis的使用...
查看>>