oracle BBED 直接修改資料庫block塊

來源:互聯網
上載者:User

標籤:oracle   bbed   修改block塊   

--將lib中bbedus.msb和bbedus.msg 放在$ORACLE_HOME/rdbms/mesg下
--將lib中sbbdpt.o和ssbbded.o 放在$ORACLE_HOME/rdbms/lib下
--在$ORACLE_HOME/rdbms/lib下執行:[[email protected] lib]$ make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed
   執行後會在lib下產生一個bbed可執行檔

預設密碼;
blockedit

oracle BBED 直接修改資料庫block塊
bbed就是英文block browse block edit的縮寫,用來直接查看和修改資料檔案資料的一個工具。

建立一個表,插入5條測試資料:
create table chenlintest (id number(5) , name varchar(10))  tablespace users;

SQL> insert into chenlintest values(1,‘aa‘);
1 row created.
SQL> insert into chenlintest values (888 ,‘chenlin‘) ;
1 row created.
SQL> insert into chenlintest values (999 ,‘china‘) ;
1 row created.
SQL> insert into chenlintest values (999 ,‘usa‘) ;
1 row created.
SQL> insert into chenlintest values (1001 ,‘sydney‘) ;
1 row created.
Commit complete.
SQL> select * from chenlintest ;
        ID NAME
---------- ----------
         1 aa
       999 usa
      1001 sydney
       888 chenlin
       999 china
 
SQL> SELECT
         dbms_rowid.rowid_relative_fno(rowid) REL_FNO,
         dbms_rowid.rowid_block_number(rowid) BLOCKNO,
         dbms_rowid.rowid_row_number(rowid) ROWNO,
         user_id,username from t
         where rownum <6;
 
   REL_FNO    BLOCKNO      ROWNO         ID NAME
---------- ---------- ---------- ---------- ----------
         4     234300          0          1 aa
         4     234300          1        999 usa
         4     234300          2       1001 sydney
         4     234300          3        888 chenlin
         4     234300          4        999 china
 
通過上面的sql語句可以看出,chenlintest這個表的所有資料都在第4號檔案的第234300個block塊上。
現在我們嘗試去修改 aa ,也就是第一行。
 
設定bbed 的 2個設定檔,
一個是 file.txt檔案:
這個檔案對應的3個列為,file_id,path,block_size,可以使用SQL產生:

select file#||‘ ‘||name||‘ ‘||bytes from v$datafile ;

[[email protected] home]$ /home/oracle> cat file.txt
 
1 /opt/oracle/oradata/ge01/system01.dbf 870318080
2 /opt/oracle/oradata/ge01/users_cms.dbf 524288000
3 /opt/oracle/oradata/ge01/sysaux01.dbf 1866465280
4 /opt/oracle/oradata/ge01/users01.dbf 18971361280
5 /opt/oracle/oradata/ge01/users02.dbf 1073741824
6 /opt/oracle/oradata/ge01/perstat.dbf 209715200
7 /opt/oracle/oradata/ge01/undotbs02.dbf 1073741824
8 /opt/oracle/oradata/ge01/ttuser.dbf 41943040
9 /opt/oracle/oradata/ge01/idx_2k 20971520
 
一個是bbed.txt:

這個檔案是bbed的設定檔,配置了blocksize,listfile,mode 三個參數,我們在啟動的時候,使用這個檔案把bbed拉起來。
SQL> show parameter db_block_size
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_block_size                        integer     8192
SQL>
 
[[email protected] home]$ cat bbed.txt
blocksize=8192
listfile=/home/oracle/file.txt
mode=edit
/*
mode=edit  預設是borwser 瀏覽模式
可以使用 set mode edit 來切換
*/
-- bbed的安裝
cd $ORACLE_HOME/rdbms/lib
make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed
*/
-- 進入bbed
[[email protected] home]$./bbed parfile=/home/oracle/bbed.txt  或者直接是 ./bbed
[[email protected] lib]$ pwd
/opt/oracle/product/10g/rdbms/lib
[[email protected] lib]$ ll | grep bbed
-rwxr-xr-x 1 oracle oinstall  536154 May 14 14:47 bbed
[[email protected] lib]$
[[email protected] lib]$ ./bbed
Password: blockedit
BBED: Release 2.0.0.0.0 - Limited Production on Mon May 14 17:45:20 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
************* !!! For Oracle Internal Use only !!! ***************

