Skip Headers
Oracle® Database Concepts
11g Release 2 (11.2)

Part Number E10713-02
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

12 Logical Storage Structures

This chapter describes the nature of and relationships among logical storage structures. These structures are created and recognized by Oracle Database and are not known to the operating system.

This chapter contains the following sections:

Introduction to Logical Storage Structures

Oracle Database allocates logical space for all data in the database. The logical units of database space allocation are data blocks, extents, segments, and tablespaces. At a physical level, the data is stored in data files on disk (see Chapter 11, "Physical Storage Structures"). The data in the data files is stored in operating system blocks.

Figure 12-1 is an entity-relationship diagram for physical and logical storage. The crow's foot notation represents a one-to-many relationship.

Figure 12-1 Logical and Physical Storage

Description of Figure 12-1 follows
Description of "Figure 12-1 Logical and Physical Storage"

Logical Storage Hierarchy

Figure 12-2 shows the relationships among data blocks, extents, and segments within a tablespace. In this example, a segment has two extents stored in different data files.

Figure 12-2 Segments, Extents, and Data Blocks Within a Tablespace

Description of Figure 12-2 follows
Description of "Figure 12-2 Segments, Extents, and Data Blocks Within a Tablespace"

At the finest level of granularity, Oracle Database stores data in data blocks. One logical data block corresponds to a specific number of bytes of physical disk space, for example, 2 KB. Data blocks are the smallest units of storage that Oracle Database can use or allocate.

An extent is a set of logically contiguous data blocks allocated for storing a specific type of information. In Figure 12-2, the 24 KB extent has 12 data blocks, while the 72 KB extent has 36 data blocks.

A segment is a set of extents allocated for a specific database object, such as a table. For example, the data for the employees table is stored in its own data segment, whereas each index for employees is stored in its own index segment. Every database object that consumes storage consists of a single segment.

Each segment belongs to one and only one tablespace. Thus, all extents for a segment are stored in the same tablespace. Within a tablespace, a segment can include extents from multiple data files, as shown in Figure 12-2. For example, one extent for a segment may be stored in users01.dbf, while another is stored in users02.dbf. A single extent can never span data files.

Logical Space Management

Oracle Database must use logical space management to track and allocate the extents in a tablespace. When a database object requires an extent, the database must have a method of finding and providing it. Similarly, when an object no longer requires an extent, the database must have a method of making the free extent available.

Oracle Database manages space within a tablespace based on the type that you create. You can create either of the following:

  • Locally managed tablespaces (default)

    The database uses bitmaps in the tablespaces themselves to manage extents. Thus, locally managed tablespaces have a part of the tablespace set aside for a bitmap. Within a tablespace, the database can manage segments with automatic segment-space management (ASSM) or manual segment-space management (MSSM).

  • Dictionary-managed tablespaces

    The database uses the data dictionary to manage extents (see "Overview of the Data Dictionary").

Figure 12-3 shows the alternatives for logical space management in a tablespace.

Figure 12-3 Logical Space Management

Description of Figure 12-3 follows
Description of "Figure 12-3 Logical Space Management"

Locally Managed Tablespaces

A locally managed tablespace maintains a bitmap in each data file to keep track of the free or used blocks in the data file. Each bit in the bitmap corresponds to a block or a group of blocks. When an extent is allocated or freed, Oracle Database changes the bitmap values to show the new status of the blocks.

A locally managed tablespace has the following advantages:

  • Avoids using the data dictionary to manage extents

    Recursive operations can occur in dictionary-managed tablespaces if consuming or releasing space in an extent results in another operation that consumes or releases space in a data dictionary table or undo segment.

  • Tracks adjacent free space automatically

    In this way, the database eliminates the need to coalesce free extents.

  • Determines the size of locally managed extents automatically

    Alternatively, all extents can have the same size in a locally managed tablespace and override object storage options.

Note:

Oracle strongly recommends the use of locally managed tablespaces with Automatic Segment Space Management.

Segment space management is an attribute inherited from the tablespace that contains the segment. Within a locally managed tablespace, the database can manage segments automatically or manually. For example, segments in tablespace users can be managed automatically while segments in tablespace tools are managed manually.

Automatic Segment-Space Management

The ASSM method uses bitmaps to manage space. Bitmaps provide the following advantages:

  • Simplified administration

    ASSM avoids the need to manually determine correct settings for many storage parameters. Only one crucial SQL parameter controls space allocation: PCTFREE. This parameter specifies the percentage of space to be reserved in a block for future updates (see "Percentage of Free Space in Data Blocks").

  • Increased concurrency

    Multiple transactions can search separate lists of free data blocks, thereby reducing contention and waits. For many standard workloads, application performance with ASSM is better than the performance of a well-tuned application that uses MSSM.

  • Dynamic affinity of space to instances in an Oracle Real Application Clusters (Oracle RAC) environment

ASSM is more efficient and is the default for permanent, locally managed tablespaces.

Note:

This chapter assumes the use of ASSM in all of its discussions of logical storage space.
Manual Segment-Space Management

The legacy MSSM method uses a linked list called a free list to manage free space in the segment. For database objects that have free space, a free list keeps track of blocks under the high water mark, which is the dividing line between segment space that is used and not yet used.

In addition to PCTFREE, MSSM requires you to control space allocation with SQL parameters such as PCTUSED, FREELISTS, and FREELIST GROUPS. For example, PCTUSED sets the percentage of free space that must exist in a currently used block for it to be free. For example, if you set PCTUSED to 40 in a CREATE TABLE statement, then a block in the segment for this table is unavailable for the insertion of new rows until the amount of used space falls below 40%.

