04 bbed修复system文件头损坏
1 启动数据库,查看trace,在mount到open,
SQL> startup mount; ORACLE instance started. Total System Global Area 784998400 bytes Fixed Size 2257352 bytes Variable Size 511708728 bytes Database Buffers 264241152 bytes Redo Buffers 6791168 bytes Database mounted. SQL> alter session set events '10046 trace name context forever,level 8'; Session altered. SQL> alter database open; Database altered. SQL> alter session set events '10046 trace name context off'; Session altered. SQL> select value from v$diag_info where name='Default Trace File'; VALUE ------------------------------------------------------------------ /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_11247.trc
查看文件,在启动的是,先检查各个数据文件的1号块
[oracle@DSI ~]$ more /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_11247.trc WAIT #139760412634104: nam='control file sequential read' ela= 2 file#=0 block#=23 blocks=1 obj#=-1 tim=1557884751568850 WAIT #139760412634104: nam='db file sequential read' ela= 3 file#=1 block#=1 blocks=1 obj#=-1 tim=1557884751568874 ##数据文件1的1号块 WAIT #139760412634104: nam='db file sequential read' ela= 1 file#=2 block#=1 blocks=1 obj#=-1 tim=1557884751568894 WAIT #139760412634104: nam='db file sequential read' ela= 2 file#=3 block#=1 blocks=1 obj#=-1 tim=1557884751568911 WAIT #139760412634104: nam='db file sequential read' ela= 1 file#=4 block#=1 blocks=1 obj#=-1 tim=1557884751568922 WAIT #139760412634104: nam='db file sequential read' ela= 1 file#=5 block#=1 blocks=1 obj#=-1 tim=1557884751568929
2 system数据文件1号块损坏修复
测试之前先做冷备,防止修复不成功
[oracle@DSI oradata]$ cp -rf orcl/ /home/oracle/. BBED> info File# Name Size(blks) ----- ---- ---------- 1 /u01/app/oracle/oradata/orcl/system01.dbf 94720 2 /u01/app/oracle/oradata/orcl/sysaux01.dbf 76800 3 /u01/app/oracle/oradata/orcl/undotbs01.dbf 144640 4 /u01/app/oracle/oradata/orcl/users01.dbf 640 5 /u01/app/oracle/oradata/orcl/test01.dbf 6400 BBED> set file 1 block 1 FILE# 1 BLOCK# 1 BBED> map /v File: /u01/app/oracle/oradata/orcl/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> dump File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 0 to 511 Dba:0x00400001 ------------------------------------------------------------------------ 0ba20000 01004000 00000000 00000104 9bec0000 00000000 0004200b cf766f5b 4f52434c 00000000 c0170000 00770100 00200000 01000300 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 08024000 07000000 00000000 512bfa3b 4f2bfa3b 01000000 00000000 00000000 00000000 00000000 00000420 8c000000 b993173c 8b000000 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 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 06005359 5354454d 00000000 00000000 00000000 00000000 00000000 00000000 01000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0a000a00 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 21fd1700 00000000 3e171a3c 01000000 75000000 1e7b0000 10000000 <32 bytes per line>
模拟损坏,用4号文件的10号块覆盖1号文件1号块
BBED> copy file 4 block 10 to file 1 block 1 Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 0 to 511 Dba:0x00400001 ------------------------------------------------------------------------ 1ea20000 0a000001 553e0000 00000104 a6010000 04000000 80403600 00000000 00000000 00f80000 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 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 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 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 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 <32 bytes per line> BBED> sum apply Check value for File 1, Block 1: current = 0x01a6, required = 0x01a6
#正常关闭不了数据库,直接abort
SQL> shutdown immediate ORA-01122: database file 1 failed verification check ORA-01110: data file 1: '/u01/app/oracle/oradata/orcl/system01.dbf' ORA-01210: data file header is media corrupt SQL> shutdown abort ORACLE instance shut down. SQL> startup ORACLE instance started. Total System Global Area 784998400 bytes Fixed Size 2257352 bytes Variable Size 511708728 bytes Database Buffers 264241152 bytes Redo Buffers 6791168 bytes Database mounted. ORA-01122: database file 1 failed verification check ORA-01110: data file 1: '/u01/app/oracle/oradata/orcl/system01.dbf' ORA-01210: data file header is media corrupt
#只能启动到mount阶段,提示需要介质恢复
BBED> set file 1 block 1 FILE# 1 BLOCK# 1 BBED> map /v File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Dba:0x00400001 ------------------------------------------------------------ BBED-00400: invalid blocktype (30) ##查看文件,提示无效数据块
构造文件头结构
用2号文件的1号块覆盖给1号文件1号块
BBED> set file 2 block 1 FILE# 2 BLOCK# 1 BBED> map /v File: /u01/app/oracle/oradata/orcl/sysaux01.dbf (2) Block: 1 Dba:0x00800001 ------------------------------------------------------------ Data File Header BBED> copy file 2 block 1 to file 1 block 1 File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 0 to 511 Dba:0x00400001 ------------------------------------------------------------------------ 0ba20000 01008000 00000000 00000104 c4d80000 00000000 0004200b cf766f5b 4f52434c 00000000 c0170000 003b0100 00200000 02000300 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 07070000 00000000 522bfa3b 4f2bfa3b 01000000 00000000 00000000 00000000 00000000 00000400 8c000000 b993173c 8b000000 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 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 01000000 06005359 53415558 00000000 00000000 00000000 00000000 00000000 00000000 02000000 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 00000000 00000000 21fd1700 00000000 3e171a3c 01000000 75000000 1e7b0000 10000000 <32 bytes per line> BBED> sum apply Check value for File 1, Block 1: current = 0xd8c4, required = 0xd8c4 查看文件头的结构 BBED> set file 1 block 1 FILE# 1 BLOCK# 1 BBED> map /v File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Dba:0x00400001 ------------------------------------------------------------ Data File Header
BBED修复文件头
1. rdba_kcbh(offset 4) 文件头block的rdba地址
2. kccfhfsz (offset 44) 文件大小
3. kccfhfno (offset 52) datafile文件号
4. kcvfhrdb (offset 96) root dba
5. kscnbas (offset 100) v$datafile.creation_change#
6. kcvfhcrt (offset 108) v$datafile.creation_time
7. kcvfhsta (offset 138) 文件状态
8. kcvfhtsn (offset 332) 表空间号v$datafile.ts#
9.kcvfhtln (offset 336) 表空间名称字符长度
10. kcvfhtnm (offset 338) 表空间名称v$tablespace.name
11. kcvfhrfn (offset 368) 相对文件号v$datafile.rfile#
12. kscnbas (offset 484) checkpoint scn
13.kcvcptim (offset 492) last checkpoint time
14.kcvfhcpc (offset 144) Datafile checkpoint count
1 BBED修复文件头block的rdba地址
BBED> p kcvfhbfh struct kcvfhbfh, 20 bytes @0 ub4 rdba_kcbh @4 0x00800001 rdba地址转换 SQL> select dbms_utility.data_block_address_file(TO_NUMBER('800001','XXXXXXXX')) file_id,dbms_utility.data_block_address_block(TO_NUMBER('800001','XXXXXXXX')) block_id from dual; 32个字节,前10个bit文件号,后22个bit块号 0000 0000 1000 >>0000 0000 10 得出是2号文件,现在要修改为1号文件0000 0000 0100>>0x00400001 转换成十六进制 BBED修复文件头block的rdba地址 ( Cont … ) BBED> set file 1 block 1 offset 4 count 32 FILE# 1 BLOCK# 1 OFFSET 4 COUNT 32 BBED> dump ##查看值 File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 4 to 35 Dba:0x00400001 ------------------------------------------------------------------------ 01008000 00000000 00000104 c4d80000 00000000 0004200b cf766f5b 4f52434c <32 bytes per line> BBED> modify /x 01004000 offset 4 ##修改 File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 4 to 35 Dba:0x00400001 ------------------------------------------------------------------------ 01004000 00000000 00000104 c4d80000 00000000 0004200b cf766f5b 4f52434c <32 bytes per line> BBED> sum apply ##提交 Check value for File 1, Block 1: current = 0xd804, required = 0xd804 BBED> dump ##再次查看,已经修改为01004000 File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 4 to 35 Dba:0x00400001 ------------------------------------------------------------------------ 01004000 00000000 00000104 04d80000 00000000 0004200b cf766f5b 4f52434c <32 bytes per line>
2 BBED修复文件头的文件大小
BBED> p kcvfhhdr ub4 kccfhfsz @44 0x00013b00 从系统层面查看system数据文件的大小 [oracle@DSI orcl]$ ll -l |grep system* -rw-r----- 1 oracle oinstall 786440192 May 15 15:32 system01.dbf 计算大小 SQL> select (786440192-8192)/8192 from dual; ##-8192是减去os层面的0号块 (786440192-8192)/8192 --------------------- 96000 SQL> select to_char(96000,'xxxxxxxxxxxxxxx') from dual; TO_CHAR(96000,'X ---------------- 17700 BBED> set file 1 block 1 offset 44 count 32 FILE# 1 BLOCK# 1 OFFSET 44 COUNT 32 BBED> dump File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 44 to 75 Dba:0x00400001 ------------------------------------------------------------------------ 003b0100 00200000 02000300 00000000 00000000 00000000 00000000 00000000 <32 bytes per line> BBED> modify /x 00770100 ##需要把17700反一下,先补全00017700,然后在反 File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 44 to 75 Dba:0x00400001 ------------------------------------------------------------------------ 00770100 00200000 02000300 00000000 00000000 00000000 00000000 00000000 <32 bytes per line> BBED> sum apply Check value for File 1, Block 1: current = 0x9404, required = 0x9404 BBED> dump File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 44 to 75 Dba:0x00400001 ------------------------------------------------------------------------ 00770100 00200000 02000300 00000000 00000000 00000000 00000000 00000000 <32 bytes per line>
3 BBED修复文件头的文件号
BBED> p kcvfhhdr ub2 kccfhfno @52 0x0002 BBED> set file 1 block 1 offset 52 count 32 FILE# 1 BLOCK# 1 OFFSET 52 COUNT 32 BBED> dump File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 52 to 83 Dba:0x00400001 ------------------------------------------------------------------------ 02000300 00000000 00000000 00000000 00000000 00000000 00000000 00000000 <32 bytes per line> BBED> modify /x 01 offset 52 File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 52 to 83 Dba:0x00400001 ------------------------------------------------------------------------ 01000300 00000000 00000000 00000000 00000000 00000000 00000000 00000000 <32 bytes per line> BBED> sum apply Check value for File 1, Block 1: current = 0x9407, required = 0x9407 BBED> dump File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 52 to 83 Dba:0x00400001 ------------------------------------------------------------------------ 01000300 00000000 00000000 00000000 00000000 00000000 00000000 00000000 <32 bytes per line>
4 BBED修复文件头的root数据块号
SQL> select fhrdb,FHFNO from x$kcvfh order by 2; FHRDB FHFNO ---------- ---------- 4194824 1 SQL> select to_char(4194824,'xxxxxxxxxx') from dual; TO_CHAR(419 ----------- 400208 SQL> select dbms_utility.data_block_address_file(TO_NUMBER('400208', 'XXXXXXXX')) file_id,dbms_utility.data_block_address_block(TO_NUMBER('400208', 'XXXXXXXX')) block_id from dual; FILE_ID BLOCK_ID ---------- ---------- 1 520 =>1号文件520号块 SQL> select to_char(520,'xxxxxxxxxxxxxxxxxxx') from dual; TO_CHAR(520,'XXXXXXX -------------------- 208 =>00400208 BBED> p kcvfhrdb ub4 kcvfhrdb @96 0x00000000 BBED> set file 1 block 1 offset 96 count 32 FILE# 1 BLOCK# 1 OFFSET 96 COUNT 32 BBED> dump File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 96 to 127 Dba:0x00400001 ------------------------------------------------------------------------ 00000000 07070000 00000000 522bfa3b 4f2bfa3b 01000000 00000000 00000000 <32 bytes per line> BBED> modify /x 08024000 ##同样这里也取反 File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 96 to 127 Dba:0x00400001 ------------------------------------------------------------------------ 08024000 07070000 00000000 522bfa3b 4f2bfa3b 01000000 00000000 00000000 <32 bytes per line> BBED> sum apply Check value for File 1, Block 1: current = 0x964f, required = 0x964f BBED> dump File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 96 to 127 Dba:0x00400001 ------------------------------------------------------------------------ 08024000 07070000 00000000 522bfa3b 4f2bfa3b 01000000 00000000 00000000 <32 bytes per line>
5 BBED修复文件头的文件创建SCN
BBED> p kcvfhcrs struct kcvfhcrs, 8 bytes @100 ub4 kscnbas @100 0x00000707 ub2 kscnwrp @104 0x0000 SQL> select file#,creation_change# from v$datafile; 1 7 2 1799 3 2821 4 15940 5 929531 SQL> select to_char(1799,'xxxxxxxxxxxx') from dual; TO_CHAR(1799, ------------- 707 BBED> set file 1 block 1 offset 100 count 32 FILE# 1 BLOCK# 1 OFFSET 100 COUNT 32 BBED> dump File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 100 to 131 Dba:0x00400001 ------------------------------------------------------------------------ 07070000 00000000 522bfa3b 4f2bfa3b 01000000 00000000 00000000 00000000 <32 bytes per line> BBED> modify /x 07000000 offset 100 ###由于这里是用的2号文件的1号块覆盖的,所以这里的值是2号文件的707,要修改为7 File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 100 to 131 Dba:0x00400001 ------------------------------------------------------------------------ 07000000 00000000 522bfa3b 4f2bfa3b 01000000 00000000 00000000 00000000 <32 bytes per line> BBED> sum apply Check value for File 1, Block 1: current = 0x914f, required = 0x914f
6 BBED修复文件头的文件创建时间
BBED> p kcvfhcrt ub4 kcvfhcrt @108 0x3bfa2b52 BBED> set file 1 block 1 offset 108 count 32 FILE# 1 BLOCK# 1 OFFSET 108 COUNT 32 BBED> dump File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 108 to 139 Dba:0x00400001 ------------------------------------------------------------------------ 522bfa3b 4f2bfa3b 01000000 00000000 00000000 00000000 00000000 00000400 <32 bytes per line> SQL> select file#,to_char(creation_time,'yyyy-mm-dd hh24:mi:ss') creation_time_file, (to_char(creation_time,'yyyy')-1988)*12*31*24*3600+ (to_char(creation_time,'mm')-1)*31*24*3600 +(to_char(creation_time,'dd')-1)*24*3600 +to_char(creation_time,'hh24')*3600 +to_ 2 3 4 5 6 char(creation_time,'mi')*60 +to_char(creation_time,'ss') creation_name_scn from v$datafile order by 1; 7 8 FILE# CREATION_TIME_FILE CREATION_NAME_SCN ---------- ------------------- ----------------- 1 2019-04-22 10:07:13 1006250833 2 2019-04-22 10:07:14 1006250834 3 2019-04-22 10:07:15 1006250835 4 2019-04-22 10:07:20 1006250840 5 2019-04-22 17:12:12 1006276332 SQL> select to_char(1006250833,'xxxxxxxxxxxx') from dual; TO_CHAR(10062 ------------- 3bfa2b51 BBED> dump File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 108 to 139 Dba:0x00400001 ------------------------------------------------------------------------ 522bfa3b 4f2bfa3b 01000000 00000000 00000000 00000000 00000000 00000400 <32 bytes per line> BBED> modify /x 512bfa3b offset 108 ##取反,如果这里报错无效的number,则分开修改 108,109,110,111 File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 108 to 139 Dba:0x00400001 ------------------------------------------------------------------------ 512bfa3b 4f2bfa3b 01000000 00000000 00000000 00000000 00000000 00000400 <32 bytes per line> BBED> sum apply Check value for File 1, Block 1: current = 0x914c, required = 0x914c
7 BBED修复文件头的文件状态
BBED> p offset 138 kcvfh.kcvfhsta -------------- ub2 kcvfhsta @138 0x0004 (KCVFHOFZ) BBED> set file 1 block 1 offset 138 count 32 FILE# 1 BLOCK# 1 OFFSET 138 COUNT 32 BBED> dump File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 138 to 169 Dba:0x00400001 ------------------------------------------------------------------------ 04008c00 0000b993 173c8b00 00000000 00000000 00000000 00000000 00000000 <32 bytes per line> #当一个datafile处于fuzzy状态的时候,其kcvfhsta为0x04,这里是abort关闭,状态时04,不修改,如果是正常关闭,则是0x2000
8 BBED修复文件头的表空间号
BBED> p kcvfhtsn sword kcvfhtsn @332 1 BBED> set file 1 block 1 offset 332 count 32 FILE# 1 BLOCK# 1 OFFSET 332 COUNT 32 BBED> dump File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 332 to 363 Dba:0x00400001 ------------------------------------------------------------------------ 01000000 06005359 53415558 00000000 00000000 00000000 00000000 00000000 <32 bytes per line> SQL> select file#,ts# from v$datafile; FILE# TS# ---------- ---------- 1 0 2 1 3 2 4 4 5 5 BBED> modify /x 00 offset 332 ##这里是system数据文件,ts为0 File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 332 to 363 Dba:0x00400001 ------------------------------------------------------------------------ 00000000 06005359 53415558 00000000 00000000 00000000 00000000 00000000 <32 bytes per line> BBED> sum apply Check value for File 1, Block 1: current = 0x914d, required = 0x914d
9 BBED修复文件头的表空间长度
BBED> p kcvfhtln ub2 kcvfhtln @336 0x0006 BBED> p kcvfhtnm text kcvfhtnm[0] @338 S text kcvfhtnm[1] @339 Y text kcvfhtnm[2] @340 S text kcvfhtnm[3] @341 A text kcvfhtnm[4] @342 U text kcvfhtnm[5] @343 X SYSTEM表空间长度一致
10 BBED修复文件头的表空间名称
BBED> p kcvfhtnm text kcvfhtnm[0] @338 S text kcvfhtnm[1] @339 Y text kcvfhtnm[2] @340 S text kcvfhtnm[3] @341 A text kcvfhtnm[4] @342 U text kcvfhtnm[5] @343 X 修改为SYSTEM BBED> set file 1 block 1 offset 338 count 32 FILE# 1 BLOCK# 1 OFFSET 338 COUNT 32 BBED> dump File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 338 to 369 Dba:0x00400001 ------------------------------------------------------------------------ 53595341 55580000 00000000 00000000 00000000 00000000 00000000 00000200 <32 bytes per line> SQL> select dump('SYSTEM',16) from dual; DUMP('SYSTEM',16) ------------------------------- Typ=96 Len=6: 53,59,53,54,45,4d BBED> set file 1 block 1 offset 341 ##直接从341偏移量开始修改,前面SYS都一样 FILE# 1 BLOCK# 1 OFFSET 341 BBED> modify /x 54454d File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 341 to 372 Dba:0x00400001 ------------------------------------------------------------------------ 54454d00 00000000 00000000 00000000 00000000 00000000 00000002 00000000 <32 bytes per line> BBED> sum apply Check value for File 1, Block 1: current = 0x915d, required = 0x915d
11 BBED修复文件头的相对文件号
BBED> p kcvfhrfn ub4 kcvfhrfn @368 0x00000002 BBED> set file 1 block 1 offset 368 FILE# 1 BLOCK# 1 OFFSET 368 BBED> dump File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 368 to 399 Dba:0x00400001 ------------------------------------------------------------------------ 02000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 <32 bytes per line> SQL> select file#,rfile# from v$datafile; FILE# RFILE# ---------- ---------- 1 1 2 2 3 3 4 4 5 5 BBED> modify /x 01 offset 368 #修改为对于的 RFILE File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 368 to 399 Dba:0x00400001 ------------------------------------------------------------------------ 01000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 <32 bytes per line> BBED> sum apply Check value for File 1, Block 1: current = 0x915e, required = 0x915e
12 BBED修复文件头的检查点SCN
BBED> p kcvfhckp struct kcvfhckp, 36 bytes @484 struct kcvcpscn, 8 bytes @484 ub4 kscnbas @484 0x0017fd21 ub2 kscnwrp @488 0x0000 ub4 kcvcptim @492 0x3c1a173e SQL> set pagesize 999 SQL> set linesize 999 SQL> select file#,CREATION_CHANGE#,CHECKPOINT_CHANGE# ,UNRECOVERABLE_CHANGE#,LAST_CHANGE#,OFFLINE_CHANGE# from v$datafile order by 1; FILE# CREATION_CHANGE# CHECKPOINT_CHANGE# UNRECOVERABLE_CHANGE# LAST_CHANGE# OFFLINE_CHANGE# ---------- ---------------- ------------------ --------------------- ------------ --------------- 1 7 1572129 0 0 2 1799 1572129 0 0 3 2821 1572129 0 0 4 15940 1572129 0 0 5 929531 1572129 0 0 SQL> select to_char(1572129,'xxxxxxxxxxxxxxxx') from dual; TO_CHAR(1572129,' ----------------- 17fd21 这里的值跟 ub4 kscnbas @484 0x0017fd21是一样的,不用修改
13 BBED修复文件头的检查点时间
BBED> set file 1 block 1 offset 492 FILE# 1 BLOCK# 1 OFFSET 492 BBED> dump File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 1 Offsets: 492 to 523 Dba:0x00400001 ------------------------------------------------------------------------ 3e171a3c 01000000 75000000 1e7b0000 10000000 02000000 00000000 00000000 <32 bytes per line> select file#,to_char(CHECKPOINT_TIME,'yyyy-mm-dd hh24:mi:ss') CHECKPOINT_TIME_file, (to_char(CHECKPOINT_TIME,'yyyy')-1988)*12*31*24*3600 +(to_char(CHECKPOINT_TIME,'mm')-1)*31*24*3600 +(to_char(CHECKPOINT_TIME,'dd')-1)*24*3600 +to_char(CHECKPOINT_TIME,'hh24')*3600 +to_char(CHECKPOINT_TIME,'mi')*60 +to_char(CHECKPOINT_TIME,'ss') CHECKPOINT_TIME_scn from v$datafile order by 1; SQL> select file#,to_char(CHECKPOINT_TIME,'yyyy-mm-dd hh24:mi:ss') CHECKPOINT_TIME_file, (to_char(CHECKPOINT_TIME,'yyyy')-1988)*12*31*24*3600 +(to_char(CHECKPOINT_TIME,'mm')-1)*31*24*3600 +(to_char(CHECKPOINT_TIME,'dd')-1)*24*3600 +to_char(CHECKPOINT_TIME,'hh24 2 3 4 5 6 ')*3600 +to_char(CHECKPOINT_TIME,'mi')*60 +to_char(CHECKPOINT_TIME,'ss') CHECKPOINT_TIME_scn from v$datafile order by 1; 7 8 9 FILE# CHECKPOINT_TIME_FIL CHECKPOINT_TIME_SCN ---------- ------------------- ------------------- 1 2019-05-15 15:14:06 1008342846 2 2019-05-15 15:14:06 1008342846 3 2019-05-15 15:14:06 1008342846 4 2019-05-15 15:14:06 1008342846 5 2019-05-15 15:14:06 1008342846 SQL> select to_char(1008342846,'xxxxxxxxxxxxxxxxxxxxxxx') from dual; TO_CHAR(1008342846,'XXXX ------------------------ 3c1a173e 这里的值与ub4 kcvcptim @492 0x3c1a173e一样,不用修改
通过dbv检查下文件头修改是否都正确
[oracle@DSI ~]$ dbv file=/u01/app/oracle/oradata/orcl/system01.dbf start=1 end=2 DBVERIFY: Release 11.2.0.4.0 - Production on Wed May 15 16:48:53 2019 Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved. DBVERIFY - Verification starting : FILE = /u01/app/oracle/oradata/orcl/system01.dbf DBVERIFY - Verification complete Total Pages Examined : 2 Total Pages Processed (Data) : 0 Total Pages Failing (Data) : 0 Total Pages Processed (Index): 0 Total Pages Failing (Index): 0 Total Pages Processed (Other): 2 Total Pages Processed (Seg) : 0 Total Pages Failing (Seg) : 0 Total Pages Empty : 0 Total Pages Marked Corrupt : 0 Total Pages Influx : 0 Total Pages Encrypted : 0 Highest block SCN : 1352932 (0.1352932) SQL> alter database open; Database altered.
这里成功打开数据库
如果打开数据库报错,根据提示再检查修改相应的块内容
如果是提示控制文件太旧
方法一:修改checkpoint count
kcvfhcpc (offset 144) Datafile checkpoint count
kcvfhccc (offset 148) Controlfile Checkpoint Count
kcvfhcpc>kcvfhccc+1 一般是这样
方法二:手工创建control file
测试题目:
1.模拟2号文件头损坏恢复的实验(详细操作步骤)
--这里2号文件跟1号文件类似,不用修改4. kcvfhrdb (offset 96) root dba
2.Oracle 11g 没有备份的情况下,1号文件520号块坏了,还能恢复吗?
如果不能恢复请给出原因?如果能恢复请给出方法和思路?
不能简单的从其他块进行覆盖修改,这里没有其他的文件快可以替换,结构都不一样,不清楚这个520号块的作用,是否可以从其他实例cp这520号块
查看本地其他数据文件的520号块
BBED> set file 1 block 1 FILE# 1 BLOCK# 1 BBED> p offset 520 pad --- ub1 pad @520 0x00 BBED> set file 1 block 520 FILE# 1 BLOCK# 520 BBED> map /v File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 520 Dba:0x00400208 ------------------------------------------------------------ Unlimited Data Segment Header struct kcbh, 20 bytes @0 ub1 type_kcbh @0 ub1 frmt_kcbh @1 ub1 spare1_kcbh @2 ub1 spare2_kcbh @3 ub4 rdba_kcbh @4 ub4 bas_kcbh @8 ub2 wrp_kcbh @12 ub1 seq_kcbh @14 ub1 flg_kcbh @15 ub2 chkval_kcbh @16 ub2 spare3_kcbh @18 struct ktech, 72 bytes @20 ub4 spare1_ktech @20 sword tsn_ktech @24 ub4 lastmap_ktech @28 ub4 mapcount_ktech @32 ub4 extents_ktech @36 ub4 blocks_ktech @40 ub2 mapend_ktech @44 struct hwmark_ktech, 32 bytes @48 struct locker_ktech, 8 bytes @80 ub4 flag_ktech @88 struct ktemh, 16 bytes @92 ub4 count_ktemh @92 ub4 next_ktemh @96 ub4 obj_ktemh @100 ub4 flag_ktemh @104 struct ktetb[1], 8 bytes @108 ub4 ktetbdba @108 ub4 ktetbnbk @112 struct ktshc, 8 bytes @4148 ub2 ktshcnxf @4148 ub2 ktshcnfl @4150 ub2 ktshcnfb @4152 ub1 ktshctyp @4154 struct ktsfs_seg[1], 20 bytes @4156 ub2 ktsfsflg @4156 struct ktsfsxid, 8 bytes @4160 ub4 ktsfslhd @4168 ub4 ktsfsltl @4172 struct ktsfs_txn[16], 320 bytes @4176 ub2 ktsfsflg @4176 struct ktsfsxid, 8 bytes @4180 ub4 ktsfslhd @4188 ub4 ktsfsltl @4192 ub4 tailchk @8188 BBED> dump File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 520 Offsets: 0 to 511 Dba:0x00400208 ------------------------------------------------------------------------ 10a20000 08024000 b9010000 00000204 43e40000 00000000 00000000 00000000 00000000 01000000 07000000 20100000 00000000 03000000 07000000 0c024000 00000000 00000000 01000000 03000000 00000000 00000000 00000000 01000000 00000000 3b000000 00000040 09024000 07000000 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 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 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 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 <32 bytes per line> BBED> set file 2 block 520 FILE# 2 BLOCK# 520 BBED> map /v File: /u01/app/oracle/oradata/orcl/sysaux01.dbf (2) Block: 520 Dba:0x00800208 ------------------------------------------------------------ BBED-00400: invalid blocktype (32) BBED> p offset 520 BBED-00400: invalid blocktype (32) BBED> set file 3 block 520 FILE# 3 BLOCK# 520 BBED> p offset 520 freespace[478] -------------- ub1 freespace[478] @520 0x00 BBED> map /v File: /u01/app/oracle/oradata/orcl/undotbs01.dbf (3) Block: 520 Dba:0x00c00208 ------------------------------------------------------------ Undo Data struct kcbh, 20 bytes @0 ub1 type_kcbh @0 ub1 frmt_kcbh @1 ub1 spare1_kcbh @2 ub1 spare2_kcbh @3 ub4 rdba_kcbh @4 ub4 bas_kcbh @8 ub2 wrp_kcbh @12 ub1 seq_kcbh @14 ub1 flg_kcbh @15 ub2 chkval_kcbh @16 ub2 spare3_kcbh @18 struct ktubh, 22 bytes @20 struct ktubhxid, 8 bytes @20 ub2 ktubhseq @28 ub1 ktubhcnt @30 ub1 ktubhirb @31 ub1 ktubhicl @32 ub1 ktubhflg @33 ub2 ktubhidx[4] @34 ub1 freespace[7806] @42 ub1 undodata[340] @7848 ub4 tailchk @8188
查看并修改1号文件520号块
SQL> select distinct dbms_rowid.rowid_relative_fno(rowid) file#, dbms_rowid.rowid_block_number(rowid) block# from bootstrap$; 2 3 FILE# BLOCK# ---------- ---------- 1 521 1 523 1 522 查看并修改1号文件520号块 BBED> info File# Name Size(blks) ----- ---- ---------- 1 /u01/app/oracle/oradata/orcl/system01.dbf 94720 2 /u01/app/oracle/oradata/orcl/sysaux01.dbf 76800 3 /u01/app/oracle/oradata/orcl/undotbs01.dbf 144640 4 /u01/app/oracle/oradata/orcl/users01.dbf 640 5 /u01/app/oracle/oradata/orcl/test01.dbf 6400 这里从别处cp一个system01数据文件过来,由于这个是单实例,我从一个rac集群拷贝一个system过来试试 ASMCMD> cp SYSTEM.259.1001364555 /tmp/. copying +data/bol/datafile/SYSTEM.259.1001364555 -> /tmp/./SYSTEM.259.1001364555 [grid@rac03 tmp]$ scp SYSTEM.259.1001364555 oracle@10.15.7.25:/tmp/. [oracle@DSI ~]$ vim filelist.txt [oracle@DSI ~]$ bbed BBED> info File# Name Size(blks) ----- ---- ---------- 1 /u01/app/oracle/oradata/orcl/system01.dbf 94720 2 /u01/app/oracle/oradata/orcl/sysaux01.dbf 76800 3 /u01/app/oracle/oradata/orcl/undotbs01.dbf 144640 4 /u01/app/oracle/oradata/orcl/users01.dbf 640 5 /u01/app/oracle/oradata/orcl/test01.dbf 6400 6 /u01/app/oracle/oradata/orcl/SYSTEM.259.1001364555 0 BBED> copy file 6 block 520 to file 1 block 520 Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y File: /u01/app/oracle/oradata/orcl/system01.dbf (1) Block: 520 Offsets: 0 to 511 Dba:0x00400208 ------------------------------------------------------------------------ 10a20000 08024000 d0010000 00000204 43e40000 00000000 00000000 00000000 00000000 01000000 07000000 20100000 00000000 03000000 07000000 0c024000 00000000 00000000 01000000 03000000 00000000 00000000 00000000 01000000 00000000 3b000000 00000040 09024000 07000000 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 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 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 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 <32 bytes per line> BBED> sum apply Check value for File 1, Block 520: current = 0xe443, required = 0xe443 启动成功 SQL> startup ORACLE instance started. Total System Global Area 784998400 bytes Fixed Size 2257352 bytes Variable Size 511708728 bytes Database Buffers 264241152 bytes Redo Buffers 6791168 bytes Database mounted. Database opened.
3.以下SQL中的1988是怎么得来的?
select file#,to_char(creation_time,'yyyy-mm-dd hh24:mi:ss') creation_time_file,
(to_char(creation_time,'yyyy')-1988)*12*31*24*3600+
(to_char(creation_time,'mm')-1)*31*24*3600
+(to_char(creation_time,'dd')-1)*24*3600
+to_char(creation_time,'hh24')*3600
+to_ 2 3 4 5 6 char(creation_time,'mi')*60
+to_char(creation_time,'ss') creation_name_scn
from v$datafile order by 1;
--数据库记录时间起点
1988/01/01 00:00:00