Oracle segment management manual




















When set to automatic, Oracle uses bitmaps to manage the free space within segments. Automatic segment-space management is a simpler and more efficient way of managing space within a segment. In a locally managed tablespace, there are two methods that Oracle Database can use to manage segment space: automatic and manual. Automatic segment space management ASSM, or bitmap freelists is a simpler and more efficient way of managing space within a segment. It completely eliminates any need to specify and tune the pctused, freelists, and freelist groups storage parameters for schema objects created in the tablespace.

Tablespace is the primary logic structure of the oracle database. It consists of one or more physical datafiles. For this reason the High Water Mark has been split in two:. If different the blocks between them may or maynot be formated for use. The HHWM is neccessary so that direct load operation can guarantee contiguous unformated blocks.

Any object within this tablespace will take advantage of this feature. 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 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 users The blocks of a newly allocated extent, although they were free, may not be empty of old data.

In general, the extents of a user segment do not return to the tablespace unless you drop the object using a DROP command. In Oracle Database 11 g Release 2 For example, if you delete all rows in a table, then the database does not reclaim the data blocks for use by other objects in the tablespace. 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 truncate a table or table cluster, which removes all rows. 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 "Segment Space 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.

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:. 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. 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. Oracle Database Administrator's Guide to learn about extent management considerations when creating a locally managed tablespace.

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. 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:. 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. By default, the database uses deferred segment creation to update only database metadata when creating tables and indexes.

Starting in Oracle Database 11 g Release 2 When a user inserts the first row into a table or partition, the database creates segments for the table or partition, its LOB columns, and its indexes. Deferred segment creation enables you to avoid using database resources unnecessarily. For example, installation of an application can create thousands of objects, consuming significant disk space. Many of these objects may never be used.

Starting with Oracle Database 11 g Release 2 To best illustrate the relationship between object creation and segment creation, assume that deferred segment creation is disabled. You create a table as follows:. As shown in Figure , the database creates one segment for the table. When you create a table with a primary key or unique key, Oracle Database automatically creates an index for this key. Again assume that deferred segment creation is disabled.

The database allocates one or more extents when a 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. Oracle Database Administrator's Guide to learn how to manage deferred segment creation. Oracle Database Advanced Replication for information on materialized views and materialized view logs.

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. Oracle Database allocates temporary segments for queries as needed during a use r 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.

Oracle Database Administrator's Guide to learn how to create temporary tablespaces. 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. 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. Oracle Database Administrator's Guide to learn how to create temporary tables. 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. Oracle Database stores undo data inside the database rather than in external logs. Undo data 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 needing to read external logs. Undo data is stored in an undo tablespace.

Oracle Database provides a fully automated mechanism, known as automatic undo management mode , for managing undo segments and space in an undo tablespace. When a transaction starts, 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 database instance does not have a designated undo tablespace, then the transaction binds to the system undo segment. Multiple active transactions can write concurrently to the same undo segment or to different segments.

Conceptually, the extents in an undo segment form a ring. Transactions write to one undo extent, and then to the next extent in the ring, and so on in cyclical fashion.

Figure shows two transactions, T1 and T2, which begin writing in the third extent E3 of an undo segment and continue writing to the fourth extent E4.

At any given time, a transaction writes sequentially to only one extent in an undo segment, known as the current extent for the transaction. Multiple active transactions can write simultaneously to the same current extent or to different current extents. Figure shows transactions T1 and T2 writing simultaneously to extent E3. Within an undo extent, a data block contains data for only one transaction.

As the current undo extent fills, the first transaction needing space checks the availability of the next allocated extent in the ring. If the next extent does not contain data from an active transaction, then this extent becomes the current extent. Now all transactions that need space can write to the new current extent. If the next extent does contain data from an active transaction, then the database must allocate a new extent.

Figure shows a scenario in which T1 and T2 are writing to E4. When E4 fills up, the transactions cannot continue writing to E1 because E1 contains active undo entries. Therefore, the database allocates a new extent E5 for this undo segment. The transactions continue writing to E5. During recovery, the database rolls back any uncommitted changes applied from the online redo log to the data files. Undo records 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.

To manage space, Oracle Database tracks the state of blocks in the segment. The high water mark HWM is the point in a segment beyond which data blocks are unformatted and have never been used. MSSM uses free lists to manage segment space. At table creation, no blocks in the segment are formatted. When a session 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. 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.

ASSM spread out inserts among blocks to avoid concurrency issues. Figure 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 and never used.

Suppose that a transaction inserts rows into the segment. The database must allocate a group of blocks to hold the rows.

The allocated blocks fall below the HWM. The database formats a bitmap block in this group to hold the metadata, but does not preformat the remaining blocks in the group. Segment size management manual vs segment size management auto: AUTOMATIC Segment Space management in tablespace used bitmap for tracking the freelist, it remove use of freelist management which cause the contention on the segment header that occurs with freelists management.

Note:Automatic segment space management is the default for all new permanent, locally managed tablespaces. Note: Create your tablespaces with the locally managed and automatic segment space management features ASSM enabled. Modify or switch between automatic or Manual space management Note: There is no way to convert the tablespace from automatic to manually or vise versa. Simple method is create a new tablespace with desired options and move the objects from the old tablespace to new tablespace.

With following query you find the objects present in your tablespace and commands of movement: Note: Specify the tablespace name from which you choose to move means source tablespace.



0コメント

  • 1000 / 1000