2.4.7 print(p)
The print command allows data structures to be printed in raw or formatted output. The DBA, Filename, File, Block and/or Offset to print can be specified with thecommand. If these are not specified, the current file, block and offset asestablished with the set command will be printed. print命令输出某个结构或元素的值。 /x输出结果为十六进制(默认),/d为十进制。在使用print时,可以指定dba,block 等参数来限定输出特定block。 If the print command is issued with just the block and offset to print, bbed will display the data structure at that offset.
在4.5 节map里讲了block的结构,在前面,我们讲过,可以通过dump 来查看block 的type。通过print 也可以查看。 现在我们print 一个file 4,block 30的Data Block Header 的type。
BBED> p frmt_kcbh ##默认是十六进制显示内容 ub1 frmt_kcbh @1 0xa2 BBED> p /d frmt_kcbh ##/d为十进制显示内容 ub1 frmt_kcbh @1 162
It is also possible to use the print command to print individual data structuresby specifying the name. 可以通过print 输出指定名称的结构。
BBED> p kcbh struct kcbh, 20 bytes @0 ub1 type_kcbh @0 0x06 ub1 frmt_kcbh @1 0xa2 ub1 spare1_kcbh @2 0x00 ub1 spare2_kcbh @3 0x00 ub4 rdba_kcbh @4 0x01000097 ub4 bas_kcbh @8 0x000ebe73 ub2 wrp_kcbh @12 0x0000 ub1 seq_kcbh @14 0x02 ub1 flg_kcbh @15 0x06 (KCBHFDLC, KCBHFCKV) ub2 chkval_kcbh @16 0xaf1f ub2 spare3_kcbh @18 0x0000
If we wanted to determine the number of rows in the block, we could print the data header structure or kdbh: 如果我们想确定block 中row的数量,可以print data header structure 或者kdbh。
BBED> p kdbh struct kdbh, 14 bytes @100 ub1 kdbhflag @100 0x00 (NONE) b1 kdbhntab @101 1 b2 kdbhnrow @102 14 sb2 kdbhfrre @104 -1 sb2 kdbhfsbo @106 46 sb2 kdbhfseo @108 7521 b2 kdbhavsp @110 7475 b2 kdbhtosp @112 7475
We can also specifying certain datastructure elements to print such as the row count: 也可以指定某个具体的structure元素进行print。
BBED> p kdbhnrow b2 kdbhnrow @102 14 BBED> p kcbh.type_kcbh ub1 type_kcbh @0 0x06 BBED> p type_kcbh ub1 type_kcbh @0 0x06
注意: 当print 一个data structure 时,输出的格式如下: UnitSize* | Name | Offset| Value
*Unit size is shown in bytes and indicates if the value is signed (s) or unsigned (u). UnitSize显示为字节数,有正负符号的,字节数前有"s"标识;无正负符号的,字节数前用"u"标识。 如:
sb2 kdbhfrre @104 -1 ##sb2表示:此值为有正负符号的值,占2个字节。值为:-1 sb2 kdbhfsbo @106 14 ##sb2表示:此值为有正负符号的值,占2个字节。值为:14 ub4 rdba_kcbh @4 0x0100001d ##ub4表示:此值为无正负符号的值,占4个字节。值为:0x0100001d ub4 bas_kcbh @8 0x004402f0 ##ub4表示:此值为无正负符号的值,占4个字节。值为:0x004402f0
Inaddition to printing information about the specified data structure, the print command can also be used to print information about the location the data structure points to by using the pointer (*) prefix. 我们可以使用kdbr[0] 作为一个指针来print 它对应的内容。这个kdbr[0] 是一个本地的data structure,此时print 需要加前缀星号。
BBED> p kdbr ##查看共有多少行 sb2 kdbr[0] @118 8050 sb2 kdbr[1] @120 8007 sb2 kdbr[2] @122 7964 sb2 kdbr[3] @124 7923 sb2 kdbr[4] @126 7878 sb2 kdbr[5] @128 7837 sb2 kdbr[6] @130 7796 sb2 kdbr[7] @132 7756 sb2 kdbr[8] @134 7718 sb2 kdbr[9] @136 7675 sb2 kdbr[10] @138 7637 sb2 kdbr[11] @140 7599 sb2 kdbr[12] @142 7560 sb2 kdbr[13] @144 7521 BBED> p *kdbr[0] ##转到某一行的偏移量位置 rowdata[529] ------------ ub1 rowdata[529] @8150 0x2c BBED> show FILE# 4 BLOCK# 152 OFFSET 8150 DBA 0x01000098 (16777368 4,152) FILENAME D:\APP\LVS\ORADATA\LVS\USERS01.DBF BIFILE bifile.bbd LISTFILE filelist.txt BLOCKSIZE 8192 MODE Edit EDIT Unrecoverable IBASE Dec OBASE Dec WIDTH 80 COUNT 128 LOGFILE bbed.log SPOOL Yes BBED> dump /v ##dump方式查看某一行的内容 File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4) Block: 152 Offsets: 8150 to 8191 Dba:0x01000098 ------------------------------------------------------- 2c000803 c24a4605 534d4954 4805434c l ,...翵F.SMITH.CL 45524b03 c2500307 77b40c11 01010102 l ERK.翽..w?..... c209ff02 c1150206 73be l ?..?..s? <16 bytes per line> SQL> desc scott.emp Name Null? Type ----------------------------------------- -------- ---------------------------- EMPNO NOT NULL NUMBER(4) ENAME VARCHAR2(10) JOB VARCHAR2(9) MGR NUMBER(4) HIREDATE DATE SAL NUMBER(7,2) COMM NUMBER(7,2) DEPTNO NUMBER(2) BBED> x /rnccntnnn ##格式化查看某一行各列的内容(按表结构中各个列的数据类型,nccnxnnn分别为:数字、字符、字符、数字、十六进制(日期不知道用哪个参数)、字符、字符、字符 rowdata[529] @8150 ------------ flag@8150: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@8151: 0x00 cols@8152: 8 col 0[3] @8153: 7369 col 1[5] @8157: SMITH col 2[5] @8163: CLERK col 3[3] @8169: 7902 col 4[7] @8173: 17-DEC-80 col 5[2] @8181: 800 col 6[0] @8184: *NULL* col 7[2] @8185: 20 print输出结果默认是16进制的。我们可以将其修改成其他格式。 Switch Display Format /x Hex /d signed decimal /u unsigned decimal /o Octal /c Character /n Oracle Number /t Oracle Date /i Oracle ROWID BBED> p *kdbr[0] rowdata[529] ------------ ub1 rowdata[529] @8150 0x2c BBED> p /d *kdbr[0] rowdata[529] ------------ ub1 rowdata[529] @8150 44
2.4.8 examine(x)
examine 命令用于以原始或格式化输出显示块中的数据。 可以使用该命令指定要检查的 DBA、文件名、文件、块和/或偏移量。 如果未指定这些,则将检查使用 set 命令建立的当前文件、块和偏移。 如果发出 examine 命令时仅带有要检查的块和偏移量,则 bbed 将显示该偏移量处的数据结构。
与 print 命令不同,它不能解释数据结构,但可用于显示行信息。 结合对行数据类型的了解,它可以用来从块中检索完整的行:
examine命令可显示格式化的数据结构内容或行数据内容。
examine 命令将根据以下开关解释块中的数据:
Switch Display Format /b b1, ub1 (byte) /h b2, ub2 (half-word) /w b4, ub4 (word) /l b8, ub8 (long) (was b4/ub4 in Oracle7). /r Oracle table/index row
examine可以根据switch的方式和print 命令进行一个结合来对data 进行解释说明。
SQL> desc scott.emp Name Null? Type ----------------------------------------- -------- ---------------------------- EMPNO NOT NULL NUMBER(4) ENAME VARCHAR2(10) JOB VARCHAR2(9) MGR NUMBER(4) HIREDATE DATE SAL NUMBER(7,2) COMM NUMBER(7,2) DEPTNO NUMBER(2) BBED> x /rnccntnnn ##格式化查看某一行各列的内容(按表结构中各个列的数据类型,nccnxnnn分别为:数字、字符、字符、数字、日期、字符、字符、字符 rowdata[529] @8150 ------------ flag@8150: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@8151: 0x00 cols@8152: 8 col 0[3] @8153: 7369 col 1[5] @8157: SMITH col 2[5] @8163: CLERK col 3[3] @8169: 7902 col 4[7] @8173: 17-DEC-80 col 5[2] @8181: 800 col 6[0] @8184: *NULL* col 7[2] @8185: 20 BBED> x /r ##各列都以十六进制形式显示 rowdata[529] @8150 ------------ flag@8150: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@8151: 0x00 cols@8152: 8 col 0[3] @8153: 0xc2 0x4a 0x46 col 1[5] @8157: 0x53 0x4d 0x49 0x54 0x48 col 2[5] @8163: 0x43 0x4c 0x45 0x52 0x4b col 3[3] @8169: 0xc2 0x50 0x03 col 4[7] @8173: 0x77 0xb4 0x0c 0x11 0x01 0x01 0x01 col 5[2] @8181: 0xc2 0x09 col 6[0] @8184: *NULL* col 7[2] @8185: 0xc1 0x15 还可以指定重复计数以对后续行重复检查命令,以指定多行进行显示。 下面的示例我们通过print命令讲offset指向到最后一个位置。然后repeat 14次。 BBED> p kdbhnrow b2 kdbhnrow @102 14 这个block上总共有14个rows。 BBED> p *kdbr[13] rowdata[0] ---------- ub1 rowdata[0] @7621 0x2c 先用print将offset位置指向最后一个row。 BBED> x /14rnccntnnn ##连续执行examine14次,输出所有行的内容 rowdata[0] @7621 ##此为最后一行 ---------- flag@7621: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@7622: 0x02 cols@7623: 8 col 0[3] @7624: 7934 col 1[6] @7628: MILLER col 2[5] @7635: CLERK col 3[3] @7641: 7782 col 4[7] @7645: 23-JAN-82 col 5[2] @7653: 5500 col 6[0] @7656: *NULL* col 7[2] @7657: 10 rowdata[39] @7660 ----------- flag@7660: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@7661: 0x00 cols@7662: 8 col 0[3] @7663: 7902 col 1[4] @7667: FORD col 2[7] @7672: ANALYST col 3[3] @7680: 7566 col 4[7] @7684: 03-DEC-81 col 5[2] @7692: 3000 col 6[0] @7695: *NULL* col 7[2] @7696: 20 rowdata[78] @7699 ----------- flag@7699: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@7700: 0x00 cols@7701: 8 col 0[2] @7702: 7900 col 1[5] @7705: JAMES col 2[5] @7711: CLERK col 3[3] @7717: 7698 col 4[7] @7721: 03-DEC-81 col 5[3] @7729: 950 col 6[0] @7733: *NULL* col 7[2] @7734: 30 rowdata[116] @7737 ------------ flag@7737: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@7738: 0x00 cols@7739: 8 col 0[3] @7740: 7876 col 1[5] @7744: ADAMS col 2[5] @7750: CLERK col 3[3] @7756: 7788 col 4[7] @7760: 23-MAY-87 col 5[2] @7768: 1100 col 6[0] @7771: *NULL* col 7[2] @7772: 20 rowdata[154] @7775 ------------ flag@7775: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@7776: 0x00 cols@7777: 8 col 0[3] @7778: 7844 col 1[6] @7782: TURNER col 2[8] @7789: SALESMAN col 3[3] @7798: 7698 col 4[7] @7802: 08-SEP-81 col 5[2] @7810: 1500 col 6[1] @7813: 0 col 7[2] @7815: 30 rowdata[197] @7818 ------------ flag@7818: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@7819: 0x00 cols@7820: 8 col 0[3] @7821: 7839 col 1[4] @7825: KING col 2[9] @7830: PRESIDENT col 3[0] @7840: *NULL* col 4[7] @7841: 17-NOV-81 col 5[2] @7849: 5000 col 6[0] @7852: *NULL* col 7[2] @7853: 10 rowdata[235] @7856 ------------ flag@7856: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@7857: 0x00 cols@7858: 8 col 0[3] @7859: 7788 col 1[5] @7863: SCOTT col 2[7] @7869: ANALYST col 3[3] @7877: 7566 col 4[7] @7881: 19-APR-87 col 5[2] @7889: 3000 col 6[0] @7892: *NULL* col 7[2] @7893: 20 rowdata[275] @7896 ------------ flag@7896: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@7897: 0x00 cols@7898: 8 col 0[3] @7899: 7782 col 1[5] @7903: CLARK col 2[7] @7909: MANAGER col 3[3] @7917: 7839 col 4[7] @7921: 09-JUN-81 col 5[3] @7929: 2450 col 6[0] @7933: *NULL* col 7[2] @7934: 10 rowdata[316] @7937 ------------ flag@7937: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@7938: 0x00 cols@7939: 8 col 0[3] @7940: 7698 col 1[5] @7944: BLAKE col 2[7] @7950: MANAGER col 3[3] @7958: 7839 col 4[7] @7962: 01-MAY-81 col 5[3] @7970: 2850 col 6[0] @7974: *NULL* col 7[2] @7975: 30 rowdata[357] @7978 ------------ flag@7978: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@7979: 0x00 cols@7980: 8 col 0[3] @7981: 7654 col 1[6] @7985: MARTIN col 2[8] @7992: SALESMAN col 3[3] @8001: 7698 col 4[7] @8005: 28-SEP-81 col 5[3] @8013: 1250 col 6[2] @8017: 1400 col 7[2] @8020: 30 rowdata[402] @8023 ------------ flag@8023: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@8024: 0x00 cols@8025: 8 col 0[3] @8026: 7566 col 1[5] @8030: JONES col 2[7] @8036: MANAGER col 3[3] @8044: 7839 col 4[7] @8048: 02-APR-81 col 5[3] @8056: 2975 col 6[0] @8060: *NULL* col 7[2] @8061: 20 rowdata[443] @8064 ------------ flag@8064: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@8065: 0x00 cols@8066: 8 col 0[3] @8067: 7521 col 1[4] @8071: WARD col 2[8] @8076: SALESMAN col 3[3] @8085: 7698 col 4[7] @8089: 22-FEB-81 col 5[3] @8097: 1250 col 6[2] @8101: 500 col 7[2] @8104: 30 rowdata[486] @8107 ------------ flag@8107: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@8108: 0x00 cols@8109: 8 col 0[3] @8110: 7499 col 1[5] @8114: ALLEN col 2[8] @8120: SALESMAN col 3[3] @8129: 7698 col 4[7] @8133: 20-FEB-81 col 5[2] @8141: 1600 col 6[2] @8144: 300 col 7[2] @8147: 30 rowdata[529] @8150 ##此为第一行 ------------ flag@8150: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@8151: 0x00 cols@8152: 8 col 0[3] @8153: 7369 col 1[5] @8157: SMITH col 2[5] @8163: CLERK col 3[3] @8169: 7902 col 4[7] @8173: 17-DEC-80 col 5[2] @8181: 800 col 6[0] @8184: *NULL* col 7[2] @8185: 20
注意: Oracle使用block 是从底向上的。 如果讲offset设置为0. 那么将会禁止repeat的操作。 假如当前current row 是3,repeat 2次,那么row 3 和row 2 将被显示。 如果current row 是9, repeat 3次,那么row 9,row 8 和row 7 将被显示。 如果不能满足repeat,就会返回错误。
BBED> help examine EXAMINE[/Nuf] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ] </Nuf>: N - a number which specifies a repeat count. u - a letter which specifies a unit size: b - b1, ub1 (byte) h - b2, ub2 (half-word) w - b4, ub4(word) r - Oracle table/index row f - a letter which specifies a display format: x - hexadecimal d - decimal u - unsigned decimal o - octal c - character (native) n - Oracle number t - Oracle date i - Oracle rowid
2.4.9 find(f)
find命令可以用来在某个块中搜索关键字数据内容,允许搜索数据格式为十六进制、字符、数字。 可以从offset 0(top)开始向下(块的底部offset最大)搜索, 或者从当前的offset向下搜索。
若搜索到相关内容,则偏移量指针定位到这个偏移量位置。
搜索到相关内容后,若想继续搜索下一个符合搜索条件的内容,只需再键入 f 即可!!!
开关用于确定要搜索的模式的数据类型。如下所示:
Switch Datatype /x Hexadecimal /d Decimal /u unsigned decimal /o Octal /c character (native)
find 命令支持的switch 类型如上表,注意,find 不支持number和Date 。
BBED> set offset 0 OFFSET 0 BBED> find /c smith ##关键字区分大小写 BBED-00212: search string not found BBED> find /c SMITH ##默认是从当前位置向下搜索 File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4) Block: 152 Offsets: 8158 to 8191 Dba:0x01000098 ------------------------------------------------------------------------ 534d4954 4805434c 45524b03 c2500307 77b40c11 01010102 c209ff02 c1150206 73be <32 bytes per line> BBED> BBED> dump /v offset 8158 count 128 ##根据上面找到的offset位置,dump内容 File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4) Block: 152 Offsets: 8158 to 8191 Dba:0x01000098 ------------------------------------------------------- 534d4954 4805434c 45524b03 c2500307 l SMITH.CLERK.翽.. 77b40c11 01010102 c209ff02 c1150206 l w?.....?..?.. 73be l s? <16 bytes per line> BBED> set offset 8160 OFFSET 8160 BBED> find /c SMITH CURR ##将offset设置为比目标位置往下时,此时在从当前位置向下搜索时就找不到目标内容了 BBED-00212: search string not found BBED> set offset 8100 OFFSET 8100 BBED> find /c SMITH CURR ##将offset设置为比目标位置往上时,此时在从当前位置向下搜索时就能找到目标内容 File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4) Block: 152 Offsets: 8158 to 8191 Dba:0x01000098 ------------------------------------------------------------------------ 534d4954 4805434c 45524b03 c2500307 77b40c11 01010102 c209ff02 c1150206 73be <32 bytes per line> BBED> set offset 8160 OFFSET 8160 BBED> find /c SMITH CURR BBED-00212: search string not found BBED> find /c SMITH top ##不管offset设置在哪,只要是从块顶部(offset 0)开始搜索,总能找到目标 File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4) Block: 152 Offsets: 8158 to 8191 Dba:0x01000098 ------------------------------------------------------------------------ 534d4954 4805434c 45524b03 c2500307 77b40c11 01010102 c209ff02 c1150206 73be <32 bytes per line> BBED> help find FIND[/x|d|u|o|c] numeric/character string [ TOP | CURR ]
2.4.10 copy
复制整个数据块到另一个位置。
命令格式如下:
BBED> copy dba 1,16 to dba 1,17 ##从file 1的16 block复制到file 1的17 block BBED> copy dba 1,16 to dba 2,16 ##从file 1的16 block复制到file 2的16 block
copy 是个危险的命令,慎用。
类似dd命令:
dd备份数据块: 注意: linux_x64文件系统文件,文件头占用1个8K块,真正的oracle数据文件头块是操作系统的第2个块开始的!!!!!! 因此,若需dd备份数据库的151块,则需跳过151个块(1个操作系统文件头块+150个oracle数据块)!!! 可与bbed set dba 4,151 dump /v进行比较!! dd if=/oracle/oradata/orcl/users01.dbf bs=8k skip=151 count=1 | od -A x -t x1z -v > file.out ##仅查看用途 dd if=/oracle/oradata/orcl/users01.dbf of=/oracle/oradata/orcl/users01_bak_blk151.dbf bs=8192 skip=151 count=1 dd if=/oracle/oradata/orcl/users01_bak_blk151.dbf of=/oracle/oradata/orcl/users01.dbf bs=8192 seek=151 count=1
2.4.11 modify(m)
更改块内的数据。可采用字符模式、十六进程模式、十进制模式等来更改数据内容。
如: 在表scott.emp中有SMITH,我们这里把SMITH 改成seven。
##参考:Oracle_BBED(block_browse_and_editor)使用手册.pdf
SELECT
dbms_rowid.rowid_object(rowid) DATA_OBJECT_ID,
dbms_rowid.rowid_relative_fno(rowid) REL_FNO,
dbms_rowid.rowid_block_number(rowid) BLOCKNO,
dbms_rowid.rowid_row_number(rowid) ROWNO,
empno, ename
FROM scott.emp;
DATA_OBJECT_ID REL_FNO BLOCKNO ROWNO EMPNO ENAME
-------------- ---------- ---------- ---------- ---------- ----------
86893 4 151 0 7369 SMITH
86893 4 151 1 7499 ALLEN
86893 4 151 2 7521 WARD
86893 4 151 3 7566 JONES
86893 4 151 4 7654 MARTIN
86893 4 151 5 7698 BLAKE
86893 4 151 6 7782 CLARK
86893 4 151 7 7788 SCOTT
86893 4 151 8 7839 KING
86893 4 151 9 7844 TURNER
86893 4 151 10 7876 ADAMS
DATA_OBJECT_ID REL_FNO BLOCKNO ROWNO EMPNO ENAME
-------------- ---------- ---------- ---------- ---------- ----------
86893 4 151 11 7900 JAMES
86893 4 151 12 7902 FORD
86893 4 151 13 7934 MILLER
已选择14行。
select dump('seven','16') from dual;
DUMP('SEVEN','16')
----------------------------
Typ=96 Len=5: 73,65,76,65,6e
D:\bbed>bbed parfile=bbed.txt
BBED: Release 2.0.0.0.0 - Limited Production on Mon Sep 21 15:58:57 2020
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED> show
FILE# 1
BLOCK# 1
OFFSET 0
DBA 0x00400001 (4194305 1,1)
FILENAME D:\APP\LVS\ORADATA\LVS\SYSTEM01.DBF
BIFILE bifile.bbd
LISTFILE filelist.txt
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE bbed.log
SPOOL Yes
BBED> set dba 4,152
##特别注意:
只是在此步骤时windows与linux平台操作有区别:windows需取152作为bbed的block号,linux取查询到的151作为块号即可。以下其余操作两平台没有任何区别!!!
DBA 0x01000098 (16777368 4,152)
BBED> show
FILE# 4
BLOCK# 152
OFFSET 0
DBA 0x01000098 (16777368 4,152)
FILENAME D:\APP\LVS\ORADATA\LVS\USERS01.DBF
BIFILE bifile.bbd
LISTFILE filelist.txt
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE bbed.log
SPOOL Yes
BBED> map
File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4)
Block: 152 Dba:0x01000098
------------------------------------------------------------
KTB Data Block (Table/Cluster)
struct kcbh, 20 bytes @0
struct ktbbh, 72 bytes @20
struct kdbh, 14 bytes @100
struct kdbt[1], 4 bytes @114
sb2 kdbr[14] @118
ub1 freespace[7475] @146
ub1 rowdata[567] @7621
ub4 tailchk @8188
BBED> p kdbr
sb2 kdbr[0] @118 8050
sb2 kdbr[1] @120 8007
sb2 kdbr[2] @122 7964
sb2 kdbr[3] @124 7923
sb2 kdbr[4] @126 7878
sb2 kdbr[5] @128 7837
sb2 kdbr[6] @130 7796
sb2 kdbr[7] @132 7756
sb2 kdbr[8] @134 7718
sb2 kdbr[9] @136 7675
sb2 kdbr[10] @138 7637
sb2 kdbr[11] @140 7599
sb2 kdbr[12] @142 7560
sb2 kdbr[13] @144 7521
BBED> p *kdbr[0] ##根据查询结果,SMITH在表scott.emp的第一行。因此,print下将offset转到第一行位置。
rowdata[529]
------------
ub1 rowdata[529] @8150 0x2c
BBED> show
FILE# 4
BLOCK# 152
OFFSET 8150
DBA 0x01000098 (16777368 4,152)
FILENAME D:\APP\LVS\ORADATA\LVS\USERS01.DBF
BIFILE bifile.bbd
LISTFILE filelist.txt
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE bbed.log
SPOOL Yes
BBED> x /rnccntnnn ##检查下第一行内容(按指定列数据类型输出)
rowdata[529] @8150
------------
flag@8150: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8151: 0x00
cols@8152: 8
col 0[3] @8153: 7369
col 1[5] @8157: SMITH
col 2[5] @8163: CLERK
col 3[3] @8169: 7902
col 4[7] @8173: 17-DEC-80
col 5[2] @8181: 800
col 6[0] @8184: *NULL*
col 7[2] @8185: 20
BBED> x /r ##检查下第一行内容(十六进制裸数据)
rowdata[529] @8150
------------
flag@8150: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8151: 0x00
cols@8152: 8
col 0[3] @8153: 0xc2 0x4a 0x46
col 1[5] @8157: 0x53 0x4d 0x49 0x54 0x48 ##特别注意:确认要更改的列值。[5]中的5表示此列占用字节数为5,dump中占用offset 8157位置1个字节。实际列值SMITH是从offset 8158开始的。
col 2[5] @8163: 0x43 0x4c 0x45 0x52 0x4b
col 3[3] @8169: 0xc2 0x50 0x03
col 4[7] @8173: 0x77 0xb4 0x0c 0x11 0x01 0x01 0x01
col 5[2] @8181: 0xc2 0x09
col 6[0] @8184: *NULL*
col 7[2] @8185: 0xc1 0x15
BBED> dump /v offset 8157
File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4)
Block: 152 Offsets: 8157 to 8191 Dba:0x01000098
-------------------------------------------------------
05534d49 54480543 4c45524b 03c25003 l .SMITH.CLERK.翽. ##特别注意:05534d49 54480543:实际SMITH字符所在偏移量是从offset 8158开始的,前面偏移量offset 8157位置的05即:col 1[5] @8157: 0x53 0x4d 0x49 0x54 0x48 中的5。
0777b40c 11010101 02c209ff 02c11502 l .w?.....?..?.
0673be l .s?
<16 bytes per line>
BBED> modify /c seven dba 4,152 offset 8158 ##特别注意:更改前,一定一定要先dump offset 8157看下,是不是上面x /r看到的列值。即,一定注意通过dump来精准确认下要更改的列值的起始offset位置。实际SMITH所在位置是从offset 8158开始的。
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4)
Block: 152 Offsets: 8158 to 8191 Dba:0x01000098
------------------------------------------------------------------------
73657665 6e05434c 45524b03 c2500307 77b40c11 01010102 c209ff02 c1150206
73be
<32 bytes per line>
BBED> dump /v offset 8157 ##确认已更改
File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4)
Block: 152 Offsets: 8157 to 8191 Dba:0x01000098
-------------------------------------------------------
05736576 656e0543 4c45524b 03c25003 l .seven.CLERK.翽.
0777b40c 11010101 02c209ff 02c11502 l .w?.....?..?.
0673be l .s?
<16 bytes per line>
SQL> select dump('seven','16') from dual;
DUMP('SEVEN','16')
----------------------------
Typ=96 Len=5: 73,65,76,65,6e
BBED> sum apply ##提交更改记录
Check value for File 4, Block 152:
current = 0xb626, required = 0xb626
BBED> verify ##确认下数据文件是否有坏块
DBVERIFY - Verification starting
FILE = D:\APP\LVS\ORADATA\LVS\USERS01.DBF
BLOCK = 151
DBVERIFY - Verification complete
Total Blocks Examined : 1
Total Blocks Processed (Data) : 1
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
SELECT
dbms_rowid.rowid_object(rowid) DATA_OBJECT_ID,
dbms_rowid.rowid_relative_fno(rowid) REL_FNO,
dbms_rowid.rowid_block_number(rowid) BLOCKNO,
dbms_rowid.rowid_row_number(rowid) ROWNO,
empno, ename
FROM scott.emp;
DATA_OBJECT_ID REL_FNO BLOCKNO ROWNO EMPNO ENAME
-------------- ---------- ---------- ---------- ---------- ----------
87108 4 151 0 7369 SMITH
87108 4 151 1 7499 ALLEN
87108 4 151 2 7521 WARD
87108 4 151 3 7566 JONES
87108 4 151 4 7654 MARTIN
87108 4 151 5 7698 BLAKE
87108 4 151 6 7782 CLARK
87108 4 151 7 7788 SCOTT
87108 4 151 8 7839 KING
87108 4 151 9 7844 TURNER
87108 4 151 10 7876 ADAMS
DATA_OBJECT_ID REL_FNO BLOCKNO ROWNO EMPNO ENAME
-------------- ---------- ---------- ---------- ---------- ----------
87108 4 151 11 7900 JAMES
87108 4 151 12 7902 FORD
87108 4 151 13 7934 MILLER
若显示没有改变,则清空buffer_cache,再物理读下:
alter system flush buffer_cache;
DATA_OBJECT_ID REL_FNO BLOCKNO ROWNO EMPNO ENAME
-------------- ---------- ---------- ---------- ---------- ----------
86893 4 151 0 7369 seven ##确认表数据已更改
86893 4 151 1 7499 ALLEN
86893 4 151 2 7521 WARD
86893 4 151 3 7566 JONES
86893 4 151 4 7654 MARTIN
86893 4 151 5 7698 BLAKE
86893 4 151 6 7782 CLARK
86893 4 151 7 7788 SCOTT
86893 4 151 8 7839 KING
86893 4 151 9 7844 TURNER
86893 4 151 10 7876 ADAMS
DATA_OBJECT_ID REL_FNO BLOCKNO ROWNO EMPNO ENAME
-------------- ---------- ---------- ---------- ---------- ----------
86893 4 151 11 7900 JAMES
86893 4 151 12 7902 FORD
86893 4 151 13 7934 MILLER
已选择14行。
将scott.emp中的seven改为SMITH
手册参考步骤如下:
(Oracle_BBED(block_browse_and_editor)使用手册.pdf P25 Example#1 Changing Data)
##先确认下要更改记录内容所在的REL_FNO及BLOCKNO(即DBA)
SELECT
dbms_rowid.rowid_object(rowid) DATA_OBJECT_ID,
dbms_rowid.rowid_relative_fno(rowid) REL_FNO,
dbms_rowid.rowid_block_number(rowid) BLOCKNO,
dbms_rowid.rowid_row_number(rowid) ROWNO,
empno, ename
FROM scott.emp;
DATA_OBJECT_ID REL_FNO BLOCKNO ROWNO EMPNO ENAME
-------------- ---------- ---------- ---------- ---------- ----------
86893 4 151 0 7369 seven
86893 4 151 1 7499 ALLEN
86893 4 151 2 7521 WARD
86893 4 151 3 7566 JONES
86893 4 151 4 7654 MARTIN
86893 4 151 5 7698 BLAKE
86893 4 151 6 7782 CLARK
86893 4 151 7 7788 SCOTT
86893 4 151 8 7839 KING
86893 4 151 9 7844 TURNER
86893 4 151 10 7876 ADAMS
DATA_OBJECT_ID REL_FNO BLOCKNO ROWNO EMPNO ENAME
-------------- ---------- ---------- ---------- ---------- ----------
86893 4 151 11 7900 JAMES
86893 4 151 12 7902 FORD
86893 4 151 13 7934 MILLER
已选择14行。
D:\bbed>bbed parfile=bbed.txt
BBED: Release 2.0.0.0.0 - Limited Production on Mon Sep 21 17:40:01 2020
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************
BBED> show
FILE# 1
BLOCK# 1
OFFSET 0
DBA 0x00400001 (4194305 1,1)
FILENAME D:\APP\LVS\ORADATA\LVS\SYSTEM01.DBF
BIFILE bifile.bbd
LISTFILE filelist.txt
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE bbed.log
SPOOL Yes
BBED> set dba 4,152
DBA 0x01000098 (16777368 4,152)
BBED> show
FILE# 4
BLOCK# 152
OFFSET 0
DBA 0x01000098 (16777368 4,152)
FILENAME D:\APP\LVS\ORADATA\LVS\USERS01.DBF
BIFILE bifile.bbd
LISTFILE filelist.txt
BLOCKSIZE 8192
MODE Edit
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE bbed.log
SPOOL Yes
BBED> find /c seven ##此方法的好处:使用find命令直接定位要改字符串在当前数据块中的offset位置
File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4)
Block: 152 Offsets: 8158 to 8191 Dba:0x01000098
------------------------------------------------------------------------
73657665 6e05434c 45524b03 c2500307 77b40c11 01010102 c209ff02 c1150206
73be
<32 bytes per line>
BBED> dump /v dba 4,152 offset 8158 count 64 ##find定位后,用dump确认下
File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4)
Block: 152 Offsets: 8158 to 8191 Dba:0x01000098
-------------------------------------------------------
73657665 6e05434c 45524b03 c2500307 l seven.CLERK.翽..
77b40c11 01010102 c209ff02 c1150206 l w?.....?..?..
73be l s?
<16 bytes per line>
再查看seven的裸数据值对比确认下:
select dump('seven',16) from dual;
DUMP('SEVEN',16)
----------------------------
Typ=96 Len=5: 73,65,76,65,6e
BBED> modify /c SMITH dba 4,152 offset 8158 ##确认offset没有问题后,直接对此offset内容进行更改即可
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4)
Block: 152 Offsets: 8158 to 8191 Dba:0x01000098
------------------------------------------------------------------------
534d4954 4805434c 45524b03 c2500307 77b40c11 01010102 c209ff02 c1150206
73be
<32 bytes per line>
BBED> dump /v dba 4,152 offset 8158 count 64 ##更改后再确认下
File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4)
Block: 152 Offsets: 8158 to 8191 Dba:0x01000098
-------------------------------------------------------
534d4954 4805434c 45524b03 c2500307 l SMITH.CLERK.翽..
77b40c11 01010102 c209ff02 c1150206 l w?.....?..?..
73be l s?
<16 bytes per line>
BBED> sum dba 4,152
Check value for File 4, Block 152:
current = 0xb626, required = 0xaf1f
BBED> sum dba 4,152 apply ##提交更改记录(更改数据块内容后,执行sum命令会生成新的校验和,sum apply将新校验和写入数据块并生效。)
Check value for File 4, Block 152:
current = 0xaf1f, required = 0xaf1f
数据块校验下:
BBED> v
DBVERIFY - Verification starting
FILE = /oracle/oradata/orcl/users01.dbf
BLOCK = 151
DBVERIFY - Verification complete
Total Blocks Examined : 1
Total Blocks Processed (Data) : 1
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
##查询下表记录是否已更改
SELECT
dbms_rowid.rowid_object(rowid) DATA_OBJECT_ID,
dbms_rowid.rowid_relative_fno(rowid) REL_FNO,
dbms_rowid.rowid_block_number(rowid) BLOCKNO,
dbms_rowid.rowid_row_number(rowid) ROWNO,
empno, ename
FROM scott.emp;
DATA_OBJECT_ID REL_FNO BLOCKNO ROWNO EMPNO ENAME
-------------- ---------- ---------- ---------- ---------- ----------
86893 4 151 0 7369 seven
86893 4 151 1 7499 ALLEN
86893 4 151 2 7521 WARD
86893 4 151 3 7566 JONES
86893 4 151 4 7654 MARTIN
86893 4 151 5 7698 BLAKE
86893 4 151 6 7782 CLARK
86893 4 151 7 7788 SCOTT
86893 4 151 8 7839 KING
86893 4 151 9 7844 TURNER
86893 4 151 10 7876 ADAMS
DATA_OBJECT_ID REL_FNO BLOCKNO ROWNO EMPNO ENAME
-------------- ---------- ---------- ---------- ---------- ----------
86893 4 151 11 7900 JAMES
86893 4 151 12 7902 FORD
86893 4 151 13 7934 MILLER
已选择14行。
SQL> alter system flush buffer_cache;
##读的还是buffer_cache未更改的内容,清理下buffer_cache,让接下来的查询走物理读磁盘
##也可以执行检查点:alter system checkpoint;
SELECT
dbms_rowid.rowid_object(rowid) DATA_OBJECT_ID,
dbms_rowid.rowid_relative_fno(rowid) REL_FNO,
dbms_rowid.rowid_block_number(rowid) BLOCKNO,
dbms_rowid.rowid_row_number(rowid) ROWNO,
empno, ename
FROM scott.emp;
DATA_OBJECT_ID REL_FNO BLOCKNO ROWNO EMPNO ENAME
-------------- ---------- ---------- ---------- ---------- ----------
86893 4 151 0 7369 SMITH ##确认表记录已更改
86893 4 151 1 7499 ALLEN
86893 4 151 2 7521 WARD
86893 4 151 3 7566 JONES
86893 4 151 4 7654 MARTIN
86893 4 151 5 7698 BLAKE
86893 4 151 6 7782 CLARK
86893 4 151 7 7788 SCOTT
86893 4 151 8 7839 KING
86893 4 151 9 7844 TURNER
86893 4 151 10 7876 ADAMS
DATA_OBJECT_ID REL_FNO BLOCKNO ROWNO EMPNO ENAME
-------------- ---------- ---------- ---------- ---------- ----------
86893 4 151 11 7900 JAMES
86893 4 151 12 7902 FORD
86893 4 151 13 7934 MILLER
已选择14行。
2.4.12 assign
Assign命令执行符号分配,并进行类型和范围检查。 当前偏移量可以省略目标或源。 例如,以下命令将当前偏移量的结构分配给文件4,块2的第一个ITL条目
BBED> assign dba 4,2 ktbbhitl[0]
2.4.13 sum
sum命令检查数据块的校验和,若需使更改生效,使用sum apply命令。 更改数据块内容后,执行sum命令会生成新的校验和,sum apply将新校验和写入数据块并生效。
BBED> sum dba 4,152 Check value for File 1, Block 115362: current = 0xe5fb, required = 0xe5fb BBED> sum dba 4,152 apply
2.4.14 push / pop
push 和 pop 命令用于将文件、块和偏移位置推送到内存支持的堆栈上,然后将它们弹出回来。
这允许在检查或修改另一个位置时临时保存正在编辑的当前位置。
请注意,堆栈仅存储位置 - 它不会保存内容。
以下示例显示了正在检查的文件 7,块 16,偏移量 8163。该位置使用 push 命令保存。然后,我们移动到文件 6,块 1,然后使用 pop 命令转到 DBA 7,16。
BBED> push dba 7,16 DBA 0x01c00010 (29360144 7,16) OFFSET 8163 BBED> set dba 6,1 DBA 0x01800001 (25165825 6,1) BBED> pop DBA 0x01c00010 (29360144 7,16) OFFSET 8163
The command pop all can be used to remove all push'd entries from the stack. The command show all can be used to show all saved locations.
2.4.15 revert
The revert command is used to restore a file, filename, block or DBA to it's original state when bbed was started. revert是恢复自bbed 启动以来的所有修改。
2.4.16 undo
The undo command rolls back the last modify or assign command. If the undo command is issued again the modification is re-done. undo命令是回滚最后一次的操作。
2.4.17 verify (v)
verify命令用来验证block的完整性。与dbv工具作用类似。
2.4.18 corrupt
corrupt命令将一个block 标记为corrupt,这样db 在操作时就会跳过该block,从而避免错误。
BBED> corrupt dba 6,15 Block marked media corrupt
Note: The undo command does not undo a corruption. The revert command however does. 注意:undo命令不能undo一个corruption,但是revert 命令却可以。
2.5 Examples
2.5.1 恢复已删除的行
以下示例演示如何反删除已删除的行。
在oracle中删除行时,实际上没有真正删除数据。该行仅标记为已删除,对可用空间计数器和指针进行了相应的调整。 行的状态存储在行头中,行头占据每行的前一个字节。
BBED> p *kdbr[0] rowdata[529] ------------ ub1 rowdata[529] @8150 0x2c BBED> x /r rowdata[529] @8150 ------------ flag@8150: 0x2c (KDRHFL, KDRHFF, KDRHFH) lock@8151: 0x00 cols@8152: 8 col 0[3] @8153: 0xc2 0x4a 0x46 col 1[5] @8157: 0x53 0x4d 0x49 0x54 0x48 col 2[5] @8163: 0x43 0x4c 0x45 0x52 0x4b col 3[3] @8169: 0xc2 0x50 0x03 col 4[7] @8173: 0x77 0xb4 0x0c 0x11 0x01 0x01 0x01 col 5[2] @8181: 0xc2 0x09 col 6[0] @8184: *NULL* col 7[2] @8185: 0xc1 0x15 BBED> dump /v count 128 File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4) Block: 152 Offsets: 8150 to 8191 Dba:0x01000098 ------------------------------------------------------- 2c000803 c24a4605 534d4954 4805434c l ,...翵F.SMITH.CL 45524b03 c2500307 77b40c11 01010102 l ERK.翽..w?..... c209ff02 c1150206 73be l ?..?..s? <16 bytes per line>
The Row Header consists of the Row Flag, Lock Byte (ITL entry) and Column Count. The first of these the Row Flag— is a single byte that holds a bitmask that shows the status ofthe row. The bitmask is decoded as follows: 行头由行标志、锁定字节(ITL条目)和列计数组成。其中,行标志是一个字节,其中包含一个位掩码,用于显示行的状态。 位掩码解码如下:
ClusterKey ClusterTableMember Head of row piece Deleted First data Piece Last data piece 1st Column continues from previous piece Last column continues in next piece 128 64 32 16 8 4 2 1
Therefore, columns that fit within a single block, are not chained, migrated or part of a clustered table and are not deleted will have the following attributes: 因此,位于单个块内的列,若没有行链接及行迁移,或是簇表的一部分,并没有被删除,则具有如下属性:
·Head of Row Piece ·First Data Piece ·Last Data Piece
Therefore the Row Flag is 32 + 8 +4 = 44 or Ox2c. If this is dumped, using the alter system dump datafile N block Y command, this pattern is represented as --H-FL--. E.g.:
block_row_dump: tab 0, row 0, @0x1f72 tl: 38 fb: --H-FL-- lb: 0x0 cc: 8 col 0: [ 3] c2 4a 46 col 1: [ 5] 53 4d 49 54 48 col 2: [ 5] 43 4c 45 52 4b col 3: [ 3] c2 50 03 col 4: [ 7] 77 b4 0c 11 01 01 01 col 5: [ 2] c2 09 col 6: *NULL* col 7: [ 2] c1 15
When a row is deleted the Row Flag is updated and bit 16 is set high. This means that for a typical row the flag value is now 32 + 16 +8+ 4 = 60 or Ox3c. In the following example we delete the record for RichardNixon from our table. Then using the bbed find command, we locate the deleted row and dump the contents of the block: 当某一行被删除时,行标志被更新,此时行标志为32 + 16 +8+ 4 = 60 即Ox3c。
SQL> select * from scott.test; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- -------------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 17-12月-80 800 20 7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30 7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30 7566 JONES MANAGER 7839 02-4月 -81 2975 20 7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30 7698 BLAKE MANAGER 7839 01-5月 -81 2850 30 7782 CLARK MANAGER 7839 09-6月 -81 2450 10 7788 SCOTT ANALYST 7566 19-4月 -87 3000 20 7839 KING PRESIDENT 17-11月-81 5000 10 7844 TURNER SALESMAN 7698 08-9月 -81 1500 0 30 7876 ADAMS CLERK 7788 23-5月 -87 1100 20 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- -------------- ---------- ---------- ---------- 7900 JAMES CLERK 7698 03-12月-81 950 30 7902 FORD ANALYST 7566 03-12月-81 3000 20 7934 MILLER CLERK 7782 23-1月 -82 5500 10 已选择14行。 SQL> SQL> delete from scott.test where ename='ALLEN'; 已删除 1 行。 SQL> commit; 提交完成。 SQL> select * from scott.test; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- -------------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 17-12月-80 800 20 7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30 7566 JONES MANAGER 7839 02-4月 -81 2975 20 7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30 7698 BLAKE MANAGER 7839 01-5月 -81 2850 30 7782 CLARK MANAGER 7839 09-6月 -81 2450 10 7788 SCOTT ANALYST 7566 19-4月 -87 3000 20 7839 KING PRESIDENT 17-11月-81 5000 10 7844 TURNER SALESMAN 7698 08-9月 -81 1500 0 30 7876 ADAMS CLERK 7788 23-5月 -87 1100 20 7900 JAMES CLERK 7698 03-12月-81 950 30 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- -------------- ---------- ---------- ---------- 7902 FORD ANALYST 7566 03-12月-81 3000 20 7934 MILLER CLERK 7782 23-1月 -82 5500 10 已选择13行。 SQL> SELECT 2 dbms_rowid.rowid_object(rowid) DATA_OBJECT_ID, 3 dbms_rowid.rowid_relative_fno(rowid) REL_FNO, 4 dbms_rowid.rowid_block_number(rowid) BLOCKNO, 5 dbms_rowid.rowid_row_number(rowid) ROWNO, 6 empno, ename 7 FROM scott.test; DATA_OBJECT_ID REL_FNO BLOCKNO ROWNO EMPNO ENAME -------------- ---------- ---------- ---------- ---------- ---------- 87152 4 179 0 7369 SMITH 87152 4 179 2 7521 WARD 87152 4 179 3 7566 JONES 87152 4 179 4 7654 MARTIN 87152 4 179 5 7698 BLAKE 87152 4 179 6 7782 CLARK 87152 4 179 7 7788 SCOTT 87152 4 179 8 7839 KING 87152 4 179 9 7844 TURNER 87152 4 179 10 7876 ADAMS 87152 4 179 11 7900 JAMES DATA_OBJECT_ID REL_FNO BLOCKNO ROWNO EMPNO ENAME -------------- ---------- ---------- ---------- ---------- ---------- 87152 4 179 12 7902 FORD 87152 4 179 13 7934 MILLER 已选择13行。 SQL> alter system checkpoint; 系统已更改。 BBED: Release 2.0.0.0.0 - Limited Production on Mon Sep 21 21:01:53 2020 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. ************* !!! For Oracle Internal Use only !!! *************** BBED> show FILE# 1 BLOCK# 1 OFFSET 0 DBA 0x00400001 (4194305 1,1) FILENAME D:\APP\LVS\ORADATA\LVS\SYSTEM01.DBF BIFILE bifile.bbd LISTFILE filelist.txt BLOCKSIZE 8192 MODE Edit EDIT Unrecoverable IBASE Dec OBASE Dec WIDTH 80 COUNT 512 LOGFILE bbed.log SPOOL Yes BBED> set dba 4,180 DBA 0x010000b4 (16777396 4,180) BBED> show FILE# 4 BLOCK# 180 OFFSET 0 DBA 0x010000b4 (16777396 4,180) FILENAME D:\APP\LVS\ORADATA\LVS\USERS01.DBF BIFILE bifile.bbd LISTFILE filelist.txt BLOCKSIZE 8192 MODE Edit EDIT Unrecoverable IBASE Dec OBASE Dec WIDTH 80 COUNT 512 LOGFILE bbed.log SPOOL Yes BBED> p *kdbr[1] rowdata[486] ------------ ub1 rowdata[486] @8107 0x3c BBED> dump /v File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4) Block: 180 Offsets: 8107 to 8191 Dba:0x010000b4 ------------------------------------------------------- 3c020803 c24b6405 414c4c45 4e085341 l <...翶d.ALLEN.SA 4c45534d 414e03c2 4d630777 b5021401 l LESMAN.翸c.w?.. 010102c2 1102c204 02c11f2c 000803c2 l ...?.?.?,...? 4a460553 4d495448 05434c45 524b03c2 l JF.SMITH.CLERK.? 50030777 b40c1101 010102c2 09ff02c1 l P..w?.....?..? 1501060c 0b l ..... <16 bytes per line> BBED> modify /x 2c dba 4,180 offset 8107 Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y #modify /x 3C filename 'D:\APP\LVS\ORADATA\LVS\USERS01.DBF' block 180. offset 8107. File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4) Block: 180 Offsets: 8107 to 8191 Dba:0x010000b4 ------------------------------------------------------------------------ 2c020803 c24b6405 414c4c45 4e085341 4c45534d 414e03c2 4d630777 b5021401 010102c2 1102c204 02c11f2c 000803c2 4a460553 4d495448 05434c45 524b03c2 50030777 b40c1101 010102c2 09ff02c1 1501060c 0b <32 bytes per line> BBED> dump /v File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4) Block: 180 Offsets: 8107 to 8191 Dba:0x010000b4 ------------------------------------------------------- 2c020803 c24b6405 414c4c45 4e085341 l ,...翶d.ALLEN.SA 4c45534d 414e03c2 4d630777 b5021401 l LESMAN.翸c.w?.. 010102c2 1102c204 02c11f2c 000803c2 l ...?.?.?,...? 4a460553 4d495448 05434c45 524b03c2 l JF.SMITH.CLERK.? 50030777 b40c1101 010102c2 09ff02c1 l P..w?.....?..? 1501060c 0b l ..... <16 bytes per line> BBED> sum apply Check value for File 4, Block 180: current = 0xbc53, required = 0xbc53 BBED> verify DBVERIFY - Verification starting FILE = D:\APP\LVS\ORADATA\LVS\USERS01.DBF BLOCK = 179 Block Checking: DBA = 16777395, Block Type = KTB-managed data block data header at 0x266027c kdbchk: the amount of space used is not equal to block size ##特别注意:校验报错,都是因为执行bbed时数据库是打开的。使用bbed时应该关闭数据库的情况下再执行修改命令。 used=613 fsc=41 avsp=7451 dtl=8064 Block 179 failed with check code 6110 DBVERIFY - Verification complete Total Blocks Examined : 1 Total Blocks Processed (Data) : 1 Total Blocks Failing (Data) : 1 Total Blocks Processed (Index): 0 Total Blocks Failing (Index): 0 Total Blocks Empty : 0 Total Blocks Marked Corrupt : 0 Total Blocks Influx : 0 ##接下来要解决上面报错,参考:kdbchk the amount of space used is not equal to block size.txt BBED> show FILE# 4 BLOCK# 180 OFFSET 8107 DBA 0x010000b4 (16777396 4,180) FILENAME D:\APP\LVS\ORADATA\LVS\USERS01.DBF BIFILE bifile.bbd LISTFILE filelist.txt BLOCKSIZE 8192 MODE Edit EDIT Unrecoverable IBASE Dec OBASE Dec WIDTH 80 COUNT 512 LOGFILE bbed.log SPOOL Yes BBED> p kdbh struct kdbh, 14 bytes @124 ub1 kdbhflag @124 0x00 (NONE) b1 kdbhntab @125 1 b2 kdbhnrow @126 14 sb2 kdbhfrre @128 -1 sb2 kdbhfsbo @130 46 sb2 kdbhfseo @132 7497 b2 kdbhavsp @134 7451 b2 kdbhtosp @136 7494 BBED> p ktbbhitl struct ktbbhitl[0], 24 bytes @44 struct ktbitxid, 8 bytes @44 ub2 kxidusn @44 0xffff ub2 kxidslt @46 0x0000 ub4 kxidsqn @48 0x00000000 struct ktbituba, 8 bytes @52 ub4 kubadba @52 0x00000000 ub2 kubaseq @56 0x0000 ub1 kubarec @58 0x00 ub2 ktbitflg @60 0x8000 (KTBFCOM) union _ktbitun, 2 bytes @62 b2 _ktbitfsc @62 0 ub2 _ktbitwrp @62 0x0000 ub4 ktbitbas @64 0x000f9365 struct ktbbhitl[1], 24 bytes @68 struct ktbitxid, 8 bytes @68 ub2 kxidusn @68 0x0005 ub2 kxidslt @70 0x0005 ub4 kxidsqn @72 0x00000395 struct ktbituba, 8 bytes @76 ub4 kubadba @76 0x00c01e72 ub2 kubaseq @80 0x00b8 ub1 kubarec @82 0x28 ub2 ktbitflg @84 0x2001 (KTBFUPB) union _ktbitun, 2 bytes @86 b2 _ktbitfsc @86 41 ub2 _ktbitwrp @86 0x0029 ub4 ktbitbas @88 0x00100b0c struct ktbbhitl[2], 24 bytes @92 struct ktbitxid, 8 bytes @92 ub2 kxidusn @92 0x0000 ub2 kxidslt @94 0x0000 ub4 kxidsqn @96 0x00000000 struct ktbituba, 8 bytes @100 ub4 kubadba @100 0x00000000 ub2 kubaseq @104 0x0000 ub1 kubarec @106 0x00 ub2 ktbitflg @108 0x0000 (NONE) union _ktbitun, 2 bytes @110 b2 _ktbitfsc @110 0 ub2 _ktbitwrp @110 0x0000 ub4 ktbitbas @112 0x00000000 BBED> dump /v dba 4,180 offset 86 count 32 File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4) Block: 180 Offsets: 86 to 117 Dba:0x010000b4 ------------------------------------------------------- 29000c0b 10000000 00000000 00000000 l )............... 00000000 00000000 00000000 00000000 l ................ <16 bytes per line> BBED> modify /x 00 dba 4,180 offset 86 ##将所有ktbitfsc值改为00 #modify /x 29 filename 'D:\APP\LVS\ORADATA\LVS\USERS01.DBF' block 180. offset 86. File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4) Block: 180 Offsets: 86 to 117 Dba:0x010000b4 ------------------------------------------------------------------------ 00000c0b 10000000 00000000 00000000 00000000 00000000 00000000 00000000 <32 bytes per line> BBED> p ktbbhitl struct ktbbhitl[0], 24 bytes @44 struct ktbitxid, 8 bytes @44 ub2 kxidusn @44 0xffff ub2 kxidslt @46 0x0000 ub4 kxidsqn @48 0x00000000 struct ktbituba, 8 bytes @52 ub4 kubadba @52 0x00000000 ub2 kubaseq @56 0x0000 ub1 kubarec @58 0x00 ub2 ktbitflg @60 0x8000 (KTBFCOM) union _ktbitun, 2 bytes @62 b2 _ktbitfsc @62 0 ub2 _ktbitwrp @62 0x0000 ub4 ktbitbas @64 0x000f9365 struct ktbbhitl[1], 24 bytes @68 struct ktbitxid, 8 bytes @68 ub2 kxidusn @68 0x0005 ub2 kxidslt @70 0x0005 ub4 kxidsqn @72 0x00000395 struct ktbituba, 8 bytes @76 ub4 kubadba @76 0x00c01e72 ub2 kubaseq @80 0x00b8 ub1 kubarec @82 0x28 ub2 ktbitflg @84 0x2001 (KTBFUPB) union _ktbitun, 2 bytes @86 b2 _ktbitfsc @86 0 ub2 _ktbitwrp @86 0x0000 ub4 ktbitbas @88 0x00100b0c struct ktbbhitl[2], 24 bytes @92 struct ktbitxid, 8 bytes @92 ub2 kxidusn @92 0x0000 ub2 kxidslt @94 0x0000 ub4 kxidsqn @96 0x00000000 struct ktbituba, 8 bytes @100 ub4 kubadba @100 0x00000000 ub2 kubaseq @104 0x0000 ub1 kubarec @106 0x00 ub2 ktbitflg @108 0x0000 (NONE) union _ktbitun, 2 bytes @110 b2 _ktbitfsc @110 0 ub2 _ktbitwrp @110 0x0000 ub4 ktbitbas @112 0x00000000 BBED> sum Check value for File 4, Block 180: current = 0xbc53, required = 0xbc7a BBED> sum apply Check value for File 4, Block 180: current = 0xbc7a, required = 0xbc7a BBED> p kdbh struct kdbh, 14 bytes @124 ub1 kdbhflag @124 0x00 (NONE) b1 kdbhntab @125 1 b2 kdbhnrow @126 14 sb2 kdbhfrre @128 -1 sb2 kdbhfsbo @130 46 sb2 kdbhfseo @132 7497 b2 kdbhavsp @134 7451 b2 kdbhtosp @136 7494 将kdbhavsp和kdbhtosp都改为:dtl(=8064)-used(=613)=7451 select to_char(7451,'XXXX') HEX from dual; ##7451十六进制为1D1B,转储后为1B1D HEX ----- 1D1B BBED> modify /x 1B1D dba 4,180 offset 134 #modify /x 1B1D filename 'D:\APP\LVS\ORADATA\LVS\USERS01.DBF' block 180. offset 134. File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4) Block: 180 Offsets: 134 to 165 Dba:0x010000b4 ------------------------------------------------------------------------ 1b1d461d 00000e00 5a1f2f1f 041fdb1e ae1e851e 5c1e341e 0e1ee31d bd1d971d <32 bytes per line> BBED> verify DBVERIFY - Verification starting FILE = D:\APP\LVS\ORADATA\LVS\USERS01.DBF BLOCK = 179 Block Checking: DBA = 16777395, Block Type = KTB-managed data block data header at 0x266027c kdbchk: the amount of space used is not equal to block size used=613 fsc=41 avsp=7451 dtl=8064 Block 179 failed with check code 6110 BBED> modify /x 1B1D dba 4,180 offset 136 #modify /x 461D filename 'D:\APP\LVS\ORADATA\LVS\USERS01.DBF' block 180. offset 136. File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4) Block: 180 Offsets: 136 to 167 Dba:0x010000b4 ------------------------------------------------------------------------ 1b1d0000 0e005a1f 2f1f041f db1eae1e 851e5c1e 341e0e1e e31dbd1d 971d701d <32 bytes per line> BBED> sum apply Check value for File 4, Block 180: current = 0xbc27, required = 0xbc27 BBED> verify DBVERIFY - Verification starting FILE = D:\APP\LVS\ORADATA\LVS\USERS01.DBF BLOCK = 179 DBVERIFY - Verification complete Total Blocks Examined : 1 Total Blocks Processed (Data) : 1 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 ##报错已解决 SQL> select * from scott.test; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- -------------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 17-12月-80 800 20 7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30 7566 JONES MANAGER 7839 02-4月 -81 2975 20 7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30 7698 BLAKE MANAGER 7839 01-5月 -81 2850 30 7782 CLARK MANAGER 7839 09-6月 -81 2450 10 7788 SCOTT ANALYST 7566 19-4月 -87 3000 20 7839 KING PRESIDENT 17-11月-81 5000 10 7844 TURNER SALESMAN 7698 08-9月 -81 1500 0 30 7876 ADAMS CLERK 7788 23-5月 -87 1100 20 7900 JAMES CLERK 7698 03-12月-81 950 30 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- -------------- ---------- ---------- ---------- 7902 FORD ANALYST 7566 03-12月-81 3000 20 7934 MILLER CLERK 7782 23-1月 -82 5500 10 已选择13行。 SQL> alter system flush buffer_cache; 系统已更改。 SQL> select * from scott.test; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- -------------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 17-12月-80 800 20 7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30 ##删除行已恢复 7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30 7566 JONES MANAGER 7839 02-4月 -81 2975 20 7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30 7698 BLAKE MANAGER 7839 01-5月 -81 2850 30 7782 CLARK MANAGER 7839 09-6月 -81 2450 10 7788 SCOTT ANALYST 7566 19-4月 -87 3000 20 7839 KING PRESIDENT 17-11月-81 5000 10 7844 TURNER SALESMAN 7698 08-9月 -81 1500 0 30 7876 ADAMS CLERK 7788 23-5月 -87 1100 20 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- -------------- ---------- ---------- ---------- 7900 JAMES CLERK 7698 03-12月-81 950 30 7902 FORD ANALYST 7566 03-12月-81 3000 20 7934 MILLER CLERK 7782 23-1月 -82 5500 10 已选择14行。
2.5.2 重置块损坏标记(Uncorrupting a Block)
下面例子显示用bbed重置块损坏标记。
尽管现在oracle官方提供了DBMS_REPAIR程序包来修复损坏快,但下面例子仍是显示bbed强大能力的例证。
下面的 Oracle 错误显示遇到了损坏的数据:
SQL> select * from scott.test; select * from scott.test ERROR at line 1: ORA-01578: ORACLE data block corrupted (file # 4, block # 179) ORA-01110: data file 4 : 'D:\APP\LVS\ORADATA\LVS\USERS01.DBF'
当Oracle确定数据块已损坏时,它通过将块序列号设置为0xff将其标记为损坏。 可通过kcbh结构的seq_kcbh属性来看:
BBED> set dba 4,180 BBED> p kcbh struct kcbh, 20 bytes @0 ub1 type_kcbh @0 0x06 ub1 frmt_kcbh @1 0xa2 ub1 spare1_kcbh @2 0x00 ub1 spare2_kcbh @3 0x00 ub4 rdba_kcbh @4 0x010000b3 ub4 bas_kcbh @8 0x00100b0c ub2 wrp_kcbh @12 0x0000 ub1 seq_kcbh @14 0xff ub1 flg_kcbh @15 0x06 (KCBHFDLC, KCBHFCKV) ub2 chkval_kcbh @16 0xbc27 ub2 spare3_kcbh @18 0x0000
因此,要重置损坏标记,我们需要将块序列号设置为0xff外的其他值。序列号存储在偏移量14位置。
The following shows the sequence number being reset to 0x01.
BBED> p seq_kcbh ub1 seq_kcbh @14 0xff BBED> dump /v count 1 File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4) Block: 180 Offsets: 14 to 14 Dba:0x010000b4 ------------------------------------------------------- ff l . <16 bytes per line> BBED> modify /x 01 dba 4,180 offset 14 ##更改块头(seq_kcbh)的scn值
序列号还作为块尾检查内容的一部分,块尾检查占用8个字节。也需要将块尾检查内容进行重组,以便oracle重新识别该块为有效块。
print看下块尾检查内容为0x000006ff。 但是,当我们重置它时,必须记住这个值被解释作为一个单个无符号整数。 在英特尔架构的机器上,此值以低位字节优先存储(即,DUMP数据低位在左),因为该处理器使用的是低位优先架构。
BBED> p tailchk ub4 tailchk @8188 0x0b0c06ff BBED> modify /x 01060c0b dba 4,180 offset 8188 ##更改块尾检查(tailchk)处的seq值 BBED> sum dba 4,180 apply
修复完成,此时表数据可正常访问了。
SQL> select * from scott.test;
注意: 本示例中,我们仅仅重置了块损坏标记,并没有解决块损坏的根本原因。 如果存在导致块损坏的问题,要在oracle重新读此数据块前先解决此问题,否则该块还将被标记为坏块。
2.5.3 重置数据文件的文件头块
下面示例显示如何使用bbed手动重置数据文件的文件头块,以便可以打开数据库。 这对于数据库处于未归档模式时遇到数据库故障的客户很有用。 如果一些数据文件没有保留在备份中,而必须从较旧的备份中还原时,也很有用。
以下信息告诉我们,有文件需要恢复:
SQL> startup ORACLE 例程已经启动。 Total System Global Area 313159680 bytes Fixed Size 2280816 bytes Variable Size 180355728 bytes Database Buffers 125829120 bytes Redo Buffers 4694016 bytes 数据库装载完毕。 ORA-01113: 文件 4 需要介质恢复 ORA-01110: 数据文件 4: 'D:\APP\LVS\ORADATA\LVS\USERS01.DBF'
The first thing we need to do is to obtain the current change number of the database from the control files and the change number in the file that needs recovery. 首先要从控制文件中获取数据库当前的系统改变号和需恢复数据文件的系统改变号。
The following obtains the change number from thecontrol file: 从控制文件中获取数据库当前的系统改变号
select file#,name,checkpoint_change# from v$datafile; FILE# NAME CHECKPOINT_CHANGE# ---------- ----------------------------------- ------------------ 1 /oracle/oradata/orcl/system01.dbf 1086565 2 /oracle/oradata/orcl/sysaux01.dbf 1086565 3 /oracle/oradata/orcl/undotbs01.dbf 1086565 5 /oracle/oradata/orcl/example01.dbf 1086565
我们看到数据库的系统改变号为1075149。再从V$RECOVER_FILE视图获取需恢复文件的系统改变号:
select file#,change# from v$recover_file; FILE# CHANGE# ------- ---------- 4 1086110
文件头存储在数据文件的第一个块中。我们可使用bbed检查并显示块结构。
头块包含单个数据结构kcvfh。
当检查一个数据文件是否与数据库中的其他数据文件同步时,oracle考虑此数据结构的四个属性:
·kscnbas (at offset 484) — SCN of last change to the dataflle. ·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 1 less than the checkpoint point count.
BBED> set dba 4,2 offset 0 ##windows文件头块为block 2,linux为block 1
DBA 0x01000002 (16777218 4,2)
OFFSET 0
BBED> map
File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4)
Block: 2 Dba:0x01000002
------------------------------------------------------------
Data File Header
struct kcvfh, 360 bytes @0
ub4 tailchk @8188
BBED> p kcvfh
struct kcvfh, 360 bytes @0
struct kcvfhbfh, 20 bytes @0
ub1 type_kcbh @0 0x0b
ub1 frmt_kcbh @1 0xa2
ub1 spare1_kcbh @2 0x00
ub1 spare2_kcbh @3 0x00
ub4 rdba_kcbh @4 0x01000001
ub4 bas_kcbh @8 0x00000000
ub2 wrp_kcbh @12 0x0000
ub1 seq_kcbh @14 0x01
ub1 flg_kcbh @15 0x04 (KCBHFCKV)
ub2 chkval_kcbh @16 0xd26c
ub2 spare3_kcbh @18 0x0000
struct kcvfhhdr, 76 bytes @20
ub4 kccfhswv @20 0x00000000
ub4 kccfhcvn @24 0x0b200400
ub4 kccfhdbi @28 0xf7cf6d9f
text kccfhdbn[0] @32 L
text kccfhdbn[1] @33 V
text kccfhdbn[2] @34 S
text kccfhdbn[3] @35
text kccfhdbn[4] @36
text kccfhdbn[5] @37
text kccfhdbn[6] @38
text kccfhdbn[7] @39
ub4 kccfhcsq @40 0x00000a55
ub4 kccfhfsz @44 0x00000280
s_blkz kccfhbsz @48 0x00
ub2 kccfhfno @52 0x0004
ub2 kccfhtyp @54 0x0003
ub4 kccfhacid @56 0x00000000
ub4 kccfhcks @60 0x00000000
text kccfhtag[0] @64
text kccfhtag[1] @65
text kccfhtag[2] @66
text kccfhtag[3] @67
text kccfhtag[4] @68
text kccfhtag[5] @69
text kccfhtag[6] @70
text kccfhtag[7] @71
text kccfhtag[8] @72
text kccfhtag[9] @73
text kccfhtag[10] @74
text kccfhtag[11] @75
text kccfhtag[12] @76
text kccfhtag[13] @77
text kccfhtag[14] @78
text kccfhtag[15] @79
text kccfhtag[16] @80
text kccfhtag[17] @81
text kccfhtag[18] @82
text kccfhtag[19] @83
text kccfhtag[20] @84
text kccfhtag[21] @85
text kccfhtag[22] @86
text kccfhtag[23] @87
text kccfhtag[24] @88
text kccfhtag[25] @89
text kccfhtag[26] @90
text kccfhtag[27] @91
text kccfhtag[28] @92
text kccfhtag[29] @93
text kccfhtag[30] @94
text kccfhtag[31] @95
ub4 kcvfhrdb @96 0x00000000
struct kcvfhcrs, 8 bytes @100
ub4 kscnbas @100 0x00003e67
ub2 kscnwrp @104 0x0000
ub4 kcvfhcrt @108 0x31601f39
ub4 kcvfhrlc @112 0x3eabda63
struct kcvfhrls, 8 bytes @116
ub4 kscnbas @116 0x000db064
ub2 kscnwrp @120 0x0000
ub4 kcvfhbti @124 0x00000000
struct kcvfhbsc, 8 bytes @128
ub4 kscnbas @128 0x00000000
ub2 kscnwrp @132 0x0000
ub2 kcvfhbth @136 0x0000
ub2 kcvfhsta @138 0x0000 (NONE)
struct kcvfhckp, 36 bytes @140 ##前两个值
struct kcvcpscn, 8 bytes @140
ub4 kscnbas @140 0x000001de ##第一个
ub2 kscnwrp @144 0x40e7
ub4 kcvcptim @148 0x000001dd ##第二个
ub2 kcvcpthr @152 0x0000
union u, 12 bytes @156
struct kcvcprba, 12 bytes @156
ub4 kcrbaseq @156 0x00000000
ub4 kcrbabno @160 0x00000000
ub2 kcrbabof @164 0x0000
struct kcvcptr, 12 bytes @156
struct kcrtrscn, 8 bytes @156
ub4 kscnbas @156 0x00000000
ub2 kscnwrp @160 0x0000
ub4 kcrtrtim @164 0x00000000
ub1 kcvcpetb[0] @168 0x00
ub1 kcvcpetb[1] @169 0x00
ub1 kcvcpetb[2] @170 0x00
ub1 kcvcpetb[3] @171 0x00
ub1 kcvcpetb[4] @172 0x00
ub1 kcvcpetb[5] @173 0x00
ub1 kcvcpetb[6] @174 0x00
ub1 kcvcpetb[7] @175 0x00
ub4 kcvfhcpc @176 0x00000000 ##第三个
ub4 kcvfhrts @180 0x00000000
ub4 kcvfhccc @184 0x00000000 ##第四个
struct kcvfhbcp, 36 bytes @188
struct kcvcpscn, 8 bytes @188
ub4 kscnbas @188 0x00000000
ub2 kscnwrp @192 0x0000
ub4 kcvcptim @196 0x00000000
ub2 kcvcpthr @200 0x0000
union u, 12 bytes @204
struct kcvcprba, 12 bytes @204
ub4 kcrbaseq @204 0x00000000
ub4 kcrbabno @208 0x00000000
ub2 kcrbabof @212 0x0000
struct kcvcptr, 12 bytes @204
struct kcrtrscn, 8 bytes @204
ub4 kscnbas @204 0x00000000
ub2 kscnwrp @208 0x0000
ub4 kcrtrtim @212 0x00000000
ub1 kcvcpetb[0] @216 0x00
ub1 kcvcpetb[1] @217 0x00
ub1 kcvcpetb[2] @218 0x00
ub1 kcvcpetb[3] @219 0x00
ub1 kcvcpetb[4] @220 0x00
ub1 kcvcpetb[5] @221 0x00
ub1 kcvcpetb[6] @222 0x00
ub1 kcvcpetb[7] @223 0x00
ub4 kcvfhbhz @224 0x00000000
struct kcvfhxcd, 16 bytes @228
ub4 space_kcvmxcd[0] @228 0x00000000
ub4 space_kcvmxcd[1] @232 0x00000000
ub4 space_kcvmxcd[2] @236 0x00000000
ub4 space_kcvmxcd[3] @240 0x00000000
word kcvfhtsn @244 0
ub2 kcvfhtln @248 0x0000
text kcvfhtnm[0] @250
text kcvfhtnm[1] @251
text kcvfhtnm[2] @252
text kcvfhtnm[3] @253
text kcvfhtnm[4] @254
text kcvfhtnm[5] @255
text kcvfhtnm[6] @256
text kcvfhtnm[7] @257
text kcvfhtnm[8] @258
text kcvfhtnm[9] @259
text kcvfhtnm[10] @260
text kcvfhtnm[11] @261
text kcvfhtnm[12] @262
text kcvfhtnm[13] @263
text kcvfhtnm[14] @264
text kcvfhtnm[15] @265
text kcvfhtnm[16] @266
text kcvfhtnm[17] @267
text kcvfhtnm[18] @268
text kcvfhtnm[19] @269
text kcvfhtnm[20] @270
text kcvfhtnm[21] @271
text kcvfhtnm[22] @272
text kcvfhtnm[23] @273
text kcvfhtnm[24] @274
text kcvfhtnm[25] @275
text kcvfhtnm[26] @276
text kcvfhtnm[27] @277
text kcvfhtnm[28] @278
text kcvfhtnm[29] @279
ub4 kcvfhrfn @280 0x00000000
struct kcvfhrfs, 8 bytes @284
ub4 kscnbas @284 0x00000000
ub2 kscnwrp @288 0x0000
ub4 kcvfhrft @292 0x00000000
struct kcvfhafs, 8 bytes @296
ub4 kscnbas @296 0x00000000
ub2 kscnwrp @300 0x0000
ub4 kcvfhbbc @304 0x00000000
ub4 kcvfhncb @308 0x00000000
ub4 kcvfhmcb @312 0x00000000
ub4 kcvfhlcb @316 0x00000000
ub4 kcvfhbcs @320 0x00000000
ub2 kcvfhofb @324 0x0000
ub2 kcvfhnfb @326 0x0000
ub4 kcvfhprc @328 0x00000000
struct kcvfhprs, 8 bytes @332
ub4 kscnbas @332 0x00000004
ub2 kscnwrp @336 0x0005
struct kcvfhprfs, 8 bytes @340
ub4 kscnbas @340 0x00535245
ub2 kscnwrp @344 0x0000
ub4 kcvfhtrt @356 0x00000000
BBED> p kcvfhckp ##The first two attributes are stored in the kcvjhckp sub-structure.
struct kcvfhckp, 36 bytes @140
struct kcvcpscn, 8 bytes @140
ub4 kscnbas @140 0x000001de ##From this we can see that the SCN of the file is 0x000001de which is 478.(select to_number('000001de','XXXXXXXX') DEC from dual;)
ub2 kscnwrp @144 0x40e7
ub4 kcvcptim @148 0x000001dd ##The change time is 0x000001dd.
ub2 kcvcpthr @152 0x0000
union u, 12 bytes @156
struct kcvcprba, 12 bytes @156
ub4 kcrbaseq @156 0x00000000
ub4 kcrbabno @160 0x00000000
ub2 kcrbabof @164 0x0000
struct kcvcptr, 12 bytes @156
struct kcrtrscn, 8 bytes @156
ub4 kscnbas @156 0x00000000
ub2 kscnwrp @160 0x0000
ub4 kcrtrtim @164 0x00000000
ub1 kcvcpetb[0] @168 0x00
ub1 kcvcpetb[1] @169 0x00
ub1 kcvcpetb[2] @170 0x00
ub1 kcvcpetb[3] @171 0x00
ub1 kcvcpetb[4] @172 0x00
ub1 kcvcpetb[5] @173 0x00
ub1 kcvcpetb[6] @174 0x00
ub1 kcvcpetb[7] @175 0x00
BBED> p kcvfhcpc ##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:
ub4 kcvfhcpc @176 0x00000000 ##Checkpoint count
BBED> p kcvfhccc
ub4 kcvfhccc @184 0x00000000 ##比Checkpoint count少1
BBED> d /v dba 4,2 offset 140 count 16 ##This data is stored at offsets 140 and 148 which we can see with the dump command:
File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4)
Block: 2 Offsets: 140 to 155 Dba:0x01000002
-------------------------------------------------------
de010000 e740b03e dd010000 00000000 l ?..鏎??...... ##de010000 dd010000分别对应kscnbas和kcvcptim
<16 bytes per line>
We now need to verify what change number the other data files are on by checking their data headers. 接下来,需要确认其他数据文件的系统改变号,检查他们的文件头块。
The following are the kcvfhckp, kcvfhcpc and kcvfhccc structures from the SYSTEM datafile: 下面检查下system datafile数据文件:
BBED> set dba 1,2 offset 0 DBA 0x00400002 (4194306 1,2) OFFSET 0 BBED> show FILE# 1 BLOCK# 2 OFFSET 0 DBA 0x00400002 (4194306 1,2) FILENAME D:\APP\LVS\ORADATA\LVS\SYSTEM01.DBF BIFILE bifile.bbd LISTFILE filelist.txt BLOCKSIZE 8192 MODE Edit EDIT Unrecoverable IBASE Dec OBASE Dec WIDTH 80 COUNT 16 LOGFILE bbed.log SPOOL Yes BBED> p kcvfhckp struct kcvfhckp, 36 bytes @140 struct kcvcpscn, 8 bytes @140 ub4 kscnbas @140 0x000001e1 ub2 kscnwrp @144 0x40e7 ub4 kcvcptim @148 0x000001e0 ub2 kcvcpthr @152 0x0000 union u, 12 bytes @156 struct kcvcprba, 12 bytes @156 ub4 kcrbaseq @156 0x00000000 ub4 kcrbabno @160 0x00000000 ub2 kcrbabof @164 0x0000 struct kcvcptr, 12 bytes @156 struct kcrtrscn, 8 bytes @156 ub4 kscnbas @156 0x00000000 ub2 kscnwrp @160 0x0000 ub4 kcrtrtim @164 0x00000000 ub1 kcvcpetb[0] @168 0x00 ub1 kcvcpetb[1] @169 0x00 ub1 kcvcpetb[2] @170 0x00 ub1 kcvcpetb[3] @171 0x00 ub1 kcvcpetb[4] @172 0x00 ub1 kcvcpetb[5] @173 0x00 ub1 kcvcpetb[6] @174 0x00 ub1 kcvcpetb[7] @175 0x00 BBED> p kcvfhcpc ub4 kcvfhcpc @176 0x00000000 BBED> p kcvfhccc ub4 kcvfhccc @184 0x00000000 BBED> d /v dba 1,2 offset 140 count 16 File: D:\APP\LVS\ORADATA\LVS\SYSTEM01.DBF (1) Block: 2 Offsets: 140 to 155 Dba:0x00400002 ------------------------------------------------------- e1010000 e740b03e e0010000 00000000 l ?..鏎??...... <16 bytes per line> We can see that the SCN on the SYSTEM dataflle is 0x000001e1 or 481. The change time is 0x000001e0. Using the modify command we can change the data file header of the older file: set dba 4,2 offset 0 BBED> modify /x e1010000 dba 4,2 offset 140 ##更改SCN Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4) Block: 2 Offsets: 140 to 155 Dba:0x01000002 ------------------------------------------------------------------------ e1010000 e740b03e dd010000 00000000 <32 bytes per line> BBED> modify /x e0010000 dba 4,2 offset 148 ##更改change time File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (4) Block: 2 Offsets: 148 to 163 Dba:0x01000002 ------------------------------------------------------------------------ e0010000 00000000 00000000 00000000 <32 bytes per line> modify /x 00 dba 4,2 offset 176 ##更改kcvfhcpc(Checkpoint count)。 注:此值一致,可不改。 modify /x 00 dba 4,2 offset 184 ##更改kcvfhccc(比Checkpoint count少1) 注:此值一致,可不改。 verify dba 4,2 sum dba 4,2 apply
Now that these four attributes of the data file have been manually updated to match the other data files, the database can opened: 我们刚刚只是修改了datafile header的信息,而存储在控制文件中的信息是无法用bbed来修改的,控制文件中的信息还是与数据文件不一致,数据库还是打不开。 这种情况,先重建控制文件,再进行恢复(参考:bbed恢复ORA-01113)
SQL> alter database backup controlfile to trace as 'd:\bbed\controlfile.txt'; 数据库已更改。 SQL> shutdown immediate ORA-01109: 数据库未打开 已经卸载数据库。 ORACLE 例程已经关闭。 SQL> startup nomount ORACLE 例程已经启动。 Total System Global Area 313159680 bytes Fixed Size 2280816 bytes Variable Size 180355728 bytes Database Buffers 125829120 bytes Redo Buffers 4694016 bytes CREATE CONTROLFILE REUSE DATABASE "LVS" NORESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 100 MAXINSTANCES 8 MAXLOGHISTORY 292 LOGFILE GROUP 1 'D:\APP\LVS\ORADATA\LVS\REDO01.LOG' SIZE 50M BLOCKSIZE 512, GROUP 2 'D:\APP\LVS\ORADATA\LVS\REDO02.LOG' SIZE 50M BLOCKSIZE 512, GROUP 3 'D:\APP\LVS\ORADATA\LVS\REDO03.LOG' SIZE 50M BLOCKSIZE 512 -- STANDBY LOGFILE DATAFILE 'D:\APP\LVS\ORADATA\LVS\SYSTEM01.DBF', 'D:\APP\LVS\ORADATA\LVS\SYSAUX01.DBF', 'D:\APP\LVS\ORADATA\LVS\UNDOTBS01.DBF', 'D:\APP\LVS\ORADATA\LVS\USERS01.DBF' CHARACTER SET ZHS16GBK ; 控制文件已创建。 SQL> alter database open; alter database open * 第 1 行出现错误: ORA-01113: ?? 4 ?????? ORA-01110: ???? 4: 'D:\APP\LVS\ORADATA\LVS\USERS01.DBF' SQL> recover database; 完成介质恢复。 SQL> alter database open; 数据库已更改。
2.5.4 恢复删除或损坏的数据(使用旧版数据文件拷贝数据块)
下面示例演示使用旧版本的数据文件拷贝恢复删除的数据。
潜在用于删除或错误更新数据的用户,他们无法承受异地恢复并导表带来的时间成本。
确认表段所在头文件、头块、块数量: select owner,segment_name,header_file,header_block,blocks from dba_segments where owner='SCOTT' and segment_name='TEST'; OWNER SEGMENT_NAME HEADER_FILE HEADER_BLOCK BLOCKS ------------------------------ --------------- ----------- ------------ ---------- SCOTT TEST 4 178 8 ##实际bbed地址从180开始,共8个块需拷贝
BBED: Release 2.0.0.0.0 - Limited Production on Tue Sep 22 21:07:54 2020 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. ************* !!! For Oracle Internal Use only !!! *************** BBED> info File# Name Size(blks) ----- ---- ---------- 1 D:\APP\LVS\ORADATA\LVS\USERS01.DBF 640 ##在用数据文件 2 D:\APP\LVS\ORADATA\LVS\USERS01_bak.DBF 640 ##旧的数据文件拷贝 BBED> show FILE# 1 BLOCK# 1 OFFSET 0 DBA 0x00400001 (4194305 1,1) FILENAME D:\APP\LVS\ORADATA\LVS\USERS01.DBF BIFILE bifile.bbd LISTFILE filelist2.txt BLOCKSIZE 8192 MODE Edit EDIT Unrecoverable IBASE Dec OBASE Dec WIDTH 80 COUNT 512 LOGFILE bbed.log SPOOL Yes BBED> set dba 1,178 DBA 0x004000b2 (4194482 1,178) BBED> map File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (1) Block: 178 Dba:0x004000b2 ------------------------------------------------------------ BBED-00400: invalid blocktype (33) BBED> set dba 1,179 DBA 0x004000b3 (4194483 1,179) BBED> map File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (1) Block: 179 Dba:0x004000b3 ------------------------------------------------------------ BBED-00400: invalid blocktype (35) ######特别注意: HEADER_BLOCK+2(windows),若linux平台,则HEADER_BLOCK+1 BBED> set dba 1,180 DBA 0x004000b4 (4194484 1,180) BBED> map File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (1) Block: 180 Dba:0x004000b4 ------------------------------------------------------------ KTB Data Block (Table/Cluster) struct kcbh, 20 bytes @0 struct ktbbh, 96 bytes @20 struct kdbh, 14 bytes @124 struct kdbt[1], 4 bytes @138 sb2 kdbr[14] @142 ub1 freespace[7411] @170 ub1 rowdata[607] @7581 ub4 tailchk @8188 BBED> p kdbr sb2 kdbr[0] @142 8026 sb2 kdbr[1] @144 7983 sb2 kdbr[2] @146 7940 sb2 kdbr[3] @148 7899 sb2 kdbr[4] @150 7854 sb2 kdbr[5] @152 7813 sb2 kdbr[6] @154 7772 sb2 kdbr[7] @156 7732 sb2 kdbr[8] @158 7694 sb2 kdbr[9] @160 7651 sb2 kdbr[10] @162 7613 sb2 kdbr[11] @164 7575 sb2 kdbr[12] @166 7536 sb2 kdbr[13] @168 7457 BBED> set dba 2,180 DBA 0x008000b4 (8388788 2,180) BBED> map File: D:\APP\LVS\ORADATA\LVS\USERS01_bak.DBF (2) Block: 180 Dba:0x008000b4 ------------------------------------------------------------ KTB Data Block (Table/Cluster) struct kcbh, 20 bytes @0 struct ktbbh, 96 bytes @20 struct kdbh, 14 bytes @124 struct kdbt[1], 4 bytes @138 sb2 kdbr[14] @142 ub1 freespace[7411] @170 ub1 rowdata[607] @7581 ub4 tailchk @8188 BBED> set offset 0 OFFSET 0 BBED> copy dba 2,180 to dba 1,180 ##重复执行8次,从180到187,共拷贝8个块 Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (1) Block: 180 Offsets: 0 to 511 Dba:0x004000b4 ------------------------------------------------------------------------ 06a20000 b3000001 5eb81000 00000104 61b70000 01000000 70540100 5eb81000 00000000 03003200 b0000001 09001e00 9d030000 7601c000 ae003900 00a00000 acb31000 05000500 95030000 721ec000 b8002800 00800000 0c0b1000 07001100 d4020000 9e02c000 92003700 00800000 9a931000 00000000 00000000 00010e00 ffff2e00 211d1a1d 1a1d0000 0e005a1f 2f1f041f db1eae1e 851e5c1e 341e0e1e e31dbd1d 971d701d 211d0000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 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> copy dba 2,181 to dba 1,181 File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (1) Block: 181 Offsets: 0 to 511 Dba:0x004000b5 ------------------------------------------------------------------------ 00a20000 b4000001 00000000 00000105 b4a60000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 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> copy dba 2,182 to dba 1,182 File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (1) Block: 182 Offsets: 0 to 511 Dba:0x004000b6 ------------------------------------------------------------------------ 00a20000 b5000001 00000000 00000105 b5a60000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 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> copy dba 2,183 to dba 1,183 File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (1) Block: 183 Offsets: 0 to 511 Dba:0x004000b7 ------------------------------------------------------------------------ 00a20000 b6000001 00000000 00000105 b6a60000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 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> copy dba 2,184 to dba 1,184 File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (1) Block: 184 Offsets: 0 to 511 Dba:0x004000b8 ------------------------------------------------------------------------ 00a20000 b7000001 00000000 00000105 b7a60000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 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> copy dba 2,185 to dba 1,185 File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (1) Block: 185 Offsets: 0 to 511 Dba:0x004000b9 ------------------------------------------------------------------------ 00a20000 b8000001 00000000 00000105 b8a60000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 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> copy dba 2,186 to dba 1,186 File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (1) Block: 186 Offsets: 0 to 511 Dba:0x004000ba ------------------------------------------------------------------------ 00a20000 b9000001 00000000 00000105 b9a60000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 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> copy dba 2,187 to dba 1,187 File: D:\APP\LVS\ORADATA\LVS\USERS01.DBF (1) Block: 187 Offsets: 0 to 511 Dba:0x004000bb ------------------------------------------------------------------------ 00a20000 ba000001 00000000 00000105 baa60000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 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>
SQL> shutdown immediate ##拷贝完重启数据库测试,数据已恢复 数据库已经关闭。 已经卸载数据库。 ORACLE 例程已经关闭。 SQL> startup ORACLE 例程已经启动。 Total System Global Area 313159680 bytes Fixed Size 2280816 bytes Variable Size 180355728 bytes Database Buffers 125829120 bytes Redo Buffers 4694016 bytes 数据库装载完毕。 数据库已经打开。 SQL> select * from scott.test; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- -------------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 17-12月-80 800 20 7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30 7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30 7566 JONES MANAGER 7839 02-4月 -81 2975 20 7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30 7698 BLAKE MANAGER 7839 01-5月 -81 2850 30 7782 CLARK MANAGER 7839 09-6月 -81 2450 10 7788 SCOTT ANALYST 7566 19-4月 -87 3000 20 7839 KING PRESIDENT 17-11月-81 5000 10 7844 TURNER SALESMAN 7698 08-9月 -81 1500 0 30 7876 ADAMS CLERK 7788 23-5月 -87 1100 20 EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- -------------- ---------- ---------- ---------- 7900 JAMES CLERK 7698 03-12月-81 950 30 7902 FORD ANALYST 7566 03-12月-81 3000 20 7934 MILLER CLERK 7782 23-1月 -82 250 10 已选择14行。
2.5.5 修改行数据列值
修改值本身,另外看情况(值长度与原值不一样)修改行头及行目录
2.5.6 清除数据块事务信息
异常宕机后回滚段损坏导致有未提交数据的块不能读取。需修改块,清除事务信息:将未提交状态改为已提交,需修改块itl中flag.lck.scn三项。
数据块Itl内容解析:
xid:usn.slot.wraps uba:dba.seq.record 提交标志: 已提交:Flag C---,Lck 0,scn 有值。 ##代表已提交,已块清除。 Flag --U-,Lck 有值,fsc 有值。 ##代表已快速提交,未做块清除。lck值代表被锁定的行数。 未提交:Flag ----,Lck 有值,scn 无值。 ##代表未提交。 block_row中行锁信息: lb:不为零时表示有事务锁定行,其值为itl槽号。
此外,可能还需更改回滚段头事务表信息state.cflags.scn.cmt。
回滚段头事务表内容解析:
提交标志: 已提交:state 9,cflags 0x00,scn 有值,cmt 有值 未提交:state 10,cflags 0x80,scn 0x0000.00000000,cmt 0
2.5.7 恢复数据文件时跳过缺少的归档
修改数据文件头块2处: checkpoint scn rba(介质恢复时日志记录的起点) 改为与存在归档文件中的信息一致。
select sequence#,first_change#,next_change#,name from v$archived_log;
更改方法,参考:oracle数据块结构及含义.txt--数据文件头块
数据文件头块: ++++++++++++++++++++ BBED> map File: /oracle/oradata/orcl/users01.dbf (4) Block: 1 Dba:0x01000001 ------------------------------------------------------------ Data File Header struct kcvfh, 860 bytes @0 ub4 tailchk @8188 里面包含单一结构:kcvfh 常用重要子结构项: kscnbas (linux:at offset 484) — SCN of last change to the dataflle. ##结构项位置:kcvfhckp kcvcptim (linux:at offset 492) — Time of the last change to the datafile. ##结构项位置:kcvfhckp kcvfhcpc (linux:at offset 140) — Checkpoint count. ##结构项位置:kcvfh kcvfhccc (linux:at offset 148) — Unknown, 比cpc少1. ##结构项位置:kcvfh kcvcprba (linux:at offset 500) ##结构项位置:kcvfh kcvfhckp ub4 kcrbaseq @500 0x0000001d ub4 kcrbabno @504 0x00000002 ub2 kcrbabof @508 0x0010 查看常用重要子结构项的值: p kcvfhckp ##查看kscnbas及kcvcptim、rba的值 p kcvfhcpc ##查看kcvfhcpc的值 p kcvfhccc ##查看kcvfhccc的值


&spm=1001.2101.3001.5002&articleId=140040841&d=1&t=3&u=24810de26fb543818b4eb99f8b8a6710)
472

被折叠的 条评论
为什么被折叠?



