Although the problem I am about to state is related to a 7.1.3 database. I would like to know if the same would happen on 8.1.6.3 databases as most of ours are 8.1.6.3 databases.
While monitoring space allocation we have noticed that one of the tables needing 40m space have not used up space from one of the contguous free spaces in the tablespace of the size of 100m,120m,60m. Instead it has used space from the largest contiguous free space i.e 703m.As per our understanding Oracle should have allocated from one of the smaller bits of space mentioned earlier. I have just read a document on Oracle metalink(DOC ID :69343.1)allocation but none of the scenarios there matches our case.
Could you please tell me under what circumstances would Oracle ignore
these other smaller chunks of free space that are closer to the required next extent size for an object?If this happens how can we predict space requirements for a tablespace? Is it possible to order the extents listed as free in the SGA by their size ? How can we control the allocation such that an object uses up smaller chunks closer to its requirement instead of picking up from anywhere.
The algorithm is well documented in the Server Concepts Guide.
This is a cut and paste from the Oracle7 Server concepts guide:
<quote>
How Extents Are Allocated for Segments
Oracle controls the allocation of extents for a given segment. The procedure to allocate a new extent for a segment is as follows:
1. Oracle searches through the free space (in the tablespace that contains the segment) for the first free, contiguous set of data blocks of an incremental extent's size or larger. Oracle finds the free space for the new extent by using the following algorithm:
a. Oracle searches for a contiguous set of data blocks that matches the size of new extent, rounded up to reduce internal fragmentation. For example, if a new extent requires 19 data blocks, Oracle searches for exactly 20 contiguous data blocks. However, if the new extent is 5 or fewer blocks, Oracle does not round up the request.
b. If an exact match is not found, Oracle then searches for a set of contiguous data blocks equal to or greater than the amount needed. If Oracle finds a group of contiguous blocks that is at least five blocks greater than the size of the extent that is needed, it splits the group of blocks into separate extents, one of which is the size it needs; if Oracle finds a group of blocks that is larger than the size it needs, but less than five blocks larger, it allocates all the contiguous blocks.
Continuing with the example, if Oracle does not find a set of exactly 20 contiguous data blocks, Oracle then searches for a set of contiguous data blocks greater than 20. If the first set that Oracle finds contains 25 or more blocks, it breaks the blocks up and allocates twenty of them to the new extent. Otherwise, it allocates all of the blocks (between 21 and 24) to the new extent.
c. If Oracle does not find a larger set of contiguous data blocks, Oracle then coalesces any free, adjacent data blocks in the corresponding tablespace so that larger sets of contiguous data blocks are formed. (The SMON background process also periodically coalesces adjacent free space.) After coalescing a tablespace's data blocks, Oracle performs the searches described in a. and b. again. If an extent cannot be allocated after the second search, Oracle returns an error.
2. Once Oracle finds the necessary free space in the tablespace, Oracle allocates a portion of the free space that corresponds to the size of the incremental extent. If Oracle had found a larger amount of free space than was required for the extent, Oracle leaves the remainder as free space (no smaller than five contiguous blocks).
3. Oracle updates the segment header and data dictionary to show that a new extent has been allocated and that the allocated space is no longer free.
Usually, Oracle zeros out the blocks of a newly allocated extent when the extent is first used; in a few cases (such as when a database administrator issues an ALTER TABLE or ALTER CLUSTER statement with the ALLOCATE EXTENT option while using free list groups), Oracle clears the extent's blocks when it allocates the extent.
</quote>
There is nothing in there to suggest it would search for the smallest free extent, it just searches FET$ to find one that fits -- first row it finds, it uses.
The extents are not listed in the SGA, they are in a table.
What you should do is place objects into tablespaces based on their EXTENT SIZES (eg: all objects in a tablespace use the same exact INITIAL=NEXT and PCTINCREASE always is ZERO).
In this case, fragmentation is IMPOSSIBLE (any object can use any extent since all extents are exactly the same size).
It is OK to have hundreds, even 1,000's of extents. It really is OK.
You need probably 3 tablespaces -- one for small, medium, and large objects and you can hold EVERY object. See
</code>
http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:730289259844 <code>
and look for "living" and read that paper for a good strategy.
In 8163, you would be using Locally managed tablespacs with uniform extent sizes (search my site for locally managed to see discussions). This just enforces the initial=next and pctincrease=0 at the tablespace level, making it IMPOSSIBLE for an object to have just any extent size it wanted to.