You must adjust PCTFREE and PCTUSED to reduce row migration (see "Chained and Migrated Rows") and avoid wasting space. Because of the difficulty of fine-tuning space allocation parameters, Oracle recommends ASSM. In ASSM, PCTFREE determines whether a new row can be inserted into a block, but it does not use free lists and ignores PCTUSED.

See Also:

Dictionary-Managed Tablespaces

A dictionary-managed tablespace uses the data dictionary to manage its extents. Oracle Database updates tables in the data dictionary whenever an extent is allocated or freed for reuse. For example, when a table needs an extent, the database queries the data dictionary tables, and searches for free extents. If the database finds space, then it modifies one data dictionary table and inserts a row into another. In this way, the database manages space by modifying and moving data.

The SQL that the database executes in the background to obtain space for database objects is recursive SQL. Frequent use of recursive SQL can have a negative impact on performance because updates to the data dictionary must be serialized. Locally managed tablespaces, which are the default, avoid this performance problem.

See Also:

Oracle Database Administrator's Guide to learn how to migrate tablespaces from dictionary-managed to locally managed

Overview of Data Blocks

Oracle Database manages the logical storage space in the data files of a database in units called data blocks, also called logical blocks, Oracle blocks, or pages. An Oracle data block is the minimum unit of database I/O.

Data Blocks and Operating System Blocks

At the physical level, database data is stored in disk files made up of operating system blocks. An operating system block is the minimum unit of data that the operating system can read or write. In contrast, an Oracle data block is a logical storage structure whose size and structure are not known to the operating system.

Figure 12-4 shows that operating system blocks may differ in size from data blocks. The database requests data in multiples of data blocks, not operating system blocks.

Figure 12-4 Data Blocks and Operating System Blocks

Description of Figure 12-4 follows
Description of "Figure 12-4 Data Blocks and Operating System Blocks"

When the database requests a data block, the operating system translates this operation into a requests for data in permanent storage. The logical separation of data blocks from operating system blocks has the following implications:

  • Applications do not need to determine the physical addresses of data on disk.

  • Database data can be striped or mirrored on multiple physical disks.

Database Block Size

Every database has a database block size. The DB_BLOCK_SIZE initialization parameter sets the data block size for a database when it is created. The size is set for the SYSTEM and SYSAUX tablespaces and is the default for all other tablespaces. The database block size cannot be changed except by re-creating the database.

If DB_BLOCK_SIZE is not set, then the default data block size is operating system-specific. The standard data block size for a database is 4 KB or 8 KB. If the size differs for data blocks and operating system blocks, then the data block size must be a multiple of the operating system block size.

See Also:

Tablespace Block Size

You can create individual tablespaces whose block size differs from the DB_BLOCK_SIZE setting. A nonstandard block size can be useful when moving a transportable tablespace to a different platform.

See Also:

Oracle Database Administrator's Guide to learn how to specify a nonstandard block size for a tablespace

Data Block Format

Every Oracle data block has a format or internal structure that enables the database to track the data and free space in the block. This format is similar whether the data block contains table, index, or table cluster data. Figure 12-5 shows the format of an uncompressed data block (see "Data Block Compression" to learn about compressed blocks).

Figure 12-5 Data Block Format

Description of Figure 12-5 follows
Description of "Figure 12-5 Data Block Format"

Data Block Overhead

Oracle Database uses the block overhead to manage the block itself. The block overhead is not available to store user data. As shown in Figure 12-5, the block overhead includes the following parts:

  • Block header

    This part contains general information about the block, including disk address and segment type. For blocks that are transaction-managed, the block header contains active and historical transaction information.

    A transaction entry is required for every transaction that updates the block. Oracle Database initially reserves space in the block header for transaction entries. In data blocks allocated to segments that support transactional changes, free space can also hold transaction entries when the header space is depleted. The space required for transaction entries is operating system dependent. However, transaction entries in most operating systems require approximately 23 bytes.

  • Table directory

    For a heap-organized table, this directory contains metadata about tables whose rows are stored in this block. Multiple tables can store rows in the same block.

  • Row directory

    For a heap-organized table, this directory describes the location of rows in the data portion of the block.

    After space has been allocated in the row directory, the database does not reclaim this space after row deletion. Thus, a block that is currently empty but formerly had up to 50 rows continues to have 100 bytes allocated for the row directory. The database reuses this space only when new rows are inserted in the block.

Some parts of the block overhead are fixed in size, but the total size is variable. On average, the block overhead totals 84 to 107 bytes.

Row Format

The row data part of the block contains the actual data, such as table rows or index key entries. Just as every data block has an internal format, every row has a row format that enables the database to track the data in the row.

Oracle Database stores rows as variable-length records. A row is contained in one or more row pieces. Each row piece has a row header and column data.

Figure 12-6 shows the format of a row.

Figure 12-6 The Format of a Row Piece

Description of Figure 12-6 follows
Description of "Figure 12-6 The Format of a Row Piece"

Row Header

Oracle Database uses the row header to manage the row piece stored in the block. The row header contains information such as the following:

  • Columns in the row piece

  • Pieces of the row located in other data blocks

    If an entire row can be inserted into a single data block, then Oracle Database stores the row as one row piece. However, if all of the row data cannot be inserted into a single block or an update causes an existing row to outgrow its block, then the database stores the row in multiple row pieces (see "Chained and Migrated Rows"). A data block usually contains only one row piece per row.

  • Cluster keys for table cluster data (see "Overview of Table Clusters")

