Oracle® Database Administrator's Guide 11g Release 2 (11.2) Part Number E25494-02 |
|
|
PDF · Mobi · ePub |
Oracle Database provides data dictionary views and PL/SQL packages that allow you to display information about the space usage of schema objects. Views and packages that are unique to a particular schema object are described in the chapter of this book associated with that object. This section describes views and packages that are generic in nature and apply to multiple schema objects.
These DBMS_SPACE
subprograms provide information about schema objects:
See Also:
Oracle Database PL/SQL Packages and Types Reference for a description of theDBMS_SPACE
packageExample: Using DBMS_SPACE.UNUSED_SPACE
The following SQL*Plus example uses the DBMS_SPACE
package to obtain unused space information.
SQL> VARIABLE total_blocks NUMBER SQL> VARIABLE total_bytes NUMBER SQL> VARIABLE unused_blocks NUMBER SQL> VARIABLE unused_bytes NUMBER SQL> VARIABLE lastextf NUMBER SQL> VARIABLE last_extb NUMBER SQL> VARIABLE lastusedblock NUMBER SQL> exec DBMS_SPACE.UNUSED_SPACE('SCOTT', 'EMP', 'TABLE', :total_blocks, - > :total_bytes,:unused_blocks, :unused_bytes, :lastextf, - > :last_extb, :lastusedblock); PL/SQL procedure successfully completed. SQL> PRINT TOTAL_BLOCKS ------------ 5 TOTAL_BYTES ----------- 10240 ... LASTUSEDBLOCK ------------- 3
These views display information about space usage in schema objects:
The following sections contain examples of using some of these views.
See Also:
Oracle Database Reference for a complete description of data dictionary viewsThe following query returns the name and size of each index segment in schema hr
:
SELECT SEGMENT_NAME, TABLESPACE_NAME, BYTES, BLOCKS, EXTENTS FROM DBA_SEGMENTS WHERE SEGMENT_TYPE = 'INDEX' AND OWNER='HR' ORDER BY SEGMENT_NAME;
The query output is:
SEGMENT_NAME TABLESPACE_NAME BYTES BLOCKS EXTENTS ------------------------- --------------- -------- ------ ------- COUNTRY_C_ID_PK EXAMPLE 65536 32 1 DEPT_ID_PK EXAMPLE 65536 32 1 DEPT_LOCATION_IX EXAMPLE 65536 32 1 EMP_DEPARTMENT_IX EXAMPLE 65536 32 1 EMP_EMAIL_UK EXAMPLE 65536 32 1 EMP_EMP_ID_PK EXAMPLE 65536 32 1 EMP_JOB_IX EXAMPLE 65536 32 1 EMP_MANAGER_IX EXAMPLE 65536 32 1 EMP_NAME_IX EXAMPLE 65536 32 1 JHIST_DEPARTMENT_IX EXAMPLE 65536 32 1 JHIST_EMPLOYEE_IX EXAMPLE 65536 32 1 JHIST_EMP_ID_ST_DATE_PK EXAMPLE 65536 32 1 JHIST_JOB_IX EXAMPLE 65536 32 1 JOB_ID_PK EXAMPLE 65536 32 1 LOC_CITY_IX EXAMPLE 65536 32 1 LOC_COUNTRY_IX EXAMPLE 65536 32 1 LOC_ID_PK EXAMPLE 65536 32 1 LOC_STATE_PROVINCE_IX EXAMPLE 65536 32 1 REG_ID_PK EXAMPLE 65536 32 1 19 rows selected.
Information about the currently allocated extents in a database is stored in the DBA_EXTENTS
data dictionary view. For example, the following query identifies the extents allocated to each index segment in the hr
schema and the size of each of those extents:
SELECT SEGMENT_NAME, SEGMENT_TYPE, TABLESPACE_NAME, EXTENT_ID, BYTES, BLOCKS FROM DBA_EXTENTS WHERE SEGMENT_TYPE = 'INDEX' AND OWNER='HR' ORDER BY SEGMENT_NAME;
The query output is:
SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME EXTENT_ID BYTES BLOCKS ------------------------- ------------ --------------- --------- -------- ------ COUNTRY_C_ID_PK INDEX EXAMPLE 0 65536 32 DEPT_ID_PK INDEX EXAMPLE 0 65536 32 DEPT_LOCATION_IX INDEX EXAMPLE 0 65536 32 EMP_DEPARTMENT_IX INDEX EXAMPLE 0 65536 32 EMP_EMAIL_UK INDEX EXAMPLE 0 65536 32 EMP_EMP_ID_PK INDEX EXAMPLE 0 65536 32 EMP_JOB_IX INDEX EXAMPLE 0 65536 32 EMP_MANAGER_IX INDEX EXAMPLE 0 65536 32 EMP_NAME_IX INDEX EXAMPLE 0 65536 32 JHIST_DEPARTMENT_IX INDEX EXAMPLE 0 65536 32 JHIST_EMPLOYEE_IX INDEX EXAMPLE 0 65536 32 JHIST_EMP_ID_ST_DATE_PK INDEX EXAMPLE 0 65536 32 JHIST_JOB_IX INDEX EXAMPLE 0 65536 32 JOB_ID_PK INDEX EXAMPLE 0 65536 32 LOC_CITY_IX INDEX EXAMPLE 0 65536 32 LOC_COUNTRY_IX INDEX EXAMPLE 0 65536 32 LOC_ID_PK INDEX EXAMPLE 0 65536 32 LOC_STATE_PROVINCE_IX INDEX EXAMPLE 0 65536 32 REG_ID_PK INDEX EXAMPLE 0 65536 32 19 rows selected.
For the hr
schema, no segment has multiple extents allocated to it.
Information about the free extents (extents not allocated to any segment) in a database is stored in the DBA_FREE_SPACE
data dictionary view. For example, the following query reveals the amount of free space available as free extents in the SMUNDO
tablespace:
SELECT TABLESPACE_NAME, FILE_ID, BYTES, BLOCKS FROM DBA_FREE_SPACE WHERE TABLESPACE_NAME='SMUNDO';
The query output is:
TABLESPACE_NAME FILE_ID BYTES BLOCKS --------------- -------- -------- ------ SMUNDO 3 65536 32 SMUNDO 3 65536 32 SMUNDO 3 65536 32 SMUNDO 3 65536 32 SMUNDO 3 65536 32 SMUNDO 3 65536 32 SMUNDO 3 131072 64 SMUNDO 3 131072 64 SMUNDO 3 65536 32 SMUNDO 3 3407872 1664 10 rows selected.