ITPub博客

首页 > 数据库 > Oracle > [20160302]关于bootstrap$的替换3.txt

[20160302]关于bootstrap$的替换3.txt

原创 Oracle 作者:lfree 时间:2016-03-02 09:10:51 0 删除 编辑

[20160302]关于bootstrap$的替换3.txt

--前几天写了关于启动时读取bootstrap$的内容。链接如下:http://blog.itpub.net/267265/viewspace-2016219/
--理论将可以自己建立一个新的bootstrap$替换它。自己测试看看。

1.环境:
--安全起见,先做一个冷备份。

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

create table bootstrap1 as select * from bootstrap$ ;

SYS@book> delete from bootstrap1 where LINE#=59;
1 row deleted.

SYS@book> commit ;
Commit complete.

SYS@book> select object_id,data_object_id,object_name from dba_objects where object_name='BOOTSTRAP1';
OBJECT_ID DATA_OBJECT_ID OBJECT_NAME
---------- -------------- --------------------
     91230          91230 BOOTSTRAP1

SYS@book> select owner,segment_name,header_file,header_block from dba_segments where segment_name='BOOTSTRAP1';
OWNER  SEGMENT_NAME         HEADER_FILE HEADER_BLOCK
------ -------------------- ----------- ------------
SYS    BOOTSTRAP1                     1        94712


SYS@book> select * from dba_extents where segment_name='BOOTSTRAP1';
OWNER  SEGMENT_NAME          SEGMENT_TYPE       TABLESPACE_NAME  EXTENT_ID    FILE_ID   BLOCK_ID      BYTES     BLOCKS RELATIVE_FNO
------ --------------------  ------------------ --------------- ---------- ---------- ---------- ---------- ---------- ------------
SYS    BOOTSTRAP1            TABLE              SYSTEM                   0          1      94712      65536          8            1

SYS@book> @ &r/convrdba 1 94712
old   2:  TO_CHAR (dbms_utility.make_data_block_address(&1,&2), 'xxxxxxxxxxxxx') rdba16,
new   2:  TO_CHAR (dbms_utility.make_data_block_address(1,94712), 'xxxxxxxxxxxxx') rdba16,
old   3: dbms_utility.make_data_block_address(&&1,&&2) rdba
new   3: dbms_utility.make_data_block_address(1,94712) rdba
RDBA16               RDBA
-------------- ----------
        4171f8    4289016

BBED> set dba 1,94712
        DBA             0x004171f8 (4289016 1,94712)

SYS@book> @ &r/bbvi 1 1
BVI_COMMAND
-----------------------------------------------------
bvi -b 8192 -s 8192 /mnt/ramdisk/book/system01.dbf

SYS@book> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

2.修改:

$ bvi -b 8192 -s 8192 /mnt/ramdisk/book/system01.dbf

--反转一下就是修改偏移量96处为 f8714100

BBED> set dba 1,1
        DBA             0x00400001 (4194305 1,1)

BBED> p kcvfhrdb
ub4 kcvfhrdb                                @96       0x004171f8

BBED> sum
Check value for File 1, Block 1:
current = 0x1f28, required = 0x6cd9

BBED> sum apply
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
Check value for File 1, Block 1:
current = 0x6cd9, required = 0x6cd9

3.启动测试:
SYS@book> startup
ORACLE instance started.

Total System Global Area  634679296 bytes
Fixed Size                  2255912 bytes
Variable Size             264242136 bytes
Database Buffers          360710144 bytes
Redo Buffers                7471104 bytes
Database mounted.
Database opened.

--OK!但是这样存在一个问题:

