【原】oracle11g bbed install and example

简介: 作者:david_zhang@sh 【转载时请以超链接形式标明文章】 链接:http://www.cnblogs.com/david-zhang-index/archive/2012/09/08/2676699.

作者:david_zhang@sh 【转载时请以超链接形式标明文章】

链接:http://www.cnblogs.com/david-zhang-index/archive/2012/09/08/2676699.html

1.上传(sbbdpt.o ssbbded.o bbedus.msb,该三个文件拷贝oracle的linux64版本的)文件,到如下代码展示的目录中

三个文件下载地址:linux10g_64_bbed.7z

1 SQL> select * from v$version where rownum=1;
2 
3 BANNER
4 --------------------------------------------------------------------------------
5 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
 1 [oracle@DG lib]$ pwd
 2 /u01/app/oracle/product/11.2.0/dbhome_1/rdbms/lib
 3 [oracle@DG lib]$ ls ssbbded.o sbbdpt.o
 4 sbbdpt.o  ssbbded.o
 5 [oracle@DG lib]$ cd ../mesg/
 6 [oracle@DG mesg]$ pwd
 7 /u01/app/oracle/product/11.2.0/dbhome_1/rdbms/mesg
 8 [oracle@DG mesg]$ ls bbedus.msb
 9 bbedus.msb
10 [oracle@DG mesg]$

2.执行如下命令:

1 [oracle@DG ~]$ make -f $ORACLE_HOME/rdbms/lib/ins_rdbms.mk BBED=$ORACLE_HOME/bin/bbed $ORACLE_HOME/bin/bbed
2 以下为执行命令后默认输出的
3 Linking BBED utility (bbed)
4 rm -f /u01/app/oracle/product/11.2.0/dbhome_1/bin/bbed
5 gcc -o /u01/app/oracle/product/11.2.0/dbhome_1/bin/bbed -m64 -L/u01/app/oracle/product/11.2.0/dbhome_1/rdbms/lib/ -L/u01/app/oracle/product/11.2.0/dbhome_1/lib/ -L/u01/app/oracle/product/11.2.0/dbhome_1/lib/stubs/  /u01/app/oracle/product/11.2.0/dbhome_1/lib/s0main.o /u01/app/oracle/product/11.2.0/dbhome_1/rdbms/lib/ssbbded.o /u01/app/oracle/product/11.2.0/dbhome_1/rdbms/lib/sbbdpt.o `cat /u01/app/oracle/product/11.2.0/dbhome_1/lib/ldflags`    -lncrypt11 -lnsgr11 -lnzjs11 -ln11 -lnl11 -ldbtools11 -lclntsh  `cat /u01/app/oracle/product/11.2.0/dbhome_1/lib/ldflags`    -lncrypt11 -lnsgr11 -lnzjs11 -ln11 -lnl11 -lnro11 `cat /u01/app/oracle/product/11.2.0/dbhome_1/lib/ldflags`    -lncrypt11 -lnsgr11 -lnzjs11 -ln11 -lnl11 -lnnz11 -lzt11 -lztkg11 -lztkg11 -lclient11 -lnnetd11  -lvsn11 -lcommon11 -lgeneric11 -lmm -lsnls11 -lnls11  -lcore11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -lxml11 -lcore11 -lunls11 -lsnls11 -lnls11 -lcore11 -lnls11 `cat /u01/app/oracle/product/11.2.0/dbhome_1/lib/ldflags`    -lncrypt11 -lnsgr11 -lnzjs11 -ln11 -lnl11 -lnro11 `cat /u01/app/oracle/product/11.2.0/dbhome_1/lib/ldflags`    -lncrypt11 -lnsgr11 -lnzjs11 -ln11 -lnl11 -lclient11 -lnnetd11  -lvsn11 -lcommon11 -lgeneric11   -lsnls11 -lnls11  -lcore11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -lxml11 -lcore11 -lunls11 -lsnls11 -lnls11 -lcore11 -lnls11 -lclient11 -lnnetd11  -lvsn11 -lcommon11 -lgeneric11 -lsnls11 -lnls11  -lcore11 -lsnls11 -lnls11 -lcore11 -lsnls11 -lnls11 -lxml11 -lcore11 -lunls11 -lsnls11 -lnls11 -lcore11 -lnls11   `cat /u01/app/oracle/product/11.2.0/dbhome_1/lib/sysliblist` -Wl,-rpath,/u01/app/oracle/product/11.2.0/dbhome_1/lib -lm    `cat /u01/app/oracle/product/11.2.0/dbhome_1/lib/sysliblist` -ldl -lm   -L/u01/app/oracle/product/11.2.0/dbhome_1/lib