BBED>  help all   查看所有命令協助

最常用的有show , map , dump  ,set dba , set file ,set  block  等
下面是幾個常用的:
set    設定當前的環境
show   查看當前的環境參數,跟sqlplus的同名命令類似。
dump   列出指定block的內容
find   在指定的block中尋找指定的字串,結果是顯示出字串,及其位移量--offset,位移量就是在block中的位元組數
modify 修改指定block的指定位移量的值,可以線上修改。
copy   把一個block的內容copy到另一個block中
verify 檢查當前環境是否有壞塊
sum    計算block的checksum,modify之後block就被標識為壞塊,current checksum與reqired checksum不一致,sum命令可以計

算出新的checksum並應用到當前塊。
undo   復原當前的修改操作,如果手誤做錯了,undo一下就ok了,回到原來的狀態。
revert 復原所有之前的修改操作,意思就是 undo all
 
BBED> show
        FILE#           0
        BLOCK#          1
        OFFSET          0
        DBA             0x00000000 (0 0,1)
        FILENAME      
        BIFILE          bifile.bbd
        LISTFILE      
        BLOCKSIZE       8192
        MODE            Browse
        EDIT            Unrecoverable
        IBASE           Dec
        OBASE           Dec
        WIDTH           80
        COUNT           512
        LOGFILE         log.bbd
        SPOOL           No
 
BBED> set file 4
BBED-00312: no LISTFILE specified  /*  LISTFILE為空白,說明我們剛剛建立的 file.txt未正確引入進來 */
BBED> set list ‘/home/oracle/file.txt‘
        LISTFILE        /home/oracle/file.txt
BBED> info
 File#  Name                                                        Size(blks)
 -----  ----                                                        ----------
     1  /opt/oracle/oradata/ge01/system01.dbf                           106240
     2  /opt/oracle/oradata/ge01/users_cms.dbf                           64000
     3  /opt/oracle/oradata/ge01/sysaux01.dbf                           227840
     4  /opt/oracle/oradata/ge01/users01.dbf                            524287
     5  /opt/oracle/oradata/ge01/users02.dbf                            131072
     6  /opt/oracle/oradata/ge01/perstat.dbf                             25600
     7  /opt/oracle/oradata/ge01/undotbs02.dbf                          131072
     8  /opt/oracle/oradata/ge01/ttuser.dbf                               5120
     9  /opt/oracle/oradata/ge01/idx_2k                                   2560
BBED> set file 4
        FILE#           4
--4號檔案為 /opt/oracle/oradata/ge01/users01.dbf
BBED> set block 234300
        BLOCK#          234300
BBED> set block +10
        BLOCK#          234310
BBED> set block -10
        BLOCK#          234300
--位移量是相對某個block裡的位移量,可以用+和-進行操作

還有很多種,不多寫了,參見:http://blog.csdn.net/tianlesoftware/article/details/5006580
BBED> map
 File: /opt/oracle/oradata/ge01/users01.dbf (4)
 Block: 234300                                Dba:0x0103933c
------------------------------------------------------------
 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[5]                                @118    
 ub1 freespace[7980]                        @128    
 ub1 rowdata[80]                            @8108   
 ub4 tailchk                                @8188
 
 通過map之後,可以看出真正block的結構體系, 塊中的儲存是由下往上儲存的,( @ 表示位移量 ),
 freespace 在真正的行資料 rowdata 之上,這個@8108開始,到@8188 ,後面放的是資料內容。
 我們上面說過的,要改的aa資料就在這2個位移量直接。