SYS@book> select rowid,a.* from bootstrap1 a where line#=2;
ROWID                   LINE#       OBJ# SQL_TEXT
------------------ ---------- ---------- ------------------------------------------------------------
AAAWReAABAAAXH7AAG          2          2 CREATE CLUSTER C_OBJ#("OBJ#" NUMBER) PCTFREE 5 PCTUSED 40 IN
                                         ITRANS 2 MAXTRANS 255 STORAGE (  INITIAL 136K NEXT 200K MINE
                                         XTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 OBJNO 2 EXTENTS
                                          (FILE 1 BLOCK 144)) SIZE 800


SYS@book> select rowid,a.* from bootstrap$ a where line#=2;
ROWID                   LINE#       OBJ# SQL_TEXT
------------------ ---------- ---------- ------------------------------------------------------------
AAAWReAABAAAXH7AAG          2          2 CREATE CLUSTER C_OBJ#("OBJ#" NUMBER) PCTFREE 5 PCTUSED 40 IN
                                         ITRANS 2 MAXTRANS 255 STORAGE (  INITIAL 136K NEXT 200K MINE
                                         XTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 OBJNO 2 EXTENTS
                                          (FILE 1 BLOCK 144)) SIZE 800

SYS@book> @ &r/rowid AAAWReAABAAAXH7AAG
    OBJECT       FILE      BLOCK        ROW DBA                  TEXT
---------- ---------- ---------- ---------- -------------------- ----------------------------------------
     91230          1      94715          6 1,94715              alter system dump datafile 1 block 94715
 
--可以发现现在bootstrap1与bootstrap$指向相同的位置。而实际的情况是:

SYS@book> select owner,segment_name,header_file,header_block from dba_segments where segment_name='BOOTSTRAP1';
OWNER  SEGMENT_NAME         HEADER_FILE HEADER_BLOCK
------ -------------------- ----------- ------------
SYS    BOOTSTRAP1                     1        94712

SYS@book> select owner,segment_name,header_file,header_block from dba_segments where segment_name='BOOTSTRAP$';
OWNER  SEGMENT_NAME         HEADER_FILE HEADER_BLOCK
------ -------------------- ----------- ------------
SYS    BOOTSTRAP$                     1          520

4.继续测试:
--实际上现在bootstrap$实际上读的是HEADER_BLOCK=94712,也就是BOOTSTRAP1.不建议做这样的修改,仅仅为了学习。
--千万不要在生产系统做这样的测试。

SYS@book> alter system flush shared_pool;
System altered.

SYS@book> select rowid,a.* from bootstrap$ a where line#=2;
ROWID                   LINE#       OBJ# SQL_TEXT
------------------ ---------- ---------- ------------------------------------------------------------
AAAWReAABAAAXH7AAG          2          2 CREATE CLUSTER C_OBJ#("OBJ#" NUMBER) PCTFREE 5 PCTUSED 40 IN
                                         ITRANS 2 MAXTRANS 255 STORAGE (  INITIAL 136K NEXT 200K MINE
                                         XTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 OBJNO 2 EXTENTS
                                          (FILE 1 BLOCK 144)) SIZE 800

--感觉有点怪怪的。最好的方式是改名看看。

SYS@book> rename bootstrap$ to bootstrapx;
rename bootstrap$ to bootstrapx
*
ERROR at line 1:
ORA-00701: object necessary for warmstarting database cannot be altered

$ oerr ora 701
00701, 00000, "object necessary for warmstarting database cannot be altered"
// *Cause:  Attempt to alter or drop a database object (table, cluster, or
//          index) which are needed for warmstarting the database.
// *Action: None.


--实际上可以参考链接,使用exec DBMS_DDL_INTERNAL.SWAP_BOOTSTRAP('BOOTSTRAP1').而不是手工操作,
--大家可以参考链接再测试,不再测试。

SYS@book> startup upgrade;
ORACLE instance started.

Total System Global Area  634679296 bytes
Fixed Size                  2255912 bytes
Variable Size             264242136 bytes
Database Buffers          360710144 bytes
Redo Buffers                7471104 bytes
Database mounted.
Database opened.