3.登录,默认密码blockedit,出现如下提示符安装成功

 1 [oracle@DG ~]$ bbed
 2 Password:
 3 
 4 BBED: Release 2.0.0.0.0 - Limited Production on Sat Sep 8 15:29:28 2012
 5 
 6 Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
 7 
 8 ************* !!! For Oracle Internal Use only !!! ***************
 9 
10 BBED> show all
11         FILE#           0
12         BLOCK#          1
13         OFFSET          0
14         DBA             0x00000000 (0 0,1)
15         FILENAME
16         BIFILE          bifile.bbd
17         LISTFILE
18         BLOCKSIZE       8192
19         MODE            Browse
20         EDIT            Unrecoverable
21         IBASE           Dec
22         OBASE           Dec
23         WIDTH           80
24         COUNT           512
25         LOGFILE         log.bbd
26         SPOOL           No

 4.Example#1-Changing Data

 1 SQL> conn scott/tiger
 2   Connected.
 3   SQL> select * from presidents;
 4   
 5   NAME                 START_YEAR END_YEAR
 6   -------------------- ---------- ----------
 7   Dwight Eisnehower    1953       1961
 8   Jonh Kennedy         1961       1963
 9   
10   SQL> select rowid from presidents where name = 'Dwight Eisnehower';
11   
12   ROWID
13   ------------------
14   AAASTyAAEAAAAivAAA
 1 create or replace function get_rowid(l_rowid in varchar2) return varchar2 is
 2     ls_my_rowid   varchar2(200);
 3     rowid_type    number;
 4     object_number number;
 5     relative_fno  number;
 6     block_number  number;
 7     row_number    number;
 8   begin
 9     dbms_rowid.rowid_info(l_rowid,
10                           rowid_type,
11                           object_number,
12                           relative_fno,
13                           block_number,
14                           row_number);
15     ls_my_rowid := 'Row_id type is  :' || to_char(rowid_type) || chr(10) ||
16                    'Object# is      :' || to_char(object_number) || chr(10) ||
17                    'Relative_fno is :' || to_char(relative_fno) || chr(10) ||
18                    'Block number is :' || to_char(block_number) || chr(10) ||
19                    'Row number is   :' || to_char(row_number);
20     return ls_my_rowid;
21   end;
1 SQL> select get_rowid('AAASTyAAEAAAAivAAA') row_id from dual;
2   
3   ROW_ID
4   ------------------------------------------------------------
5   Row_id type is  :1
6   Object# is      :74994
7   Relative_fno is :4
8   Block number is :2223
9   Row number is   :0
 1 [oracle@DG ~]$ bbed parfile=bbed.par
 2  Password:
 3  
 4  BBED: Release 2.0.0.0.0 - Limited Production on Sat Sep 15 21:00:43 2012
 5  
 6  Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
 7  
 8  ************* !!! For Oracle Internal Use only !!! ***************
 9  
10  BBED> set dba 4,2223
11          DBA             0x010008af (16779439 4,2223)
12  
13  BBED> find /c Dwight
14   File: /u01/app/oracle/oradata/oracle/users01.dbf (4)
15   Block: 2223             Offsets: 8161 to 8191           Dba:0x010008af
16  ------------------------------------------------------------------------
17   44776967 68742045 69736e65 686f7765 72043139 35330431 39363101 0611d9
18  
19   <32 bytes per line>
20  BBED> dump /v dba 4,2223 offset 8161 count 64
21   File: /u01/app/oracle/oradata/oracle/users01.dbf (4)
22   Block: 2223    Offsets: 8161 to 8191  Dba:0x010008af
23  -------------------------------------------------------
24   44776967 68742045 69736e65 686f7765 l Dwight Eisnehowe
25   72043139 35330431 39363101 0611d9   l r.1953.1961...Ù
26  
27   <16 bytes per line>
28  
29  BBED> modify /c Eisn dba 4,2223 offset 8161
30  Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
31   File: /u01/app/oracle/oradata/oracle/users01.dbf (4)
32   Block: 2223             Offsets: 8161 to 8191           Dba:0x010008af
33  ------------------------------------------------------------------------
34   4569736e 68742045 69736e65 686f7765 72043139 35330431 39363101 0611d9
35  
36   <32 bytes per line>
37  
38  BBED> dump /v dba 4,2223 offset 8161 count 64
39   File: /u01/app/oracle/oradata/oracle/users01.dbf (4)
40   Block: 2223    Offsets: 8161 to 8191  Dba:0x010008af
41  -------------------------------------------------------
42   4569736e 68742045 69736e65 686f7765 l Eisnht Eisnehowe
43   72043139 35330431 39363101 0611d9   l r.1953.1961...Ù
44  
45   <16 bytes per line>
46  
47  BBED> sum dba 4,2223
48  Check value for File 4, Block 2223:
49  current = 0xcf83, required = 0xd494
50  
51  BBED> sum dba 4,2223 apply
52  Check value for File 4, Block 2223:
53  current = 0xd494, required = 0xd494
54  
55  BBED> exit
 1 SQL> alter system flush buffer_cache;
 2   
 3   System altered.
 4   
 5   SQL> conn scott/tiger
 6   Connected.
 7 SQL> select * from presidents;
 8 
 9 NAME                 START_YEAR END_YEAR
