Oracle Block

Oracle calls the smallest unit in which it stores and reads data a block (data block). It is the same concept as a page in other DBMSs. Contiguous blocks form an extent, and the extents occupied by one table or index make up a segment.

Key Specifications

ItemValue
Standard block sizeDB_BLOCK_SIZE, 8KB by default. Choose from 2, 4, 8, 16, 32KB
When it can be changedOnly when the database is created. It cannot be changed afterward
Non-standard block sizesA different size can be used per tablespace. A cache for that size (DB_nK_CACHE_SIZE) is required
Free space for updatesPCTFREE, 10 (%) by default
Transaction slotsINITRANS (1 by default for tables, 2 for indexes), grown from free space when needed
Row addressThe ROWID contains the block number and the row number within the block

Block Structure

Figure. Layout inside a data block

block-beta
  columns 6
  h["Block header<br/>address, block type, ITL transaction slots"]:6
  td["Table directory"]:2 rd["Row directory<br/>location of each row"]:4
  f["Free space (PCTFREE worth is kept for updates)"]:6
  r1["Row 3"]:2 r2["Row 2"]:2 r3["Row 1"]:2
  class h,td meta
  class rd slot
  class f free
  class r1,r2,r3 data

Diagram explanation: The Block header holds the block address and type, and the ITL slots, one of which each transaction modifying rows in this block occupies. The Row directory holds the location of each row in the block, so a row can be found directly from the row number in the ROWID. Row data fills from the end of the block, and the Free space between the header and the rows shrinks. When free space falls below PCTFREE, no new rows are inserted, and the space is used only for updates of existing rows.

Row Migration and Row Chaining

  • Row migration. If an update makes a row longer and the block has no room, the whole row moves to another block, and only the new location remains in the original place. The ROWID stays the same, so indexes need no change, but reading that row costs one more block read. Increase PCTFREE to reduce it.
  • Row chaining. If a single row is larger than a block, it is stored across several blocks. Rows with more than 255 columns are also split. Increase the block size, or store large values as LOB.

Configuration and Inspection

SELECT value FROM v$parameter WHERE name = 'db_block_size';
SELECT table_name, pct_free, ini_trans, blocks, num_rows, chain_cnt FROM user_tables;

-- Number of times migrated or chained rows were read
SELECT name, value FROM v$sysstat WHERE name = 'table fetch continued row';

-- Which file and block holds the row
SELECT dbms_rowid.rowid_relative_fno(rowid) AS file_no,
       dbms_rowid.rowid_block_number(rowid) AS block_no, id
FROM orders WHERE ROWNUM <= 5;

In the Articles

NOTE Default values may differ by version.

Related pages