Поиск по этому блогу

вторник, мая 26, 2009

Ковыряем BBED. Block Browser and EDitor. Часть 1

Для Linux програмка есть в поставке, но в разобраном виде. Поэтому выполняем следующие действия

cd $ORACLE_HOME/rdbms/lib
make -f ins_rdbms.mk $ORACLE_HOME/rdbms/lib/bbed

Имеет смысл скопировать bbed в каталог $ORACLE_HOME/bin. После запуска программки требуется ввод пароля. Для RedHat4 и Oracle10 пароль по умолчанию "blockedit".

[oracle@localhost lib]$ bbed
Password:

BBED: Release 2.0.0.0.0 - Limited Production on Sat May 23 20:30:31 2009

Copyright (c) 1982, 2005, Oracle. All rights reserved.

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



Команды:
help all - я бы сказал очень краткая помощь

BBED> help all
SET DBA [ dba | file#, block# ]
SET FILENAME 'filename'
SET FILE file#
SET BLOCK [+/-]block#
SET OFFSET [ [+/-]byte offset | symbol | *symbol ]
SET BLOCKSIZE bytes
SET LIST[FILE] 'filename'
SET WIDTH character_count
SET COUNT bytes_to_display
SET IBASE [ HEX | OCT | DEC ]
SET OBASE [ HEX | OCT | DEC ]
SET MODE [ BROWSE | EDIT ]
SET SPOOL [ Y | N ]
SHOW [ | ALL ]
INFO
MAP[/v] [ DBA | FILENAME | FILE | BLOCK ]
DUMP[/v] [ DBA | FILENAME | FILE | BLOCK | OFFSET | COUNT ]
PRINT[/x|d|u|o|c] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
EXAMINE[/Nuf] [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
:
N - a number which specifies a repeat count.
u - a letter which specifies a unit size:
b - b1, ub1 (byte)
h - b2, ub2 (half-word)
w - b4, ub4(word)
r - Oracle table/index row
f - a letter which specifies a display format:
x - hexadecimal
d - decimal
u - unsigned decimal
o - octal
c - character (native)
n - Oracle number
t - Oracle date
i - Oracle rowid
FIND[/x|d|u|o|c] numeric/character string [ TOP | CURR ]
COPY [ DBA | FILE | FILENAME | BLOCK ] TO [ DBA | FILE | FILENAME | BLOCK ]
MODIFY[/x|d|u|o|c] numeric/character string
[ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
ASSIGN[/x|d|u|o] =
: [ DBA | FILE | FILENAME | BLOCK | OFFSET | symbol | *symbol ]
: [ value | ]
SUM [ DBA | FILE | FILENAME | BLOCK ] [ APPLY ]
PUSH [ DBA | FILE | FILENAME | BLOCK | OFFSET ]
POP [ALL]
REVERT [ DBA | FILE | FILENAME | BLOCK ]
UNDO
HELP [ | ALL ]
VERIFY [ DBA | FILE | FILENAME | BLOCK ]
CORRUPT [ DBA | FILE | FILENAME | BLOCK ]

show - показывает текущие настройки. Какой файл данных смотрим, размер блока, где располагается список файлов данных и т.д.

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

BLOCKSIZE - Размер стандартного блока в байтах.
MODE - Режим запуска программы (browse or edit)
SILENT - Suppreses output to standart out (Y or N)
SPOOL - Spools output to bbed.log file (Y or N)
LISTFILE - Список датафайлов для редактирования
CMDFILE - Имя файла со списком команд для выполнения
BIFILE - Filename of before-image file (undo) file. Default name is bifile.bbd
LOGFILE - Filename of user logfile. Default name is log.bbd
PARFILE - Parameter file with above option listed. Почему-то я не наше этого параметря в Oracle10. Поэтому настройки менял вручную.

Если присмотреться к листингу предудщей команды и текущей, то нетрудно догадаться
что выполнение команды SET DBA приведет к изменению параметра DBA в команде show.
к примеру:
выполнение команды set file 2 приведет к ошибке. И действительно если посмотреть на листинг команды show увидим что параметр LISTFILE пустой.

BBED> set file 2
BBED-00312: no LISTFILE specified

Исправить это можно выполнив следующие действия. Запрос к базе
SQL> select file#||' '||name||' '||bytes from v$datafile;
FILE#||''||NAME||''||BYTES
--------------------------------------------------------------------------------1 /home/oracle/oracle/product/10.2.0/oradata/pahom/system01.dbf 503316480
2 /home/oracle/oracle/product/10.2.0/oradata/pahom/undotbs01.dbf 36700160
3 /home/oracle/oracle/product/10.2.0/oradata/pahom/sysaux01.dbf 251658240
4 /home/oracle/oracle/product/10.2.0/oradata/pahom/users01.dbf 5242880
5 /home/oracle/oracle/product/10.2.0/oradata/pahom/example01.dbf 104857600

Результат выполнения сохраним в файле /home/oracle/oracle/product/10.2.0/bbed/fileunix.log

И выполним команду
BBED> set list '/home/oracle/oracle/product/10.2.0/bbed/fileunix.log'
LISTFILE /home/oracle/oracle/product/10.2.0/bbed/fileunix.log
Теперь запрос на установку параметра set file 2 выполнится.
BBED> set file 2
FILE# 2

Изучив новый листинг команды show, заметим что текущие значения FILENAME, FILE#, DBA, LISTFILE изменились.
BBED> show
FILE# 2
BLOCK# 1
OFFSET 0
DBA 0x00800001 (8388609 2,1)
FILENAME /home/oracle/oracle/product/10.2.0/oradata/pahom/undotbs01.dbf
BIFILE bifile.bbd
LISTFILE /home/oracle/oracle/product/10.2.0/bbed/fileunix.log
BLOCKSIZE 8192
MODE Browse
EDIT Unrecoverable
IBASE Dec
OBASE Dec
WIDTH 80
COUNT 512
LOGFILE log.bbd
SPOOL No

info - показывает список датафайлов.
BBED> info
File# Name Size(blks)
----- ---- ----------
1 /home/oracle/oracle/product/10.2.0/oradata/pahom/system01. 61440
2 /home/oracle/oracle/product/10.2.0/oradata/pahom/undotbs01 4480
3 /home/oracle/oracle/product/10.2.0/oradata/pahom/sysaux01. 30720
4 /home/oracle/oracle/product/10.2.0/oradata/pahom/users01.d 640
5 /home/oracle/oracle/product/10.2.0/oradata/pahom/example01 12800

Конечно если указал файл с этим списком. Иначе получим результат:
BBED> info
File# Name Size(blks)
----- ---- ----------

set dba - Data Block Address. set dba "file_id","block"

set filename - Указываем имя текущего обрабатываемого датафайла

set file - Указываем file_id текущего обрабатываемого датафайла

set block - Указываем текущий блок данных обрабатываемого датафайла. Возможно использование set block +16. Если текущий блок 16, то после этой команды текущим станет 32 блок.

set offset - Незнакомое мне понятие. Кажется относительная ссылка в блоке(в байтах). Описание аналогично set block

set width - Ширина экрана. По умолчанию 80 символов

set count - Количество байт выводимых при команде dump. По умолчанию 512.

set ibase - Формат чисел используемый при работе с BBED. По умолчанию decimal (hexadecimal or octal)

map - The map command shows a map of the current block.
Structure/Element Description
Struct kcbh, 20 bytes ==Block Header Structure
ub1 type_kcbh ==Block type (see Header Block Types
below)
ub1 frmt_kcbh ==Block format 1=Oracle7, 2=Oracle8+
ub1 spare1_kcbh ==Not used
ub1 spare2_kcbh ==Not used
ub4 rdba_kcbh ==RDBA – Relative Data Block Address
ub4 bas_kcbh ==SCN Base
ub2 wrp_kcbh ==SCN Wrap
ub1 seq_kcbh ==Sequence number, incremented for every change made
to the bock at the same SCN
ub1 flg_kcbh ==Flag: 0x01 New block
0x02 delayed Logging Change advanced SCN/seq
0x04 Check value saved – block XOR’s to zero
0x08 Temporary block
ub2 chkval_kcbh ==Optional block checksum ( if DB_BLOCK_CHECKSUM=TRUE)
ub2 spare3_kcbh ==Not used
struct ktbbh, 72 bytes ==Transaction Fixed Header Structure
ub1 ktbbhtyp ==Block type (1=DATA, 2=INDEX)
union ktbbhsid, 4 bytes ==Segment/Object ID
struct ktbbhcsc, 8 bytes ==SCN at last block cleanout
b2 ktbbhict ==Number of ITL slots
ub1 ktbbhflg ==0=on the freelist
ub1 ktbbhfsl ==ITL TX freelist slot
ub4 ktbbhfnx ==DBA of next block on the freelist
struct ktbbhitl[2], 48 bytes ==ITL list index
struct kdbh, 14 bytes ==Data Header Structure
ub1 kdbhflag ==N=pctfree hit(clusters); F=do not put on freelist;
K=flushable cluster keys
b1 kdbhntab ==Number of tables (>1 in clusters)
b2 kdbhnrow ==Number of rows
sb2 kdbhfrre ==First free row entry index; -1=you have to add one
sb2 kdbhfsbo ==Freespace begin offset
sb2 kdbhfseo ==Freespace end offset
b2 kdbhavsp ==Available space in the block
b2 kdbhtops ==Total available space when all TXs commit
struct kdbt[1], 4 bytes ==Table Directory Entry Structure
b2 kdbtofs
b2 kdbtnrow
sb2 kdbr[1] ==Row Directory
ub1 freespace[8030] ==Free Space
ub1 rowdata[38] ==Row Data
ub4 tailchk ==(See Tailchecks below)

Header Block Types
ID Type
01 Undo segment header
02 Undo data block
03 Save undo header
04 Save undo data block
05 Data segment header(temp,index,data and so on)
06 KTB managed data block (with ITL)
07 Temp table data block (no ITL)
08 Sort Key
09 Sort Run
10 Segment free list block
11 Data file header


Cache Layer Block Types

This is a list of the block type numbers found in cache layer block headers.

Code= Block Type= Versions
1= Undo header block (limited extents)= all, but superseded by type 14 from 8.0
2= Undo data block= all
3= Save undo header block (limited extents)= all, but superseded by type 15 from 8.0
4= Save undo data block= all
5= Data segment header block (limited extents, no freelist groups)= all, but superseded by type 16 from 8.0
6= Table/cluster/index segment data block= all
7= Temporary segment data block= all
8= Sort key block= all
9= Sort run block= all
10= Free list block= all, but superseded by type 22 from 8.0
11= Data file header block= all
12= Data segment header block (limited extents, with freelist groups)= all, but superseded by type 17 from 8.0
13= Compatibility segment= all
14= Undo header block (unlimited extents)= from 7.3
15= Save undo header block (unlimited extents)= from 7.3
16= Data segment header block (unlimited extents, no freelist groups)= from 7.3
17= Data segment header block (unlimited extents, with freelist groups)= from 7.3
18= Extent map block= from 7.3
19= Backup set piece header= from 8.0
20= Backup set directory block= from 8.0
21= Controlfile block= from 8.0
22= Free list block with free block count= from 8.0
23= LOB segment header block= from 8.0
24= LOB segment freelist block= from 8.0
25= LOB segment space usage index block= from 8.0
26= LOB segment space usage bitmap block= from 8.0
27= LOB segment chunk data block= from 8.0
28= don't know
29= LMT space map header block= from 8.1
30= LMT space map block= from 8.1
31= don't know
32= ASSM level 1 bitmap block= from 9.0
33= ASSM level 2 bitmap block= from 9.0
34= ASSM level 3 bitmap block= from 9.0
35= ASSM segment header block= from 9.0
36= ASSM extent map block= from 9.0
37= don't know
38= System managed undo header block= from 9.0




Tailchecks
SCN base Type SCN seq
9728 06 02
A tail check of 0x97280602 stored on an Intel machine would be written to disk as "02062897".

BBED> map dba 4,12
File: /home/oracle/oracle/product/10.2.0/oradata/pahom/users01.dbf (4)
Block: 12 Dba:0x0100000c
------------------------------------------------------------
KTB Data Block (Table/Cluster)
struct kcbh, 20 bytes @0
struct ktbbh, 72 bytes @20
struct kdbh, 14 bytes @100
struct kdbt[0], 0 bytes @114
sb2 kdbr[0] @114
ub1 freespace[8074] @114
ub1 rowdata[0] @8188
ub4 tailchk @8188


(d)ump -The dump command dumps the content of the block to the screen. It can be combinet with the /v option to produce a more verbose output.
Описание первых 16 байтов блока
06020000 0с00с001 16830300 00000104
Type Format Unused RDBA SCN Base SCN Wrap Seq Flag
06 02 0000 0c00c001 16830300 0000 01 04

(p)rint - Насколько понял печатает содержимое описания блока. Описание формата вывода
Unit Size* | Name | Offset | Value

BBED> p tailchk
ub4 tailchk @8188 0xbfdb0601

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 0x0100000c
ub4 bas_kcbh @8 0x0006bfdb
ub2 wrp_kcbh @12 0x0000
ub1 seq_kcbh @14 0x01
ub1 flg_kcbh @15 0x04 (KCBHFCKV)
ub2 chkval_kcbh @16 0x38aa
ub2 spare3_kcbh @18 0x0000

BBED> p offset 16
kcbh.chkval_kcbh
ub2 chkval_kcbh @16 0x38aa

Switch Display Format
/x Hex
/d signed decimal
/u uncigned decimal
/o Octal
/c Character
/n Oracle Number
/t Oracle Date
/i Oracle ROWID

BBED> p /c offset 14 - получим в поле Value “.” вместо 0x01


e(x)amine - Надо разобраться. Чего-то там проверяет. Не совсем понятна строка BBED> x /rcnn


(f)ind - Поиск в блоке. Поиск можно задавать в различных типах данных
/x Hexadecimal
/d Decimal
/u unsigned decimal
/o Octal
/c character (native)
Если использовать TOP то поиск начинается с начала блока (offset 0)
BBED> find /c ar TOP -поиск строки “ar” в текущем блоке. Начиная с начала блока.


copy - Копирование содержимого блока в другой блок.
BBED> copy dba 2,16 to dba 1,16


(m)odify - Изменение данных в блоке. Начиная с 8170 байта
BBED> modify /c Eisen dba 7,16 offset 8170


assign - The assign command does symbolic assignment, with type and range checking. Eithen target or source can be omitted for the current offset. Exemple assign structure at current offset to file 4, block 2’s first ITL entry
BBED> assign dba 4,2 ktbbhitl[0]


sum - The sum command is used to check and set the block checksum. The apply directive can be used to update the checksum. Example shows the block checksum of file 7, block 16 being checked and then updated.
BBED> sum dba 7, 16
Check value for File 7 Block 16:
Current = 0x02d1, required = 0x09da
BBED> sum dba 7, 16 apply
Check value for File 7 Block 16:
Current = 0x09da, required = 0x09da


push/pop - Записываем в память содержимое блока. Извлекаем из памяти в текущий блок.
BBED> push dba 7, 16
BBED> set dba 6, 1
BBED> pop


revert - The revert command is used to restore a file, filename, block or DBA to it’s original state when bbed was started.
BBED> revert dba 7, 16


undo - The undo command rolls back the last modify or assign command.


verify - The verify command is used to verify the integrity of the block. It performs a similar function to the "dbverify" utility.


corrupt - The corrupt command is used to mark blocks as media corrupt.
Note: The undo command does not undo a corruption. The revert command however does.

понедельник, мая 25, 2009

Делаем dump. Описание команд

Donald K. Burleson

Oracle Tips

How to tell Oracle to take a dump



It is often useful to dump the internal contents of Oracle internal structures such as the control files, library cache, and redo log headers. The following undocumented Oracle commands can be used for this purpose.



For each of these commands, a trace file will be generated in your UDUMP directory. After issuing the command, you can go to your UDUMP directory to view the contents of the dump.



1 – SCN Dump - This command dumps the control file contents to see SCN information. The SCN information is especially useful when doing a database recovery.



alter session set events
'immediate trace name CONTROLF level 10';





2 – File Header Dump - Here is the command to dump file headers. This dump is also quite useful if you have a corrupt database or a failure from rman in doing a database recovery.



alter session set events
'immediate trace name FILE_HDRS level 10';



3 - Dump redo log headers – This command will dump all of the redo log header information.



alter session set events
'immediate trace name REDOHDR level 10';



4 – System state dump – This command will dump the system state to your trace file.



alter session set events
'immediate trace name SYSTEMSTATE level 10';



5 – Process state dump – This command will dump the process state for all active processes in your database:



alter session set events
'immediate trace name PROCESSSTATE level 10';



6 – Library Cache Dump – This command is very useful for examining library Cache details, especially when you are having high library cache reloads or SQL access contention:





alter session set events
'immediate trace name library_cache level 10';



Here is a partial listing from this dump. As you can see, Oracle provides a wealth of detailed information about the internals of the library cache:



Dump file /u01/app/oracle/admin/testc1/udump/testc1_ora_16167.trc

Oracle8i Enterprise Edition Release 8.1.6.1.0 - 64bit Production

With the Partitioning option

JServer Release 8.1.6.1.0 - 64bit Production

ORACLE_HOME = /u01/app/oracle/product/8.1.6_64

System name: SunOS

Node name: sting

Release: 5.8

Version: Generic_108528-03

Machine: sun4u

Instance name: testc1

Redo thread mounted by this instance: 1

Oracle process number: 10

Unix process pid: 16167, image: oracle@sting (TNS V1-V3)



*** SESSION ID:(10.6858) 2001-07-05 10:29:17.148

LIBRARY CACHE STATISTICS:

gets hit ratio pins hit ratio reloads invalids namespace

---------- --------- ---------- --------- ---------- ---------- ---------

48475 0.9905518 273499 0.9975868 20 13 CRSR

5043 0.9569700 151734 0.9973045 0 0 TABL/PRCD/TYPE

4044 0.9943126 4051 0.9923476 0 0 BODY/TYBD

1 0.0000000 1 0.0000000 0 0 TRGR

29 0.0000000 29 0.0000000 0 0 INDX