A row fully contained in one block has at least 3 bytes of row header.

Column Data

After the row header, the column data section stores the actual data in the row. The row piece usually stores columns in the order listed in the CREATE TABLE statement, but this order is not guaranteed. For example, columns of type LONG are created last.

As shown in Figure 12-6, for each column in a row piece, Oracle Database stores the column length and data separately. The space required depends on the data type. If the data type of a column is variable length, then the space required to hold a value can grow and shrink with updates to the data.

Each row has a slot in the row directory of the data block header. The slot points to the beginning of the row.

Rowid Format

Oracle Database uses a rowid to uniquely identify a row. Internally, the rowid is a structure that holds information that the database needs to access a row. A rowid is not physically stored in the database, but is inferred from the file and block on which the data is stored.

An extended rowid includes the data in the restricted rowid plus a data object number. This rowid type uses a base 64 encoding of the physical address for each row. The encoding characters are A-Z, a-z, 0-9, +, and /.

Example 12-1 queries the ROWID pseudocolumn to show the extended rowid of the row in the employees table for employee 100.

Example 12-1 ROWID Pseudocolumn

SQL> SELECT ROWID FROM employees WHERE employee_id = 100;
 
ROWID
------------------
AAAPecAAFAAAABSAAA

Figure 12-7 illustrates the format of an extended rowid.

An extended rowid is displayed in a four-piece format, OOOOOOFFFBBBBBBRRR, with the format divided into the following components:

  • OOOOOO

    The data object number identifies the segment (data object AAAPec in Example 12-1). A data object number is assigned to every database segment. Schema objects in the same segment, such as a cluster of tables, have the same data object number.

  • FFF

    The tablespace-relative data file number identifies the data file that contains the row (file AAF in Example 12-1).

  • BBBBBB

    The data block number identifies the block that contains the row (block AAAABS in Example 12-1). Block numbers are relative to their data file, not their tablespace. Thus, two rows with identical block numbers could reside in different data files of the same tablespace.

  • RRR

    The row number identifies the row in the block (row AAA in Example 12-1).

After a rowid is assigned to a row piece, the rowid can change in special circumstances. For example, if row movement is enabled, then the rowid can change because of partition key updates, Flashback Table operations, shrink table operations, and so on. If row movement is disabled, then a rowid can change if the row is exported and imported using Oracle Database utilities.

Note:

Internally, the database performs row movement as if the row were physically deleted and reinserted. However, row movement is considered an update, which has implications for triggers.

Data Block Compression

The database can use table compression to eliminate duplicate values in a data block (see "Table Compression"). This section describes the format of data blocks that use compression.

The format of a data block that uses basic and OLTP table compression is essentially the same as an uncompressed block. The difference is that a symbol table at the beginning of the block stores duplicate values for the rows and columns. The database replaces occurrences of these values with a short reference to the symbol table.

Assume that the rows in Example 12-2 are stored in a data block for the seven-column sales table.

Example 12-2 Rows in sales Table

2190,13770,25-NOV-00,S,9999,23,161
2225,15720,28-NOV-00,S,9999,25,1450
34005,120760,29-NOV-00,P,9999,44,2376
9425,4750,29-NOV-00,I,9999,11,979
1675,46750,29-NOV-00,S,9999,19,1121

When basic or OLTP table compression is applied to this table, the database replaces duplicate values with a symbol reference. Example 12-3 is a conceptual representation of the compression in which the symbol * replaces 29-NOV-00 and % replaces 9999.

Example 12-3 OLTP Compressed Rows in sales Table

2190,13770,25-NOV-00,S,%,23,161
2225,15720,28-NOV-00,S,%,25,1450
34005,120760,*,P,%,44,2376
9425,4750,*,I,%,11,979
1675,46750,*,S,%,19,1121

Table 12-1 is a conceptual representation of the symbol table that maps symbols to values.

Table 12-1 Symbol Table

Symbol Value Column Rows

*

29-NOV-00

3

958-960

%

9999

5

956-960


Space Management in Data Blocks

As the database fills a data block from the bottom up, the amount of free space between the row data and the block header decreases. This free space can also shrink during updates, as when changing a trailing null to a nonnull value. The database manages free space in the data block to optimize performance and avoid wasted space.

Note:

This section assumes the use of automatic segment-space management.

Percentage of Free Space in Data Blocks

The PCTFREE storage parameter is essential to how the database manages free space. This SQL parameter sets the minimum percentage of a data reserved as free space for updates to existing rows. Thus, PCTFREE is important for preventing row migration and avoiding wasted space.

For example, assume that you create a table that will require only occasional updates, most of which will not increase the size of the existing data. You specify the PCTFREE parameter within a CREATE TABLE statement as follows:

CREATE TABLE test_table (n NUMBER) PCTFREE 20;

Figure 12-8 shows how a PCTFREE setting of 20 affects space management. The database adds rows to the block over time, causing the row data to grow upwards toward the block header, which is itself expanding downward toward the row data. The PCTFREE setting ensures that at least 20% of the data block is free. For example, the database prevents an insert from filling the block so that the row data and header occupy a combined 90% of the total block space, leaving only 10% free.

Note:

This discussion does not apply to LOB data types, which do not use the PCTFREE storage parameter or free lists. See "Overview of LOBs".

