Overview

Oracle stores data in a logical hierarchy that maps onto files: blocks (default 8 KB) form extents, extents form segments (a table, an index, a partition, an undo or temp segment), and segments live in tablespaces, which consist of data files.

Core concepts

  • Tablespaces: SYSTEM and SYSAUX (dictionary and components), UNDOTBS1 (undo, oracle-redo-undo), TEMP (sorts, hashes, global temporary tables), USERS (default for user data). Create separate tablespaces for application data and indexes only if you have a reason (I/O isolation, quotas, transport).
  • Locally managed tablespaces with automatic segment space management (ASSM) are the default; extents are tracked in the data file header, not the dictionary. AUTOALLOCATE sizes extents automatically (64 KB growing to 1 MB, 8 MB, 64 MB); UNIFORM uses a fixed size.
  • Big file tablespaces use a single large file; small file ones allow several. Files can auto-extend; set a maximum.
  • High-water mark (HWM): the boundary beyond which blocks have never been used. Full table scans read up to the HWM, even after rows are deleted; ALTER TABLE ... SHRINK SPACE or MOVE lowers it.
  • PCTFREE reserves space in each block for row growth from updates; rows that no longer fit are migrated or chained.
  • Oracle Managed Files (OMF) and ASM (Automatic Storage Management, a volume manager and file system for Oracle files) simplify file placement in larger installations.

Worked example

A table of 500,000 rows (avg. row length 129 bytes) in USERS, after loading with INSERT /*+ APPEND */:

SELECT segment_name, segment_type, blocks, ROUND(bytes/1024/1024,1) mb, extents
FROM user_segments ORDER BY 1;
-- ORDERS        TABLE   10240   80 MB   81 extents
-- SYS_C008928   INDEX    1024    8 MB   23 extents   (primary key)
 
SELECT num_rows, blocks, avg_row_len FROM user_tables WHERE table_name = 'ORDERS';
-- 500000 | 9579 | 129

The segment holds 10,240 blocks of which 9,579 are below the high-water mark with data (the statistics BLOCKS value); a full scan of the table later cost 9,443 buffer gets (oracle-execution-plans). The 81 extents show AUTOALLOCATE growing extents from 64 KB to 1 MB.

Pitfalls and production notes

  • Space is not returned by DELETE. After deleting most rows, shrink or move the segment, or partition and drop partitions (oracle-partitioning).
  • Undo and temp tablespaces can fill with a runaway query; monitor DBA_TABLESPACE_USAGE_METRICS and set alerts.
  • Do not store application data in SYSTEM or SYSAUX.
  • Use AUTOEXTEND ON with a MAXSIZE so a runaway load cannot fill the disk silently.
  • Compare to PostgreSQL pages and TOAST (pg-architecture) and SQL Server files and filegroups (sqlserver-storage-tempdb).

Practice questions

  1. Why does a full scan of a table that has just had 90% of its rows deleted stay slow?
  2. What does PCTFREE protect against?
  3. How do locally managed tablespaces avoid dictionary contention?

References

  • Oracle Database Concepts, Logical Storage Structures; Physical Storage Structures

oracle-architecture · oracle-redo-undo · oracle-partitioning · sqlserver-storage-tempdb