10 -------------------- ---------- ----------
11 Eisnht Eisnehower    1953       1961
12 Jonh Kennedy         1961       1963

备注:Dwight被Eisn替换是按照顺序进行的且字节数一致,替换后为Eisnht,如果ht也提替换可以空格补充。

Example#2-Recovering Deleted Rows

删除一条记录

 1 SQL> select * from presidents;
 2 
 3 NAME                 START_YEAR END_YEAR
 4 -------------------- ---------- ----------
 5 Eisnht Eisnehower    1953       1961
 6 Jonh Kennedy         1961       1963
 7 Richard Nixon        1969       1974
 8 
 9 SQL> delete from presidents where name = 'Richard Nixon';
10 
11 1 row deleted.
12 
13 SQL> commit;
14 
15 Commit complete.
16 
17 SQL> select * from presidents;
18 
19 NAME                 START_YEAR END_YEAR
20 -------------------- ---------- ----------
21 Eisnht Eisnehower    1953       1961
22 Jonh Kennedy         1961       1963

根据段名查询相关信息,并dump数据块

 1 SQL> select HEADER_FILE,HEADER_BLOCK,BLOCKS from dba_segments where SEGMENT_NAME = 'PRESIDENTS';
 2 
 3 HEADER_FILE HEADER_BLOCK     BLOCKS
 4 ----------- ------------ ----------
 5           4         2218          8
 6 
 7 SQL> alter system dump datafile 4 block min 2218 block max 2225;
 8 
 9 System altered.
10 
11 SQL> oradebug setmypid;
12 Statement processed.
13 SQL> oradebug tracefile_name;
14 /u01/app/oracle/diag/rdbms/oracle/oracle/trace/oracle_ora_3381.trc

查看trace文件,这里我dump了8个块,这里稍微解释下“--H-FL--”(数据块属性)= Row Flag=32+8+4=44=0x2c,“--HDFL--”(删除数据块属性)= Row Flag=32+16+8+4=60=0x3c

 1 .....省略.....
 2 block_row_dump:
 3 tab 0, row 0, @0x1f79
 4 tl: 31 fb: --H-FL-- lb: 0x0  cc: 3
 5 col  0: [17]  45 69 73 6e 68 74 20 45 69 73 6e 65 68 6f 77 65 72
 6 col  1: [ 4]  31 39 35 33
 7 col  2: [ 4]  31 39 36 31
 8 tab 0, row 1, @0x1f5f
 9 tl: 26 fb: --H-FL-- lb: 0x0  cc: 3
10 col  0: [12]  4a 6f 6e 68 20 4b 65 6e 6e 65 64 79
11 col  1: [ 4]  31 39 36 31
12 col  2: [ 4]  31 39 36 33
13 tab 0, row 2, @0x1f44
14 tl: 27 fb: --HDFL-- lb: 0x1  cc: 3
15 col  0: [13]  52 69 63 68 61 72 64 20 4e 69 78 6f 6e
16 col  1: [ 4]  31 39 36 39
17 col  2: [ 4]  31 39 37 34
18 end_of_block_dump
19 .....省略.....
定位数据块
1 BBED> set dba 4,2218 offset 0
2         DBA             0x010008aa (16779434 4,2218)
3         OFFSET          0