See Also:

Oracle Database SQL Language Reference for the syntax and semantics of the PCTFREE parameter

Optimization of Free Space in Data Blocks

While the percentage of free space cannot be less than PCTFREE, the amount of free space can be greater. For example, a PCTFREE setting of 20% prevents the total amount of free space from dropping to 5% of the block, but permits 50% of the block to be free space. The following SQL statements can increase free space:

  • DELETE statements

  • UPDATE statements that either update existing values to smaller values or increase existing values and force a row to migrate

  • INSERT statements on a table that uses OLTP compression

    If inserts fill a block with data, then the database invokes block compression, which may result in the block having more free space.

The space released is available for INSERT statements under the following conditions:

  • If the INSERT statement is in the same transaction and after the statement that frees space, then the statement can use the space.

  • If the INSERT statement is in a separate transaction from the statement that frees space (perhaps run by another user), then the statement can use the space made available only after the other transaction commits and only if the space is needed.

See Also:

Oracle Database Administrator's Guide to learn about OLTP compression
Coalescing Fragmented Space

Released space may or may not be contiguous with the main area of free space in a data block, as shown in Figure 12-9. Noncontiguous free space is called fragmented space.

Figure 12-9 Data Block with Fragmented Space

Description of Figure 12-9 follows
Description of "Figure 12-9 Data Block with Fragmented Space"

Oracle Database automatically and transparently coalesces the free space of a data block only when the following conditions are true:

  • An INSERT or UPDATE statement attempts to use a block that contains sufficient free space to contain a new row piece.

  • The free space is fragmented so that the row piece cannot be inserted in a contiguous section of the block.

After coalescing, the amount of free space is identical to the amount before the operation, but the space is now contiguous. Figure 12-10 shows a data block after space has been coalesced.

Figure 12-10 Data Block After Coalescing Free Space

Description of Figure 12-10 follows
Description of "Figure 12-10 Data Block After Coalescing Free Space"

Oracle Database performs coalescing only in the preceding situations because otherwise performance would decrease because of the continuous coalescing of the free space in data blocks.

Reuse of Index Space

The database can reuse space within an index block. For example, if you insert a value into a column and delete it, and if an index exists on this column, then the database can reuse the index slot when a row requires it.

The database can reuse an index block itself. Unlike a table block, an index block only becomes free when it is empty. The database places the empty block on the free list of the index structure and makes it eligible for reuse. However, Oracle Database does not automatically compact the index: an ALTER INDEX REBUILD or COALESCE statement is required.

Figure 12-11 represents an index of the employees.department_id column before the index is coalesced. The first three leaf blocks are only partially full, as indicated by the gray fill lines.

Figure 12-11 Index Before Coalescing

Description of Figure 12-11 follows
Description of "Figure 12-11 Index Before Coalescing"

Figure 12-12 shows the index in Figure 12-11 after the index has been coalesced. The first two leaf blocks are now full, as indicated by the gray fill lines, and the third leaf block has been freed.

Figure 12-12 Index After Coalescing

Description of Figure 12-12 follows
Description of "Figure 12-12 Index After Coalescing"

See Also:

Chained and Migrated Rows

Oracle Database must manage rows that are too large to fit into a single block. The following situations are possible:

  • The row is too large to fit into one data block when it is first inserted.

    In row chaining, Oracle Database stores the data for the row in a chain of one or more data blocks reserved for the segment. Row chaining most often occurs with large rows. Examples include rows that contain a column of data type LONG or LONG RAW, a VARCHAR2(4000) column in a 2 KB block, or a row with a huge number of columns. Row chaining in these cases is unavoidable.

  • A row that originally fit into one data block is updated so that the overall row length increases, but insufficient free space exists to hold the updated row.

    In row migration, Oracle Database moves the entire row to a new data block, assuming the row can fit in a new block. The original row piece of a migrated row contains a pointer or "forwarding address" to the new block containing the migrated row. The rowid of a migrated row does not change.

  • A row has more than 255 columns.

    Oracle Database can only store 255 columns in a row piece. Thus, if you insert a row into a table that has 1000 columns, then the database creates 4 row pieces, typically chained over multiple blocks.

Figure 12-13 depicts the difference between chaining and migration.

Figure 12-13 Row Chaining and Migration

Description of Figure 12-13 follows
Description of "Figure 12-13 Row Chaining and Migration"

When a row is chained or migrated, the amount of I/O necessary to retrieve the data increases. This situation results because Oracle Database must scan multiple blocks to retrieve the information for the row. For example, if the database performs one I/O to read an index and one I/O to read a nonmigrated table row, then an additional I/O is required to obtain the data for a migrated row.

The Segment Advisor, which can be run both manually and automatically, is an Oracle Database component that identifies segments that have space available for reclamation. The advisor can offer advice about objects that have significant free space or too many chained rows.

See Also:

Overview of Extents

An extent is a logical unit of database storage space allocation made up of contiguous data blocks. Data blocks in an extent are logically contiguous but can be physically spread out on disk because of RAID striping and file system implementations.

Allocation of Extents

By default, the database allocates an initial extent for a data segment when the segment is created. An extent is always contained in one data file.

Although no data has been added to the segment, the data blocks in the initial extent are reserved for this segment exclusively. The first data block of every segment contains a directory of the extents in the segment. Figure 12-14 shows the initial extent in a segment in a data file that previously contained no data.

Figure 12-14 Initial Extent of a Segment

