10.4 Managing Extent UsageAn extent in Oracle parlance is the size of the chunks of storage that are allocated to a table or index upon creation or when that table or index needs to be extended to accommodate more data. Extent management was always a problem in older versions of Oracle because it could never be precisely controlled. With the advent of locally managed tablespaces (LMTs) in Oracle8i, Oracle has greatly simplified space management. LMTs allow DBAs to control the extent sizes allocated for tablespace objects, regardless of their STORAGE specifications. This eliminates the fragmentation that can occur in dictionary-managed tablespaces when objects are created with different extent sizes. Such fragmentation is impossible when LMTs are used. With LMTs, the extent size can be controlled so that all tablespace extents are the same size. In this section, we'll look at the benefits of LMTs and then see how the toolkit script maxext.pl can make this feature even more effective. 10.4.1 Locally Managed Tablespaces (LMTs)If CREATE TABLE statements request an extent greater than the tablespace's uniform extent size, they receive multiple smaller extents, satisfying the total storage amount requested. This is illustrated in Example 10-16. There, a tablespace is created with locally managed extents of 128K. Even though the requested extent size for EMPTEST is 512K, the space is allocated in 128K chunks. USER_EXTENTS shows four allocated chunks of 128K each. Example 10-16. Extent allocation in a locally managed tablespaceCREATE TABLESPACE USERS DATAFILE '/u01/oradata/ts01/users.dbf' SIZE 20M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K; CREATE TABLE EMPTEST ( FNAME VARCHAR2(20), LNAME VARCHAR2(20) ) TABLESPACE USERS STORAGE( INITIAL 512K NEXT 512K ); BREAK ON TABLESPACE_NAME SKIP 1 ON SEGMENT_TYPE SKIP 1 ON SEGMENT_NAME SKIP 1 ON REPORT COMPUTE SUM OF BYTES ON REPORT SELECT TABLESPACE_NAME, SEGMENT_TYPE, SEGMENT_NAME, DECODE(EXTENT_ID,0,'0',TO_CHAR(EXTENT_ID)) EXTENT_ID, BYTES FROM USER_EXTENTS WHERE SEGMENT_NAME = 'EMPTEST' ORDER BY TABLESPACE_NAME, SEGMENT_TYPE, SEGMENT_NAME, TO_NUMBER(EXTENT_ID); TABLESPACE TYPE NAME ID BYTES ---------- ------ ---------- -- ------------ USERS TABLE EMPTEST 0 131,072 1 131,072 2 131,072 3 131,072 ********** ****** ********** ------------ sum 524,288 4 rows selected. Even though fragmentation is eliminated, storage still needs monitoring. In Example 10-16 a table is created, with four empty extents. If no more tablespace extents are available, does this require an increase in tablespace size? Increasing tablespace size may be unnecessary. Even if your table sits within a full tablespace, the table itself contains no data. If you could determine whether all tablespace objects have a sufficient number of unused blocks to satisfy application data needs for six months, for example, there would be no immediate need to increase tablespace size. To figure this out, we will need to check the individual objects to determine if their free space is sufficient. The statistics of interest in determining if an object will soon need more space are the following:
10.4.2 Examining Object Space with maxext.plThe maxext.pl script in our toolkit determines if an object may be running out of space. It follows the steps illustrated in Figure 10-3 and listed here:
Figure 10-3. Flowchart of maxext.pl operationsIn maxext.pl we rely upon UNUSED_BLOCKS, rather than FREE_BLOCKS, because the amount of space available in a used freelist block is unknown. It can be calculated, but we prefer to rely on the ratio of UNUSED_BLOCKS / TOTAL_BLOCKS to determine if a tablespace or tablespace object needs space attention. Before running maxext.pl, make sure that you have a copy of the maxext.conf file stored in PDBA_HOME, as for the other configuration files described earlier in this chapter. There are only a few parameters in this configuration file that you will need to edit, shown in the following list. The entire file maxext.conf is reproduced in Example 10-17. Example 10-17. maxext.confpackage maxext; use vars qw{ %config @emailAddresses }; %config = ( minExtentsCanExtend => 3, minPctBlocksUnused => 10, ); @emailAddresses = ( '[email protected]', '[email protected]', );
There are only a few command options for maxext.pl, summarized in Table 10-7.
The results of running maxext.pl can be seen in Example 10-18. We forced these tables to appear in the report by setting the minPctBlocksUnused parameter to 100 in the maxext.conf file. Example 10-18. Results from maxext.pl%oramon > maxext.pl -machine sherlock -database ts01 -username \ system -email NUMBER EXTENTS NEXT OWNER NAME TYPE AVAILABLE EXTENT SIZE MAX BYTES FREE ========= ============ ======== ========== =========== =============== JKSTILL BIG_TABLE TABLE UNLIM 65536 0 JKSTILL FILL_ER_UP TABLE UNLIM 65536 0 %oramon > |