SYS@book> rename bootstrap$ to bootstrapx;
rename bootstrap$ to bootstrapx
*
ERROR at line 1:
ORA-00701: object necessary for warmstarting database cannot be altered

SYS@book> drop table  bootstrap$ ;
drop table  bootstrap$
            *
ERROR at line 1:
ORA-00701: object necessary for warmstarting database cannot be altered

--我的这个版本根本不能改名与删除。也许要通过直接修改内部表obj$,对换名字。

SYS@book> select obj#,owner#,name,namespace from obj$ where  obj# in (59,91230);
      OBJ#     OWNER# NAME                  NAMESPACE
---------- ---------- -------------------- ----------
        59          0 BOOTSTRAP$                    1
     91230          0 BOOTSTRAP1                    1


SYS@book> update obj$ set name='BOOTSTRAPX' where obj#=59;
1 row updated.

SYS@book> update obj$ set name='BOOTSTRAP$' where obj#=91230;
1 row updated.

SYS@book> select obj#,owner#,name,namespace from obj$ where  obj# in (59,91230);
      OBJ#     OWNER# NAME                  NAMESPACE
---------- ---------- -------------------- ----------
        59          0 BOOTSTRAPX                    1
     91230          0 BOOTSTRAP$                    1

SYS@book> commit ;
Commit complete.


--重新启动再测试:
SYS@book> startup
ORACLE instance started.
Total System Global Area  634679296 bytes
Fixed Size                  2255912 bytes
Variable Size             264242136 bytes
Database Buffers          360710144 bytes
Redo Buffers                7471104 bytes
Database mounted.
Database opened.
--OK!

SYS@book> select rowid,a.* from bootstrap$ a where line#=2;
ROWID                   LINE#       OBJ# SQL_TEXT
------------------ ---------- ---------- ------------------------------------------------------------
AAAWReAABAAAXH7AAG          2          2 CREATE CLUSTER C_OBJ#("OBJ#" NUMBER) PCTFREE 5 PCTUSED 40 IN
                                         ITRANS 2 MAXTRANS 255 STORAGE (  INITIAL 136K NEXT 200K MINE
                                         XTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 OBJNO 2 EXTENTS
                                          (FILE 1 BLOCK 144)) SIZE 800


SYS@book> select rowid,a.* from bootstrapx a where line#=2;
ROWID                   LINE#       OBJ# SQL_TEXT
------------------ ---------- ---------- ------------------------------------------------------------
AAAAA7AABAAAAILAAG          2          2 CREATE CLUSTER C_OBJ#("OBJ#" NUMBER) PCTFREE 5 PCTUSED 40 IN
                                         ITRANS 2 MAXTRANS 255 STORAGE (  INITIAL 136K NEXT 200K MINE
                                         XTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 OBJNO 2 EXTENTS
                                          (FILE 1 BLOCK 144)) SIZE 800
--rowid 不一样了。

SYS@book> select owner,segment_name,header_file,header_block from dba_segments where segment_name='BOOTSTRAPX';
OWNER  SEGMENT_NAME         HEADER_FILE HEADER_BLOCK
------ -------------------- ----------- ------------
SYS    BOOTSTRAPX                     1          520

SYS@book> select owner,segment_name,header_file,header_block from dba_segments where segment_name='BOOTSTRAP$';
OWNER  SEGMENT_NAME         HEADER_FILE HEADER_BLOCK
------ -------------------- ----------- ------------
SYS    BOOTSTRAP$                     1        94712

总结:
1.实际上测试测试仅仅加强理解,不要在生产系统做这样的测试!!!
2.而且如果出现损坏坏块,仅仅损坏这个区域的概率很小,要破坏也是一片区域。另外其他的区域如果破坏,你可以发现
  CREATE CLUSTER C_OBJ# 建立在FILE 1 BLOCK 144,如果损坏,数据库也无法启动。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/267265/viewspace-2022857/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    2903
  • 访问量
    6679110