Description of Figure 12-14 follows
Description of "Figure 12-14 Initial Extent of a Segment"

If the initial extent become full, and if more space is required, then the database automatically allocates an incremental extent for this segment. An incremental extent is a subsequent extent created for the segment.

The allocation algorithm depends on whether the tablespace is locally managed or dictionary-managed. In the locally managed case, the database searches the bitmap of a data file for adjacent free blocks. If the data file has insufficient space, then the database looks in another data file. Extents for a segment are always in the same tablespace but may be in different data files.

Figure 12-15 shows that the database can allocate extents for a segment in any data file in the tablespace. For example, the segment can allocate the initial extent in users01.dbf, allocate the first incremental extent in users02.dbf, and allocate the next extent in users01.dbf.

Figure 12-15 Incremental Extent of a Segment

Description of Figure 12-15 follows
Description of "Figure 12-15 Incremental Extent of a Segment"

The blocks of a newly allocated extent, although they were free, may not be empty of old data. In ASSM, Oracle Database formats the blocks of a newly allocated extent when it starts using the extent, but only as needed (see "ASSM and the High Water Mark").

Note:

This section applies to serial operations, in which one server process parses and runs a statement. Extents are allocated differently in parallel SQL statements, which entail multiple server processes.

See Also:

Oracle Database Administrator's Guide to learn how to manually allocate extents

Deallocation of Extents

In general, the extents of a user segment do not return to the tablespace unless the object is dropped. For example, if you delete all rows in a table, then Oracle Database does not reclaim the data blocks for use by other objects in the tablespace.

Note:

In an undo segment, Oracle Database periodically deallocates one or more extents if it has the OPTIMAL size specified or if the database is in automatic undo management mode (see "Undo Tablespaces").

In some circumstances, you can manually deallocate space. The Oracle Segment Advisor helps determine whether an object has space available for reclamation based on the level of fragmentation in the object. The following techniques can free extents:

  • You can use an online segment shrink to reclaim fragmented space in a segment. Segment shrink is an online, in-place operation. In general, data compaction leads to better cache utilization and requires fewer blocks to be read in a full table scan.

  • You can move the data of a nonpartitioned table or table partition into a new segment, and optionally into a different tablespace for which you have quota.

  • You can rebuild or coalesce the index (see "Reuse of Index Space").

  • You can truncate a table or table cluster, which removes all rows. By default, Oracle Database deallocates all space used by the removed rows except that specified by the MINEXTENTS storage parameter.

  • You can deallocate unused space, which frees the unused space at the high water mark end of the database segment and makes the space available for other segments in the tablespace (see "ASSM and the High Water Mark").

When extents are freed, Oracle Database modifies the bitmap in the data file for locally managed tablespaces to reflect the regained extents as available space. Any data in the blocks of freed extents becomes inaccessible.

See Also:

Oracle Database Administrator's Guide for guidelines on reclaiming segment space

Storage Parameters for Extents

Every segment is defined by storage parameters expressed in terms of extents. These parameters control how Oracle Database allocates free space for a segment.

The storage settings are determined in the following order of precedence, with setting higher on the list overriding settings lower on the list:

  1. Segment storage clause

  2. Tablespace storage clause

  3. Oracle Database default

A locally managed tablespace can have either uniform extent sizes or variable extent sizes determined automatically by the system:

  • For uniform extents, you can specify an extent size or use the default size of 1 MB. All extents in the tablespace are of this size. Locally managed temporary tablespaces can only use this type of allocation.

  • For automatically allocated extents, Oracle Database determines the optimal size of additional extents, with a minimum extent size of 64 KB.

For locally managed tablespaces, some storage parameters cannot be specified at the tablespace level. However, you can specify these parameters at the segment level. In this case, the databases uses all parameters together to compute the initial size of the segment. Internal algorithms determine the subsequent size of each extent.

See Also:

Overview of Segments

A segment is a set of extents that contains all the data for a logical storage structure within a tablespace. For example, Oracle Database allocates one or more extents to form the data segment for a table. The database also allocates one or more extents to form the index segment for a table.

As explained in "Logical Space Management", Oracle Database manages segment space automatically or manually. This section assumes the use of ASSM.

User Segments

A single data segment in a database stores the data for one user object. There are different types of segments. Examples of user segments include:

  • Table, table partition, or table cluster

  • LOB or LOB partition

  • Index or index partition

Each nonpartitioned object and object partition is stored in its own segment. For example, if an index has five partitions, then five segments contain the index data.

User Segment Creation

By default, Oracle Database creates a user segment when you create a user object with a CREATE statement. For example, Oracle Database creates a segment for a table, table cluster, index, or materialized view.

The database allocates one or more extents when the segment is created. Storage parameters for the object determine how the extents for each segment are allocated (see "Storage Parameters for Extents"). The parameters affect the efficiency of data retrieval and storage for the data segment associated with the object.

For example, assume that you create a table as follows:

CREATE TABLE test_table (my_column NUMBER);

As shown in Figure 12-16, the data for the preceding table is stored in one segment.

Figure 12-16 Creation of a User Segment

Description of Figure 12-16 follows
Description of "Figure 12-16 Creation of a User Segment"

When you create a table with a primary key or unique key, Oracle Database automatically creates an index for this key. Thus, a single CREATE TABLE statement can create multiple segments. For example, suppose you create a table as follows:

CREATE TABLE lob_table (my_column NUMBER PRIMARY KEY, clob_column CLOB);

