Logical Storage Structures
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 types of tablespaces:
· 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
Locally Managed Tablespaces
A locally managed tablespace maintains a bitmap in the data file header to track free and used space in the data file body. Each bit corresponds to a group of blocks. When space is allocated or freed, Oracle Database changes the bitmap values to reflect the new status of the blocks.
The following graphic is a conceptual representation of bitmap-managed storage. A
1 in the header refers to used space, whereas a
0 refers to free space.
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.
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.
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 a database object that has free space, a free list keeps track of blocks under the high water mark (HWM), which is the dividing line between segment space that is used and not yet used. As blocks are used, the database puts blocks on or removes blocks from the free list as needed.
In addition to
PCTFREE, MSSM requires you to control space allocation with SQL parameters such as
PCTUSED sets the percentage of free space that must exist in a currently used block for the database to put it on the free list. For example, if you set
40 in a
CREATE TABLE statement, then you cannot insert rows into a block in the segment until less than 40% of the block space is used.
As an illustration, suppose you insert a row into a table. The database checks a free list of the table for the first available block. If the row cannot fit in the block, and if the used space in the block is greater than or equal to
PCTUSED, then the database takes the block off the list and searches for another block. If you delete rows from the block, then the database checks whether used space in the block is now less than
PCTUSED. If so, then the database places the block at the beginning of the free list.
An object may have multiple free lists. In this way, multiple sessions performing DML on a table can use different lists, which can reduce contention. Each database session uses only one free list for the duration of its session.
As shown in Figure 12-4, you can also create an object with one or more free list groups, which are collections of free lists. Each group has a master free list that manages the individual process free lists in the group. Space overhead for free lists, especially for free list groups, can be significant.
Figure 12-4 Free List Groups
Managing segment space manually can be complex. You must adjust
PCTUSED to reduce row migration (see "Chained and Migrated Rows") and avoid wasting space. For example, if every used block in a segment is half full, and if
PCTUSED is 40, then the database does not permit inserts into any of these blocks. Because of the difficulty of fine-tuning space allocation parameters, Oracle strongly 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
-- ASSM 会忽略PCTUSED 参数