一. 官网说明
Logical Storage Structures
http://download.oracle.com/docs/cd/E11882_01/server.112/e16508/logical.htm#CNCPT7668
其中有关ASSM 的内容如下:
Logical Space Management
Oracle Database must use logical spacemanagement to track and allocate the extents in atablespace. When a database object requires an extent, the databasemust have a method of finding and providing it. Similarly, when anobject no longer requires an extent, the database must have amethod of making the free extent available.
Oracle Database managesspace within a tablespace based on the type that you create. Youcan create either of the following types of tablespaces:
·
The database uses bitmaps in the tablespaces themselves tomanage extents. Thus, locally managed tablespaces have a part ofthe tablespace set aside for a bitmap. Within a tablespace, thedatabase can manage segments with automatic segment spacemanagement (ASSM) or manual segment spacemanagement (MSSM).
·
The database uses the data dictionary to manage extents (see "Overview of the Data Dictionary").
Figure 12-3 shows the alternatives for logical space managementin a tablespace.
Figure 12-3 Logical SpaceManagement
Descriptionof "Figure 12-3 Logical Space Management"
Locally ManagedTablespaces
A locallymanaged tablespace maintains a bitmap in the data file header totrack free and used space in the data file body. Each bitcorresponds to a group of blocks. When space is allocated or freed,Oracle Database changes the bitmap values to reflect the new statusof the blocks.
The following graphic is a conceptual representation ofbitmap-managed storage. A 1
in the header refers toused space, whereas a 0
refers to free space.
A locally managed tablespace has the following advantages:
·
Recursive operations can occur in dictionary-managed tablespacesif consuming or releasing space in an extent results in anotheroperation that consumes or releases space in a data dictionarytable or undo segment.
·
In this way, the database eliminates the need to coalesce freeextents.
·
Alternatively, all extents can have the same size in a locallymanaged tablespace and override object storage options.
Note:
Oracle strongly recommends the use of locally managedtablespaces with Automatic Segment Space Management.
Segment space management is an attributeinherited from the tablespace that contains the segment. Within alocally managed tablespace, the database can manage segmentsautomatically or manually. For example, segments in tablespaceusers
can be managed automatically while segments intablespace tools
are managed manually.
Automatic Segment Space Management
The ASSM method uses bitmaps to manage space. Bitmaps providethe following advantages:
·
ASSM avoids the need to manually determine correct settings formany storage parameters. Only one crucial SQL parameter controlsspace allocation: PCTFREE
. This parameter specifiesthe percentage of space to be reserved in a block for futureupdates (see "Percentage of Free Space in Data Blocks").
ASSM 管理,只需要一个参数:PCTFREE
·
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 ofa well-tuned application that uses MSSM.
·
ASSM is more efficient and is the default for permanent, locallymanaged tablespaces.
Note:
This chapter assumes the use of ASSM in all of its discussionsof logical storage space.
Manual Segment Space Management
The legacy MSSM method uses a linked list called a freelist to manage free space in the segment. For a databaseobject that has free space, a free list keeps track of blocks underthe high water mark (HWM), which is the dividing line betweensegment space that is used and not yet used. As blocks are used,the database puts blocks on or removes blocks from the free list asneeded.
In addition to PCTFREE
, MSSM requires you tocontrol space allocation with SQL parameters such asPCTUSED
, FREELISTS
, and FREELISTGROUPS
. PCTUSED
sets the percentage of freespace that must exist in a currently used block for the database toput it on the free list. For example, if you setPCTUSED
to 40
in a CREATETABLE
statement, then you cannot insert rows into a block inthe segment until less than 40% of the block space is used.
As an illustration, suppose you insert a row into a table. Thedatabase checks a free list of the table for the first availableblock. If the row cannot fit in the block, and if the used space inthe block is greater than or equal to PCTUSED
, thenthe database takes the block off the list and searches for anotherblock. If you delete rows from the block, then the database checkswhether used space in the block is now less thanPCTUSED
. If so, then the database places the block atthe beginning of the free list.
An object may have multiple free lists. In this way, multiplesessions performing DML on a table can use different lists, whichcan reduce contention. Each database session uses only one freelist for the duration of its session.
As shown in Figure 12-4, you can also create an object with one or morefree list groups, which are collections of freelists. Each group has a master free list thatmanages the individual process free lists in thegroup. Space overhead for free lists, especially for free listgroups, can be significant.
Descriptionof "Figure 12-4 Free List Groups"
Managing segment space manually can be complex. You must adjustPCTFREE
and PCTUSED
to reduce rowmigration (see "Chained and Migrated Rows") and avoid wasting space. Forexample, if every used block in a segment is half full, and ifPCTUSED
is 40, then the database does not permitinserts into any of these blocks. Because of the difficulty offine-tuning space allocation parameters, Oracle strongly recommendsASSM. In ASSM, PCTFREE
determines whether a new rowcan be inserted into a block, but it does not use free lists andignores PCTUSED
.
-- ASSM 会忽略PCTUSED 参数
Dictionary-Managed Tablespaces
Adictionary-managed tablespace uses the data dictionary to manageits extents. Oracle Database updates tables in the data dictionarywhenever an extent is allocated or freed for reuse. For example,when a table needs an extent, the database queries the datadictionary tables, and searches for free extents. If the databasefinds space, then it modifies one data dictionary table and insertsa row into another. In this way, the database manages space bymodifying and moving data.
The SQL that the database executes in the background to obtainspace for database objects is recursive SQL.Frequent use of recursive SQL can have a negative impact onperformance because updates to the data dictionary must beserialized. Locally managed tablespaces, which are the default,avoid this performance problem.
二.
让我们看看位图freelist是如何实现的。从使用区段空间管理自动参数创建tablespace开始:
create tablespace demo
datafile '/ora01/oem/demo01.dbf'
size 5m
EXTENT MANAGEMENT LOCAL -- Turn onLMT
SEGMENT SPACE MANAGEMENT AUTO -- Turn onASSM;
一旦你定义好了tablespace,那么表和索引就能够使用各种方法很容易地被移动到新的tablespace里,带有ASSM的本地管理tablespace会略掉任何为PCTUSED、NEXT和FREELISTS所指定的值。