Figure 12-17 shows that the data for lob_table is stored in one segment, while the implicitly created index is in a different segment. Also, the CLOB data is stored in its own segment, as is its associated CLOB index (see "Internal Lobs"). Thus, the statement results in the creation of four different segments.

Figure 12-17 Multiple Segments

Description of Figure 12-17 follows
Description of "Figure 12-17 Multiple Segments"

Note:

The segments of a table and the index for this table do not have to occupy the same tablespace.

In some cases, installation of an application can create thousands of objects, consuming significant disk space. Many of these objects may never be used. By default, the database uses delayed segment creation to update only database metadata when creating nonpartitioned tables and indexes, avoiding the initial creation of user segments. When a user inserts the first row into a table, the database creates segments for the table, its LOB columns, and its indexes.

See Also:

Temporary Segments

When processing a query, Oracle Database often requires temporary workspace for intermediate stages of SQL statement execution. Typical operations that may require a temporary segment include sorting, hashing, and merging bitmaps. While creating an index, Oracle Database also places index segments into temporary segments and then converts them into permanent segments when the index is complete.

Oracle Database does not create a temporary segment if an operation can be performed in memory. However, if memory use is not possible, then the database automatically allocates a temporary segment on disk.

Allocation of Temporary Segments for Queries

Oracle Database allocates temporary segments for queries as needed during a user session and drops them when the query completes. Changes to temporary segments are not recorded in the online redo log, except for space management operations on the temporary segment (see "Overview of the Online Redo Log").

The database creates temporary segments in the temporary tablespace assigned to the user. The default storage characteristics of the tablespace determine the characteristics of the extents in the temporary segment. Because allocation and deallocation of temporary segments occurs frequently, the best practice is to create at least one special tablespace for temporary segments. The database distributes I/O across disks and avoids fragmenting SYSTEM and other tablespaces with temporary segments.

Note:

When SYSTEM is locally managed, you must define a default temporary tablespace at database creation. A locally managed SYSTEM tablespace cannot be used for default temporary storage.

See Also:

Allocation of Temporary Segments for Temporary Tables and Indexes

Oracle Database can also allocate temporary segments for temporary tables and their indexes. Temporary tables hold data that exists only for the duration of a transaction or session. Each session accesses only the extents allocated for the session and cannot access extents allocated for other sessions.

Oracle Database allocates segments for a temporary table when the first INSERT into that table occurs. The insert can occur explicitly or because of CREATE TABLE AS SELECT. The first INSERT into a temporary table allocates the segments for the table and its indexes, creates the root page for the indexes, and allocates any LOB segments.

Segments for a temporary table are allocated in a temporary tablespace of the current user. Assume that the temporary tablespace assigned to user1 is temp1 and the temporary tablespace assigned to user2 is temp2. In this case, user1 stores temporary data in the temp1 segments, while user2 stores temporary data in the temp2 segments.

See Also:

Undo Segments

Oracle Database maintains records of the actions of transactions, collectively known as undo data. Oracle Database uses undo to do the following:

  • Roll back an active transaction

  • Recover a terminated transaction

  • Provide read consistency

  • Perform some logical flashback operations

Oracle Database stores undo data inside the database rather than in external logs. Undo is stored in blocks that are updated just like data blocks, with changes to these blocks generating redo. In this way, Oracle Database can efficiently access undo data without having to read external logs.

Undo is stored in an undo tablespace. The database manages data within an undo tablespace using undo segments that are automatically created and maintained.

When the first DML is run in a transaction, the database binds (assigns) the transaction to an undo segment, and therefore to a transaction table, in the current undo tablespace. In rare circumstances, if the instance does not have a designated undo tablespace, the transaction binds to the system undo segment.

When a ROLLBACK statement is issued, undo records are used to undo changes made to the database by the uncommitted transaction. During recovery, undo records are used to undo any uncommitted changes applied from the redo log to the data files. Undo records also provide read consistency by maintaining the before image of the data for users accessing data at the same time that another user is changing it.

Oracle Database provides a fully automated mechanism, known as automatic undo management mode, for managing undo segments and space in an undo tablespace.

See Also:

Oracle Database 2 Day DBA and Oracle Database Administrator's Guide to learn how to manage undo

ASSM and the High Water Mark

To manage space, Oracle Database tracks the state of blocks in the segment. Every data block is in one of the following states:

  • Formatted

  • Unformatted

  • Unknown

MSSM uses free lists to manage segment space. At table creation, no blocks in the segment are formatted. When a user first inserts rows into the table, the database searches the free list for usable blocks. If the database finds no usable blocks, then it preformats a group of blocks, places them on the free list, and begins inserting data into the blocks. The high water mark (HWM) is the point in a segment beyond which data blocks are unformatted and have never been used. In MSSM, a full table scan reads all blocks below the HWM.

ASSM does not use free lists and so must manage space differently. When a session first inserts data into a table, the database formats a single bitmap block instead of preformatting a group of blocks as in MSSM. The bitmap tracks the state of blocks in the segment, taking the place of the free list. The database uses the bitmap to find free blocks and then formats each block before filling it with data.

Figure 12-18 depicts an ASSM segment as a horizontal series of blocks. At table creation, the HWM is at the beginning of the segment on the left. Because no data has been inserted yet, all blocks in the segment are unformatted.

Figure 12-18 HWM at Table Creation

Description of Figure 12-18 follows
Description of "Figure 12-18 HWM at Table Creation"

