用oracle 11g bbed copy替換同一個表資料塊block為另一個資料塊之系列八

wisdomone1發表於2015-11-01

背景

  學習用bbed替換同一個表中不同資料塊,即用同一個表中1個資料塊的內容替換另一個資料塊的內容。


結論

1,可以使用bbed copy命令複製一個資料塊內容到另一個資料塊
2,copy命令為
BBED> help copy
COPY [ DBA | FILE | FILENAME | BLOCK ] TO [ DBA | FILE | FILENAME | BLOCK ]


3,使用bbed copy複製資料塊後,目標資料塊的kcbh結構體的rdba_kcbh要恢復到修改前的內容
4,在用copy複製資料塊前,先要檢視或備份下源資料塊的內容
  p kcbh block 源資料塊編號
5,rdba_kcbh它是以反序顯示,但儲存以顯示的順序反過來儲存
   具體修改順序如下:
     1,檢視未複製前的rdba_kcbh,用命令:p kcbh block 未修改前的目標資料塊
     2, 採用copy複製源資料塊內容到目標資料塊,用命令:copy 源資料塊 to 目標資料塊
     3, 定位到目標資料塊的rdba_kcbh的偏移量,還原rdba_kcbh為修改前的內容,用命令
         set block 目標資料塊
         set offset rdba_kcbh的偏移量 (一般源於修改前的map獲取,因為修改中間不能使用map,可能會報錯) 
         根據修改前的rdba_kcbh內容,用m /x 修改前的rdba_kcbh值,進行還原即可
         固化或真正修改目標資料塊,用命令:sum apply
         檢視目標資料塊的rdba_kcbh,用命令:p rdba_kcbh,檢視是否變更成功


      4,如果中期想回退操作,使用undo即可
     


6,bbed print命令,組合非常強大,可以基於資料塊地址,檔案號,檔名稱,塊號,塊內的偏移量,或塊內的結構體,或採用父子樹狀結構體,顯示其資料塊的對應內容
BBED> help print
PRINT[/x|d|u|o|c] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]


BBED> p block 99183 
kcbh.type_kcbh
--------------
ub1 type_kcbh                               @0        0x06


BBED> p 4
kcbh.rdba_kcbh
--------------
ub4 rdba_kcbh                               @4        0x0101836f


BBED> p rdba_kcbh
ub4 rdba_kcbh                               @4        0x0101836f


BBED> p kcbh.rdba_kcbh
ub4 rdba_kcbh                               @4        0x0101836f




7,用bbed修改資料塊的內容,必須用強制重新整理緩衝池,方可生效,否則仍是原有的值


感嘆,BBED牛比啊,強悍


測試



SQL> select * from v$version where rownum=1;


BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production


SQL> create table t_replace_block(a int,b int);


Table created.


SQL> insert into t_replace_block select level,level from dual connect by level<=10000;


10000 rows created.


SQL> commit;


Commit complete.




SQL> select distinct DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID) from t_copy_block;


DBMS_ROWID.ROWID_RELATIVE_FNO(ROWID)
------------------------------------
                                   4






SQL> select distinct DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID) block_number from t_copy_block;


BLOCK_NUMBER
------------
       99182
       99183
       99185
       99198
       99193
       99197
       99187
       99189
       99199
       99179
       99180


BLOCK_NUMBER
------------
       99194
       99190
       99181
       99184
       99186
       99188
       99191


18 rows selected.


資料塊99182
SQL> select a,b from t_copy_block where DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)=99182 and dbms_rowid.rowid_row_number(rowid)=1;


         A          B
---------- ----------
      1135       1135 


資料塊99183
SQL> select a,b from t_copy_block where DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)=99183 and dbms_rowid.rowid_row_number(rowid)=1;


         A          B
---------- ----------
      1694       1694      


準備用99182資料塊內容替換99183資料塊內容




[oracle@seconary bbed_test]$ bbed parfile=bbed.text password=blockedit


BBED: Release 2.0.0.0.0 - Limited Production on Fri Oct 30 21:49:57 2015


Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.


************* !!! For Oracle Internal Use only !!! ***************


檢視資料塊99182
BBED> p kcbh block 99182
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        0x0101836e
   ub4 bas_kcbh                             @8        0x037afb1b
   ub2 wrp_kcbh                             @12       0x0000
   ub1 seq_kcbh                             @14       0x01
   ub1 flg_kcbh                             @15       0x06 (KCBHFDLC, KCBHFCKV)
   ub2 chkval_kcbh                          @16       0x1d7a
   ub2 spare3_kcbh                          @18       0x0000


檢視資料塊99183
BBED> p kcbh block 99183
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        0x0101836f
   ub4 bas_kcbh                             @8        0x037afb1b
   ub2 wrp_kcbh                             @12       0x0000
   ub1 seq_kcbh                             @14       0x01
   ub1 flg_kcbh                             @15       0x06 (KCBHFDLC, KCBHFCKV)
   ub2 chkval_kcbh                          @16       0x9362
   ub2 spare3_kcbh                          @18       0x0000


複製資料塊99182內容到資料塊99183
BBED> copy block 99182 to block 99183
 File: /oracle/oradata/guowang/users01.dbf (4)
 Block: 99183            Offsets:    0 to   31           Dba:0x0101836f
