|
The interrelation between the tablespaces, their data files, segments, and free and used extents can be examined by querying the data dictionary. The views that you can use to find information on tablespace are in the following sections. DBA_TABLESPACESWhen a tablespace with one or more files is created, a single row is created in DBA_TABLESPACES. This view provides information that allows you to determine the status, type, and space usage of the tablespace. DBA_DATA_FILESFor every single file associated with a tablespace in the database, online or offline, a row is added to DBA_DATA_FILES. The following query can be used to find information on the data files associated with the tablespaces in the database: SELECT FILE_NAME, TABLESPACE_NAME, BYTES, BLOCKS FROM DBA_DATA_FILES where tablespace_name = 'UNDOTBS1'; The following shows the output of the query:
DBA_SEGMENTSWhenever a segment is created, regardless of the segment type, a row is added to the DBA_SEGMENTS view. From this view, you can determine the number of blocks associated with a segment, the number of extents, to what tablespace the segment belongs, and more. To obtain information on the number of extents and blocks allocated to a segment, you would execute the following query: SELECT SEGMENT_NAME, TABLESPACE_NAME, EXTENTS, BLOCKS FROM DBA_SEGMENTS WHERE OWNER = 'SCOTT'; Here is the output you would expect to see from running this query.
DBA_EXTENTSWhenever space is allocated the extents of a segment, that space can be viewed in the DBA_EXTENTS view. Because the extent is the smallest unit of space allocated (although the block is the smallest unit stored or retrieved), whenever an additional extent is allocated to a segment, information about that extent can be found in DBA_EXTENTS. If you want to get information on the number of blocks and extents for a given segment from this view, you can run the following query: SELECT EXTENT_ID, FILE_ID, BLOCK_ID, BLOCKS FROM DBA_EXTENTS WHERE OWNER = 'SCOTT' AND SEGMENT_NAME = 'EMP';
DBA_FREE_SPACEWhen a tablespace and its data files are added to the database, but before anything is inserted into the objects, all the space in each data file minus the space allocated to the file header, shows up in the DBA_FREE_SPACE view. When extents are added to a segment, and that space is viewed in DBA_EXTENTS, the space found in DBA_FREE_SPACE is adjusted lower to show the reduced free space in the files where the extents were created for the segment. All the space in a file, with the exception of that space allocated to the file's header block, must be accounted for in either DBA_FREE_SPACE or DBA_EXTENTS. DBA_FREE_SPACE is used to check the extents from a given segment. SELECT TABLESPACE_NAME, COUNT(*), MAX(BLOCKS), SUM(BLOCKS) FROM DBA_FREE_SPACE GROUP BY TABLESPACE_NAME; TABLESPACE_NAME COUNT(*) MAX(BLOCKS) SUM(BLOCKS) The following is the output that you might see if running this query.
|
|