Suppose that a transaction inserts rows into the segment. The database must allocate a group of blocks to hold the rows. The database formats a bitmap block in this group to hold the metadata but does not preformat the remaining blocks in the group.

In Figure 12-19, the blocks below the HWM are allocated for the transaction, whereas blocks above the HWM have not been allocated and so are known to be unformatted. As the inserts occur, the database proceeds from block to block, formatting and filling each with data. The low high water mark (low HWM) marks the point below which all blocks are known to be already formatted because they contain data.

Figure 12-19 HWM and Low HWM

Description of Figure 12-19 follows
Description of "Figure 12-19 HWM and Low HWM"

The low HWM is important during a full table scan, when the database must scan the table up to the HWM and avoid reading unformatted blocks. Because blocks between the HWM and the low HWM are in an unknown state, the database reads the bitmap block to obtain the location of the low HWM and reads all blocks below this point.

Assume that a new transaction inserts rows into the table, but the bitmap indicates that insufficient free space exists under the HWM. In Figure 12-20, the database advances the HWM to the right, allocating a new group of unformatted blocks.

Figure 12-20 Advancing HWM and Low HWM

Description of Figure 12-20 follows
Description of "Figure 12-20 Advancing HWM and Low HWM"

When the blocks between the HWM and low HWM are full, the HWM advances to the right and the low HWM advances to the location of the old HWM. As the database inserts data over time, the HWM continues to advance to the right, with the low HWM always trailing behind it. Unless you manually rebuild, truncate, or shrink the object, the HWM never retreats.

See Also:

Overview of Tablespaces

A database has two or more logical storage units called tablespaces. A tablespace is logical storage container for segments. Segments are database objects, such as tables and indexes, that consume storage space.

Use of Tablespaces

A tablespace groups related schema objects together. A very small database may need only the default SYSTEM and SYSAUX tablespaces. However, Oracle recommends that you create at least one tablespace to store user data.

You can use tablespaces to achieve the following goals:

  • Control disk space allocation for database data

  • Assign a quota (space allowance or limit) to a database user

  • Take individual tablespaces online or offline without affecting the availability of the whole database

  • Perform backup and recovery of individual tablespaces

  • Import or export application data by using the Oracle Data Pump utility (see "Oracle Data Pump Export and Import")

  • Create a transportable tablespace that you can copy or move from one database to another, even across platforms

    Moving data by transporting tablespaces can be orders of magnitude faster than either export/import or unload/load of the same data, because transporting a tablespace involves only copying data files and integrating the tablespace metadata. When you transport tablespaces you can also move index data.

See Also:

Tablespace Characteristics

Oracle Database enables you to control various characteristics of tablespaces. As explained in "Logical Space Management", one characteristic of a tablespace is whether it is locally managed or dictionary-managed. This section describes other important characteristics.

Smallfile and Bigfile Tablespaces

A tablespace is either a bigfile or a smallfile tablespace. The tablespaces are indistinguishable in terms of execution of SQL statements that do not explicitly refer to data files. The difference is as follows:

  • A smallfile tablespace can contain multiple data files or temp files, but the files cannot be as large as in bigfile tablespaces. This is the default tablespace type.

  • A bigfile tablespace contains one very large data file or temp file. This type of tablespaces can do the following:

    • Increase the storage capacity of a database

      The maximum number of data files in a database is limited (usually to 64 KB files), so increasing the size of each data file increases the overall storage.

    • Reduce the burden of managing many data files

      Bigfile tablespaces simplify data file management with Oracle-managed files and Automatic Storage Management by eliminating the need for adding new data files and dealing with multiple files.

    • Perform operations on tablespaces rather than data files

      Bigfile tablespaces make the tablespace the main unit of the disk space administration, backup and recovery, and so on.

    Bigfile tablespaces are supported only for locally managed tablespaces with ASSM. However, locally managed undo and temporary tablespaces can be bigfile tablespaces even though segments are manually managed.

See Also:

Read/Write and Read-Only Tablespaces

Every tablespace is in a write mode that specifies whether it can be written to. The mutually exclusive modes are as follows:

  • Read/write mode

    Users can read and write to the tablespace. All tablespaces are initially created as read/write.

  • Read-only mode

    Write operations to the data files in the tablespace are prevented. A read-only tablespace can reside on read-only media such as DVDs or WORM drives.

    Read-only tablespaces eliminate the need to perform backup and recovery of large, static portions of a database. Read-only tablespaces do not change and thus do not require repeated backup. If you recover a database after a media failure, then you do not need to recover read-only tablespaces.

See Also:

Online and Offline Tablespaces

Any tablespace other than the SYSTEM tablespace can be online (accessible) or offline (not accessible) whenever the database is open. A tablespace is usually online so that its data is available to users.

A tablespace can go offline manually or automatically. For example, a database administrator can take a tablespace offline for maintenance or backup and recovery. The database automatically takes a tablespace offline when certain errors are encountered, as when the database writer (DBWn) process fails in several attempts to write to a data file of the tablespace. Users trying to access tables in the offline tablespace receive an error.

When a tablespace goes offline, the database does the following:

  • The database does not permit subsequent DML statements to reference objects in the offline tablespace. An offline tablespace cannot be read or edited by any utility other than Oracle Database.

  • Active transactions with completed statements that refer to data in that tablespace are not affected at the transaction level.

  • The database saves undo data corresponding to those completed statements in a deferred undo segment in the SYSTEM tablespace. When the tablespace is brought online, the database applies the undo data to the tablespace, if needed.