------------------------------------------------------------------------
 06a20000 6e830101 1bfb7a03 00000106 7a1d0000 01002100 dc240100 8ff97a03 


 <32 bytes per line>  


 再次檢視資料塊99183
 BBED> p kcbh block 99183
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        0x0101836e
   ub4 bas_kcbh                             @8        0x037afb1b
   ub2 wrp_kcbh                             @12       0x0000
   ub1 seq_kcbh                             @14       0x01
   ub1 flg_kcbh                             @15       0x06 (KCBHFDLC, KCBHFCKV)
   ub2 chkval_kcbh                          @16       0x1d7a
   ub2 spare3_kcbh                          @18       0x0000


BBED> 


當前資料塊變成複製資料塊的目標資料塊99183
BBED> d
 File: /oracle/oradata/guowang/users01.dbf (4)
 Block: 99183            Offsets:    0 to   31           Dba:0x0101836f
------------------------------------------------------------------------
 06a20000 6e830101 1bfb7a03 00000106 7a1d0000 01002100 dc240100 8ff97a03 


 <32 bytes per line> 




 BBED> d
 File: /oracle/oradata/guowang/users01.dbf (4)
 Block: 99183            Offsets:    4 to   35           Dba:0x0101836f
------------------------------------------------------------------------
 6e830101 1bfb7a03 00000106 7a1d0000 01002100 dc240100 8ff97a03 0000e81f 


 <32 bytes per line>


但複製後還需要把99183資料塊的rdba_kcbh還原回去,用於指定檔案號及資料塊,不然就亂套了
BBED> p rdba_kcbh block 99183
ub4 rdba_kcbh                               @0        0x0000a206


未複製前的99183資料塊的rdba_kcbh
   ub4 rdba_kcbh                            @4        0x0101836f




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        0x0101836e
   ub4 bas_kcbh                             @8        0x037afb1b
   ub2 wrp_kcbh                             @12       0x0000
   ub1 seq_kcbh                             @14       0x01
   ub1 flg_kcbh                             @15       0x06 (KCBHFDLC, KCBHFCKV)
   ub2 chkval_kcbh                          @16       0x1d7a
   ub2 spare3_kcbh                          @18       0x0000


BBED> set offset 4
        OFFSET          4


BBED> d
 File: /oracle/oradata/guowang/users01.dbf (4)
 Block: 99183            Offsets:    4 to   35           Dba:0x0101836f
------------------------------------------------------------------------
 6e830101 1bfb7a03 00000106 7a1d0000 01002100 dc240100 8ff97a03 0000e81f 


 <32 bytes per line>


BBED> m /x 6f830101
 File: /oracle/oradata/guowang/users01.dbf (4)
 Block: 99183            Offsets:    4 to   35           Dba:0x0101836f
------------------------------------------------------------------------
 6f830101 1bfb7a03 00000106 123d0000 01002100 dc240100 8ff97a03 0000e81f 


 <32 bytes per line>


BBED> sum apply
Check value for File 4, Block 99183:
current = 0x1d7b, required = 0x1d7b


BBED> p kcbh block 99183
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        0x0101836f
   ub4 bas_kcbh                             @8        0x037afb1b
   ub2 wrp_kcbh                             @12       0x0000
   ub1 seq_kcbh                             @14       0x01
   ub1 flg_kcbh                             @15       0x06 (KCBHFDLC, KCBHFCKV)
   ub2 chkval_kcbh                          @16       0x1d7b
   ub2 spare3_kcbh                          @18       0x0000


再次檢視錶的資料是否變化過來






可見資料塊的內容已經發生了,但一定要進行重新整理緩衝池,才能讓新變更的內容體現出來
SQL> select a,b from t_copy_block where DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)=99183 and dbms_rowid.rowid_row_number(rowid)=1;


         A          B
---------- ----------
      1694       1694


SQL> alter system flush buffer_cache;


System altered.


SQL> select a,b from t_copy_block where DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)=99183 and dbms_rowid.rowid_row_number(rowid)=1;


         A          B
---------- ----------
      1135       1135


個人簡介:


8年oracle從業經驗,具備豐富的oracle技能,目前在國內北京某專業oracle服務公司從事高階技術顧問。
   
   服務過的客戶:
          中國電信
          中國移動
          中國聯通
          中國電通
          國家電網
          四川達州商業銀行
          湖南老百姓大藥房
          山西省公安廳
          中國郵政
          北京302醫院     
          河北廊坊新奧集團公司
  
 專案經驗:
           中國電信3G專案AAA系統資料庫部署及最佳化
           中國聯通CRM資料庫效能最佳化
           中國移動10086電商平臺資料庫部署及最佳化
           湖南老百姓大藥房ERR資料庫sql最佳化專案
           四川達州商業銀行TCBS核心業務系統資料庫模型設計和RAC部署及最佳化
           四川達州商業銀行TCBS核心業務系統後端批處理儲存過程功能模組編寫及最佳化
           北京高鐵訊號監控系統RAC資料庫部署及最佳化
           河南宇通客車資料庫效能最佳化
           中國電信電商平臺核心採購模組表模型設計及最佳化
           中國郵政儲蓄系統資料庫效能最佳化及sql最佳化
           北京302醫院資料庫遷移實施
           河北廊坊新奧data guard部署及最佳化
           山西公安廳身份證審計資料庫系統故障評估
         
 聯絡方式:
          手機:18201115468
          qq   :   305076427
          qq微博: wisdomone1
          新浪微博:wisdomone9
          qq群:275813900    
          itpub部落格名稱:wisdomone1    http://blog.itpub.net/9240380/






來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-1820208/,如需轉載,請註明出處,否則將追究法律責任。

相關文章