查找被删除数据

 1 BBED> find /c Nixon
 2 BBED-00212: search string not found
 3 
 4 
 5 BBED> set dba 4,2219 offset 0
 6         DBA             0x010008ab (16779435 4,2219)
 7         OFFSET          0
 8 
 9 BBED> find /c Nixon
10 BBED-00212: search string not found
11 
12 
13 BBED> set dba 4,2220 offset 0
14         DBA             0x010008ac (16779436 4,2220)
15         OFFSET          0
16 
17 BBED> find /c Nixon
18 BBED-00212: search string not found
19 
20 
21 BBED> set dba 4,2221 offset 0
22         DBA             0x010008ad (16779437 4,2221)
23         OFFSET          0
24 
25 BBED> find /c Nixon
26 BBED-00212: search string not found
27 
28 
29 BBED> set dba 4,2222 offset 0
30         DBA             0x010008ae (16779438 4,2222)
31         OFFSET          0
32 
33 BBED> find /c Nixon
34 BBED-00212: search string not found
35 
36 
37 BBED> set dba 4,2223 offset 0
38         DBA             0x010008af (16779439 4,2223)
39         OFFSET          0
40 
41 BBED> find /c Nixon
42  File: /u01/app/oracle/oradata/oracle/users01.dbf (4)
43  Block: 2223             Offsets: 8116 to 8191           Dba:0x010008af
44 ------------------------------------------------------------------------
45  4e69786f 6e043139 36390431 3937342c 00030c4a 6f6e6820 4b656e6e 65647904
46  31393631 04313936 332c0003 11456973 6e687420 4569736e 65686f77 65720431
47  39353304 31393631 0206d148
48 
49  <32 bytes per line>

dump数据块内容

 1 BBED> d /v dba 4,2223 offset 8116
 2  File: /u01/app/oracle/oradata/oracle/users01.dbf (4)
 3  Block: 2223    Offsets: 8116 to 8191  Dba:0x010008af
 4 -------------------------------------------------------
 5  4e69786f 6e043139 36390431 3937342c l Nixon.1969.1974,
 6  00030c4a 6f6e6820 4b656e6e 65647904 l ...Jonh Kennedy.
 7  31393631 04313936 332c0003 11456973 l 1961.1963,...Eis
 8  6e687420 4569736e 65686f77 65720431 l nht Eisnehower.1
 9  39353304 31393631 0206d148          l 953.1961..ÑH
10 
11  <16 bytes per line>

根据下面内容可以得出:一个偏移量两个字节,而“4e69786f”是8个字节,所以一次想跳8个字节,offset一次偏移4

 1 BBED> d /v dba 4,2223 offset 8116
 2  File: /u01/app/oracle/oradata/oracle/users01.dbf (4)
 3  Block: 2223    Offsets: 8116 to 8191  Dba:0x010008af
 4 -------------------------------------------------------
 5  4e69786f 6e043139 36390431 3937342c l Nixon.1969.1974,
 6  00030c4a 6f6e6820 4b656e6e 65647904 l ...Jonh Kennedy.
 7  31393631 04313936 332c0003 11456973 l 1961.1963,...Eis
 8  6e687420 4569736e 65686f77 65720431 l nht Eisnehower.1
 9  39353304 31393631 0206d148          l 953.1961..ÑH
10 
11  <16 bytes per line>
12 
13 BBED> d /v dba 4,2223 offset 8115
14  File: /u01/app/oracle/oradata/oracle/users01.dbf (4)
15  Block: 2223    Offsets: 8115 to 8191  Dba:0x010008af
16 -------------------------------------------------------
17  204e6978 6f6e0431 39363904 31393734 l  Nixon.1969.1974
18  2c00030c 4a6f6e68 204b656e 6e656479 l ,...Jonh Kennedy
19  04313936 31043139 36332c00 03114569 l .1961.1963,...Ei
20  736e6874 20456973 6e65686f 77657204 l snht Eisnehower.
21  31393533 04313936 310206d1 48       l 1953.1961..ÑH
22 
23  <16 bytes per line>