BBED> set offset 8108
        OFFSET          8108
BBED> dump /v  --查看offset 為8180 -8192的資料值
 File: /opt/oracle/oradata/ge01/users01.dbf (4)
 Block: 234300  Offsets: 8108 to 8191  Dba:0x0103933c
-------------------------------------------------------
 2c020203 c20b0206 7379646e 65792c02 l ,.......sydney,.
 0203c20a 64037573 612c0202 03c20a64 l ....d.usa,.....d
 05636869 6e612c00 0203c209 59076368 l .china,.....Y.ch
 656e6c69 6e3c0202 02c10402 63633c02 l enlin<......cc<.
 0202c103 0262622c 000202c1 02026161 l .....bb,......aa
 04066fe1                            l ..o.
 <16 bytes per line>
 
[email protected]> select dump(‘aa‘,1016) from dual;
 DUMP(‘AA‘,1016)
----------------------------------------------------------------------------------
 Typ=96 Len=2 CharacterSet=US7ASCII: 61,61
 
 在find之前先設定想要尋找的 file 和 block,預設是十進位的ascii編碼,/x 表示16進位,find的結果顯示出offset,即字元

出現的位置。
通過find尋找,“aa”的位置,我們發現6161就是 aa
如果還不確認,可以通過dump來實現

第一種find方法:
BBED> find   /x 6161 curr
 File: /opt/oracle/oradata/ge01/users01.dbf (4)
 Block: 234300           Offsets: 8186 to 8191           Dba:0x0103933c
------------------------------------------------------------------------
 61610406 6fe1
 <32 bytes per line>
 
第二種find方法:
BBED>
BBED>  find /c aa
 File: /opt/oracle/oradata/ge01/users01.dbf (4)
 Block: 234300           Offsets: 8186 to 8191           Dba:0x0103933c
------------------------------------------------------------------------
 61610406 6fe1
 <32 bytes per line>
 
 通過這2種方法,找到並確認 aa 在 8186 和 8191之間,下面試試修改他,把 aa 改成 bb
BBED> modify /c abcdefg
BBED-00215: editing not allowed in BROWSE mode
 
BBED> set mode edit
        MODE            Edit
 
BBED> modify /c bb  (注意長度,不能超過建表時候設定的長度,否則會出錯)
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) y
 File: /opt/oracle/oradata/ge01/users01.dbf (4)
 Block: 234300           Offsets: 8186 to 8191           Dba:0x0103933c
------------------------------------------------------------------------
 61626364 6566
 <32 bytes per line>
--讓 oracle進行checksum操作
BBED>  sum dba 4,234300
Check value for File 4, Block 234300:
current = 0xd268, required = 0x3405
--直接應用
BBED>  sum dba 4,234300 apply ;
Check value for File 4, Block 234300:
current = 0x3405, required = 0x3405
--驗證是否修改成功
BBED> verify
DBVERIFY - Verification starting
FILE = /opt/oracle/oradata/ge01/users01.dbf
BLOCK = 234300
 
--驗證是否修改成功
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
 
/*
Total Blocks Marked Corrupt   : 0,表示木有錯誤
在實際工作當中,如果發現修改錯誤了,則可以通過undo,revert進行復原操作。
在上面最常用的基本命令裡面講過了, 請注意undo和 revert的區別。
*/
SQL> select * from chenlintest ;
 
        ID NAME
---------- ----------
         1 aa
       999 usa
      1001 sydney
       888 chenlin
       999 china
 
--發現沒有變化,考慮是否需要清空buffer cache
SQL> alter system flush buffer_cache;
System altered.
SQL> select * from chenlintest ;
        ID NAME
---------- ----------
         1 bb
       999 usa
      1001 sydney
       888 chenlin
       999 china
打完收工,下一次繼續寫當資料庫,由於某個資料檔案不一致,啟動不來的時,改怎麼樣去修改datafile header的 SCN 號。使其

和控制檔案的SCN號一致!

 

oracle BBED 直接修改資料庫block塊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.