Better At Oracle

A collection of tutorials, code and tools to help you get better using Oracle


01 February 2012

Dumping Blocks

Dumping blocks can be useful when debugging strange problems or when trying to understand how Oracle works under the covers.

Dumping Table Blocks

select DBMS_ROWID.ROWID_OBJECT(chartorowid('AAAsfQAAEAAB2g4AAA')) "OBJECT",
       DBMS_ROWID.ROWID_RELATIVE_FNO(chartorowid('AAAsfQAAEAAB2g4AAA')) "FILE",
       DBMS_ROWID.ROWID_BLOCK_NUMBER(chartorowid('AAAsfQAAEAAB2g4AAA')) "BLOCK",
       DBMS_ROWID.ROWID_ROW_NUMBER(chartorowid('AAAsfQAAEAAB2g4AAA')) "ROW"
from dual;

Then to dump the block:

alter system dump datafile <FILE ABOVE> block <BLOCK ABOVE>;

If you simply have a block number, for instance from a wait event

select dbms_utility.data_block_address_file(25184092) file, 
            dbms_utility.data_block_address_block(25184092) block
from dual;

alter system dump datafile <FILE ABOVE> block <BLOCK ABOVE>;

Dumping Index Blocks

To dump the entire set of blocks in an index (but not their contents), first find the index object ID:

select owner, object_id
from dba_objects where object_name = 'T_IDX1';

Then use the object_id in the following command to dump the index tree:

alter session set events 'immediate trace name treedump level <OBJECT_ID>';

You may then be interested in the contents of one of the index blocks. The end of the index tree dump looks like:

  leaf: 0x180475d 25184093 (430: nrow: 122 rrow: 122)
  leaf: 0x1804760 25184096 (431: nrow: 113 rrow: 113)
  leaf: 0x180475a 25184090 (432: nrow: 206 rrow: 206)
  leaf: 0x1804759 25184089 (433: nrow: 204 rrow: 204)
  leaf: 0x180475c 25184092 (434: nrow: 194 rrow: 194)
----- end tree dump

The numbers beginning 251 are the block numbers. To dump the contents of the block, you need to translate the block number into the file and block address:

select dbms_utility.data_block_address_file(25184092) file, 
            dbms_utility.data_block_address_block(25184092) block
from dual;

alter system dump datafile <file> block <block>;

Dumping a Range of Blocks

To dump a range of blocks specify the min and max blocks in the range:

alter system dump datafile 4 block min 485432 block max 485434;
blog comments powered by Disqus