找到块头

 1 BBED> d /v dba 4,2223 offset 8104
 2  File: /u01/app/oracle/oradata/oracle/users01.dbf (4)
 3  Block: 2223    Offsets: 8104 to 8191  Dba:0x010008af
 4 -------------------------------------------------------
 5  3c02030d 52696368 61726420 4e69786f l <...Richard Nixo
 6  6e043139 36390431 3937342c 00030c4a l n.1969.1974,...J
 7  6f6e6820 4b656e6e 65647904 31393631 l onh Kennedy.1961
 8  04313936 332c0003 11456973 6e687420 l .1963,...Eisnht
 9  4569736e 65686f77 65720431 39353304 l Eisnehower.1953.
10  31393631 0206d148                   l 1961..ÑH
11 
12  <16 bytes per line>

再次确认被删除数据位置

 1 BBED> p kdbr
 2 sb2 kdbr[0]                                 @118      8057
 3 sb2 kdbr[1]                                 @120      8031
 4 sb2 kdbr[2]                                 @122      8004
 5 
 6 BBED> p *kdbr[0]
 7 rowdata[53]
 8 -----------
 9 ub1 rowdata[53]                             @8157     0x2c
10 
11 BBED> p *kdbr[1]
12 rowdata[27]
13 -----------
14 ub1 rowdata[27]                             @8131     0x2c
15 
16 BBED>  p *kdbr[2]
17 rowdata[0]
18 ----------
19 ub1 rowdata[0]                              @8104     0x3c

恢复删除数据

 1 BBED> modify /x 2c offset 8104
 2 Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
 3  File: /u01/app/oracle/oradata/oracle/users01.dbf (4)
 4  Block: 2223             Offsets: 8104 to 8191           Dba:0x010008af
 5 ------------------------------------------------------------------------
 6  2c02030d 52696368 61726420 4e69786f 6e043139 36390431 3937342c 00030c4a
 7  6f6e6820 4b656e6e 65647904 31393631 04313936 332c0003 11456973 6e687420
 8  4569736e 65686f77 65720431 39353304 31393631 0206d148
 9 
10  <32 bytes per line>

生效恢复

1 BBED> sum dba 4,2223
2 Check value for File 4, Block 2223:
3 current = 0xcfd0, required = 0xcfc0
4 
5 BBED> sum dba 4,2223 apply
6 Check value for File 4, Block 2223:
7 current = 0xcfc0, required = 0xcfc0

再次dump数据块确认成功

 1 BBED> d /v dba 4,2223 offset 8104
 2  File: /u01/app/oracle/oradata/oracle/users01.dbf (4)
 3  Block: 2223    Offsets: 8104 to 8191  Dba:0x010008af
 4 -------------------------------------------------------
 5  2c02030d 52696368 61726420 4e69786f l ,...Richard Nixo
 6  6e043139 36390431 3937342c 00030c4a l n.1969.1974,...J
 7  6f6e6820 4b656e6e 65647904 31393631 l onh Kennedy.1961
 8  04313936 332c0003 11456973 6e687420 l .1963,...Eisnht
 9  4569736e 65686f77 65720431 39353304 l Eisnehower.1953.
10  31393631 0206d148                   l 1961..ÑH
11 
12  <16 bytes per line>
13 ---------------------

查询表,数据成功恢复

 1 SQL> alter system flush buffer_cache;
 2 
 3 System altered.
 4 
 5 SQL> conn scott/tiger
 6 Connected.
 7 SQL> select * from presidents;
 8 
 9 NAME                 START_YEAR END_YEAR
10 -------------------- ---------- ----------
11 Eisnht Eisnehower    1953       1961
12 Jonh Kennedy         1961       1963
13 Richard Nixon        1969       1974

Example#3-Uncorrupting a Block

相关文章
|
Oracle 关系型数据库 数据库
Oracle 不使用DBCA在Oracle 11中删除数据库
Oracle 不使用DBCA在Oracle 11中删除数据库
69 0
|
Oracle 安全 关系型数据库
Oracle --Oracle 11.2.0.4静默安装
Oracle 11.2.0.4静默安装的详细步骤及踩坑记录
653 0
|
Web App开发 Oracle 关系型数据库
oracle database 18c rpm 安装
oracle rpm 安装,oracle rpm install.
2380 0
|
Oracle 关系型数据库 Windows
oracle 11g 删除
唔,百度上有完整的删除方式但是我好多找不到,就自己直接找到各个盘里面的删除了。记录下步骤:1.先把任务管理器里面的服务中所有oracle开头的服务全部关掉。
1007 0
|
Oracle 关系型数据库 数据库
|
Oracle 关系型数据库 C语言