[20160405]bbed的assign命令.txt

lfree發表於2016-04-05

[20160405]bbed的assign命令.txt

--我記得開始學習bbed的時候,看的是一份pdf文件,提到assign的用法,摘要如下:

assign

The assign command does symbolic assignment, with type and range checking. Either target or source can be omitted for the
current offset.  For example, the following command assigns structure at current offset to file 4,block 2 's first ITL
entry

BBED> assign dba 4, 2 ktbbhitl[0]

--感覺不是非常靈活,實際上assign非常靈活.
BBED> help assign
ASSIGN[/x|d|u|o] <target spec>=<source spec>
<target spec> : [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
<source spec> : [ value | <target spec options> ]

--使用這個命令,可以避免大小頭問題,修改資料塊變得非常簡單,我感覺許多人都不知道很好的使用assign.透過一個例子來說明:

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

SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name  FROM v$datafile_header;
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT FUZ NAME                             TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- -------------------------------- ----------------
    1        13227505290 2016-04-05 12:16:40                7       13227286650 ONLINE              1016 YES /mnt/ramdisk/book/system01.dbf   SYSTEM
    2        13227505290 2016-04-05 12:16:40             1834       13227286650 ONLINE              1012 YES /mnt/ramdisk/book/sysaux01.dbf   SYSAUX
    3        13227505290 2016-04-05 12:16:40           923328       13227286650 ONLINE               932 YES /mnt/ramdisk/book/undotbs01.dbf  UNDOTBS1
    4        13227505290 2016-04-05 12:16:40            16143       13227286650 ONLINE              1016 YES /mnt/ramdisk/book/users01.dbf    USERS
    5        13227505290 2016-04-05 12:16:40           952916       13227286650 ONLINE               929 YES /mnt/ramdisk/book/example01.dbf  EXAMPLE
    6        13227505290 2016-04-05 12:16:40          1314508       13227286650 ONLINE               945 YES /mnt/ramdisk/book/sugar01.dbf    SUGAR
    7        13227505290 2016-04-05 12:16:40      13227207527       13227286650 ONLINE                40 YES /mnt/ramdisk/book/tea01.dbf      TEA
7 rows selected.

2.假設我修改file#=7,CHECKPOINT_CHANGE#=13227505290-1.

select 13227505289,trunc(13227505289/power(2,32)) scn_wrap,mod(13227505289,power(2,32))  scn_base from dual
13227505289     SCN_WRAP     SCN_BASE
------------ ------------ ------------
13227505289            3    342603401

SYS@book> @ &r/10to16  13227505289

10 to 16 HEX   REVERSE16
-------------- -----------------------------------
00003146bb689 0x89b66b14-03000000

BBED> p /x dba 7,1 kcvfh.kcvfhckp.kcvcpscn.kscnbas
ub4 kscnbas                                 @484      0x146bb68a

BBED> p /x dba 1,1 kcvfh.kcvfhckp.kcvcpscn.kscnbas
ub4 kscnbas                                 @484      0x146bb68a

--我可以寫成:

BBED> assign dba 7,1 kcvfh.kcvfhckp.kcvcpscn.kscnbas  = 342603401
ub4 kscnbas                                 @484      0x146bb689

BBED> assign dba 7,1 kcvfh.kcvfhckp.kcvcpscn.kscnbas  = 0x146bb689
ub4 kscnbas                                 @484      0x146bb689


SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name  FROM v$datafile_header where file# in (1,7);
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT FUZ NAME                            TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- ------------------------------- ---------------
    1        13227505290 2016-04-05 12:16:40                7       13227286650 ONLINE              1016 YES /mnt/ramdisk/book/system01.dbf  SYSTEM
    7        13227505289 2016-04-05 12:16:40      13227207527       13227286650 ONLINE                40 YES /mnt/ramdisk/book/tea01.dbf     TEA

BBED> assign  dba 7,1 kcvfh.kcvfhckp.kcvcpscn.kscnbas  = dba 1,1 kcvfh.kcvfhckp.kcvcpscn.kscnbas
ub4 kscnbas                                 @484      0x146bb68a

--這樣就不要考慮大小頭的轉換,修改更加方便快捷,減少錯誤的發生.
--再舉一個例子,調整scn某個塊的scn增加10000,產生ORA-00600: internal error code, arguments: [2662].錯誤.

SYS@book> select current_scn from v$database ;
CURRENT_SCN
------------
13227510828

SYS@book> select ora_rowscn ,rowid,a.* from scott.empx a where rownum<=1;
  ORA_ROWSCN ROWID                     EMPNO ENAME      JOB                MGR HIREDATE                     SAL         COMM       DEPTNO
------------ ------------------ ------------ ---------- --------- ------------ ------------------- ------------ ------------ ------------
13227501857 AAAWe/AAHAAAACDAAA         7369 ZZZZ       CLERK             7902 1980-12-17 00:00:00          800                        20

select 13227501857,trunc(13227501857/power(2,32)) scn_wrap,mod(13227501857,power(2,32))  scn_base from dual
13227501857     SCN_WRAP     SCN_BASE
------------ ------------ ------------
13227501857            3    342599969

SYS@book> @ &r/rowid AAAWe/AAHAAAACDAAA
      OBJECT         FILE        BLOCK          ROW DBA                  TEXT
------------ ------------ ------------ ------------ -------------------- ----------------------------------------
       92095            7          131            0 7,131                alter system dump datafile 7 block 131 ;

select 13227520828,trunc(13227520828/power(2,32)) scn_wrap,mod(13227520828,power(2,32))  scn_base from dual
13227520828     SCN_WRAP     SCN_BASE
------------ ------------ ------------
13227520828            3    342618940
--比當前多1萬.

BBED> set dba 7,131
        DBA             0x01c00083 (29360259 7,131)

BBED> p /d kcbh.bas_kcbh
ub4 bas_kcbh                                @8        342599969

BBED> assign dba 7,131 kcbh.bas_kcbh=342618940;
ub4 bas_kcbh                                @8        0x146bf33c
--直接指定十進位制.

BBED> modify /x 3cf3 offset 8190
File: /mnt/ramdisk/book/tea01.dbf (7)
Block: 131      Offsets: 8190 to 8191  Dba:0x01c00083
-------------------------------------------------------
3cf3

<80 bytes per line>
--要顛倒一下,不小心很容易錯誤,這是不能使用assign dba 7,131 tailchk = 0xf33c0602;,不知道為什麼
--BBED> assign dba 7,131 tailchk = 0xf33c0602;
-- BBED-00207: invalid offset specifier (f33c0602)

BBED> p tailchk
ub4 tailchk                                 @8188     0xf33c0602

SYS@book> select ora_rowscn ,rowid,a.* from scott.empx a where rownum<=1;
select ora_rowscn ,rowid,a.* from scott.empx a where rownum<=1
*
ERROR at line 1:
ORA-00600: internal error code, arguments: [2662], [3], [342609366], [3], [342618940], [29360259], [], [], [], [], [], []

SYS@book> Select current_scn from v$database ;
CURRENT_SCN
------------
13227511270

--資料塊的scn超前了,需要等一會.

SCOTT@book> select ora_rowscn ,rowid,a.* from scott.empx a where rownum<=1;
  ORA_ROWSCN ROWID                     EMPNO ENAME      JOB                MGR HIREDATE                     SAL         COMM       DEPTNO
------------ ------------------ ------------ ---------- --------- ------------ ------------------- ------------ ------------ ------------
13227501857 AAAWe/AAHAAAACDAAA         7369 ZZZZ       CLERK             7902 1980-12-17 00:00:00          800                        20

SCOTT@book> select current_scn from v$database ;
CURRENT_SCN
------------
13227521335
--ok,現在正常了.

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

相關文章