System Tablespaces

The SYSTEM and SYSAUX tablespaces are part of every database. These tablespaces are automatically created when the database is created.

The SYSTEM Tablespace

Oracle Database uses the SYSTEM tablespace to manage the database. This tablespace includes the following information, all owned by the SYS user:

  • The data dictionary

  • Tables and views that contain administrative information about the database

  • Compiled stored objects such as triggers, procedures, and packages

The SYSTEM tablespace is managed as any other tablespace, but requires a higher level of privilege and is restricted in some ways. For example, you cannot rename or drop the SYSTEM tablespace or take it offline.

By default, Oracle Database sets all newly created user tablespaces to be locally managed. In a database with a locally managed SYSTEM tablespace, dictionary-managed tablespaces (which are deprecated) cannot be created. However, if you execute the CREATE DATABASE statement manually and accept the defaults, then the SYSTEM tablespace is dictionary managed. You can migrate an existing dictionary-managed SYSTEM tablespace to a locally managed format.

Note:

Oracle strongly recommends that you use Database Configuration Assistant (DBCA) to create new databases so that all tablespaces, including SYSTEM, are locally managed by default.

See Also:

The SYSAUX Tablespace

The SYSAUX tablespace is an auxiliary tablespace to the SYSTEM tablespace. The SYSAUX tablespace provides a centralized location for database metadata that does not reside in the SYSTEM tablespace. It reduces the number of tablespaces created by default, both in the seed database and in user-defined databases.

Several database components, including Oracle Enterprise Manager and Oracle Streams, use the SYSAUX tablespace as their default storage location. Therefore, the SYSAUX tablespace is created during database creation or upgrade.

During normal database operation, the database does not allow the SYSAUX tablespace to be dropped or renamed. If the SYSAUX tablespace becomes unavailable, then core database functionality remains operational. The database features that use the SYSAUX tablespace could fail, or function with limited capability.

See Also:

Oracle Database Administrator's Guide to learn about the SYSAUX tablespace

Undo Tablespaces

An undo tablespace is a locally managed tablespace reserved for system-managed undo data (see "Undo Segments"). Like other permanent tablespaces, undo tablespaces contain data files. Undo blocks in these files are grouped in extents.

Automatic Undo Management Mode

Undo tablespaces require the database to be in the default automatic undo management mode. This mode eliminates the complexities of manually administering undo segments. The database automatically tunes itself to provide the best possible retention of undo data to satisfy long-running queries that may require this data.

An undo tablespace is automatically created with a new installation of Oracle Database. Earlier versions of Oracle Database may not include an undo tablespace and use legacy rollback segments instead, known as manual undo management mode. When upgrading to Oracle Database 11g, you can enable automatic undo management mode and create an undo tablespace. Oracle Database contains an Undo Advisor that provides advice on and helps automate your undo environment.

A database can contain multiple undo tablespaces, but only one can be in use at a time. When an instance attempts to open a database, Oracle Database automatically selects the first available undo tablespace. If no undo tablespace is available, then the instance starts without an undo tablespace and stores undo records in the SYSTEM tablespace. Storing undo in SYSTEM is not recommended.

See Also:

Automatic Undo Retention

The undo retention period is the minimum amount of time that Oracle Database attempts to retain old undo data before overwriting it. Undo retention is important because long-running queries may require older block images to supply read consistency. Also, some Oracle Flashback features can depend on undo availability.

In general, it is desirable to retain old undo data as long as possible. After a transaction commits, undo data is no longer needed for rollback or transaction recovery. The database can retain old undo data if the undo tablespace has space for new transactions. When available space is low, the database begins to overwrite old undo data for committed transactions.

Oracle Database automatically provides the best possible undo retention for the current undo tablespace. The database collects usage statistics and tunes the retention period based on these statistics and the undo tablespace size. If the undo tablespace is configured with the AUTOEXTEND option, and if the maximum size not specified, then undo retention tuning is different. In this case, the database tunes the undo retention period to be slightly longer than the longest-running query, if space allows.

See Also:

Oracle Database Administrator's Guide for more details on automatic tuning of undo retention

Temporary Tablespaces

A tablespace is either permanent or temporary. The difference is:

  • A permanent tablespace contains persistent schema objects.

    You use permanent tablespaces to store user and application data. Each user is assigned a default permanent tablespace. Objects in permanent tablespaces are stored in data files.

  • A temporary tablespace contains transient data that persists only for the duration of a session.

    A temporary tablespace is not the same as a permanent tablespace that a user designates for temporary segments. No permanent schema objects can reside in a temporary tablespace. Data in a temporary tablespace is stored in temp files.

Temporary tablespaces can improve the concurrency of multiple sort operations that do not fit in memory. These tablespaces also improve the efficiency of space management operations during sorts.

Default Temporary Tablespace

When the SYSTEM tablespace is locally managed, a default temporary tablespace is included in the database by default during database creation. A locally managed SYSTEM tablespace cannot be used for default temporary storage.

Note:

You cannot make a default temporary tablespace permanent or take it offline.

You can specify a user-named default temporary tablespace when you create a database by using the DEFAULT TEMPORARY TABLESPACE extension to the CREATE DATABASE statement. If SYSTEM is dictionary managed, and if a default temporary tablespace is not defined at database creation, then SYSTEM is the default temporary storage. However, the database writes a warning in the alert log saying that a default temporary tablespace is recommended.

See Also: