表空间管理是DBA的工作重点之一,所以本节也会用较大的篇幅来阐述数据库表空间相关的重要知识点和注意事项。
区管理和段管理
在日常维护中和表空间管理相关的主要视图如下所示。
视图 描述
V$TABLESPACE Name and number of all tablespaces from the control file.
DBA_TABLESPACES, USER_TABLESPACES Descriptions of all (or user accessible) tablespaces.
DBA_TABLESPACE_GROUPS Displays the tablespace groups and the tablespaces that belong to them.
DBA_SEGMENTS, USER_SEGMENTS Information about segments within all (or user accessible) tablespaces.
DBA_EXTENTS, USER_EXTENTS Information about data extents within all (or user accessible) tablespaces.
DBA_FREE_SPACE, USER_FREE_SPACE Information about free extents within all (or user accessible) tablespaces.
V$DATAFILE Information about all datafiles, including tablespace number of owning tablespace.
V$TEMPFILE Information about all tempfiles, including tablespace number of owning tablespace.
DBA_DATA_FILES Shows files (datafiles) belonging to tablespaces.
DBA_TEMP_FILES Shows files (tempfiles) belonging to temporary tablespaces.
V$TEMP_EXTENT_MAP Information for all extents in all locally managed temporary tablespaces.
V$TEMP_EXTENT_POOL For locally managed temporary tablespaces: the state of temporary space cached and used for by each instance.
V$TEMP_SPACE_HEADER Shows space used/free for each tempfile.
DBA_USERS Default and temporary tablespaces for all users.
DBA_TS_QUOTAS Lists tablespace quotas for all users.
V$SORT_SEGMENT Information about every sort segment in a given instance. The view is only updated when the tablespace is of the TEMPORARY type.
V$TEMPSEG_USAGE Describes temporary (sort) segment usage by user for temporary or permanent tablespaces.
最重要的一张视图是DBA_TABLESPACE,其结构如下:
SQL> desc dba_tablespaces
Name Null? Type
----------------------------------------- -------- ----------------------------
TABLESPACE_NAME NOT NULL VARCHAR2(30)
BLOCK_SIZE NOT NULL NUMBER
INITIAL_EXTENT NUMBER
NEXT_EXTENT NUMBER
MIN_EXTENTS NOT NULL NUMBER
MAX_EXTENTS NUMBER
PCT_INCREASE NUMBER
MIN_EXTLEN NUMBER
STATUS VARCHAR2(9)
CONTENTS VARCHAR2(9)
LOGGING VARCHAR2(9)
FORCE_LOGGING VARCHAR2(3)
EXTENT_MANAGEMENT VARCHAR2(10)
ALLOCATION_TYPE VARCHAR2(9)
PLUGGED_IN VARCHAR2(3)
SEGMENT_SPACE_MANAGEMENT VARCHAR2(6)
DEF_TAB_COMPRESSION VARCHAR2(8)
RETENTION VARCHAR2(11)
BIGFILE VARCHAR2(3)
这张视图中包含了表空间管理中的几个重要知识点:
1.区(EXTENT)的管理方式
区(EXTENT)管理主要有数据字典管理方式(DMT)和本地管理方式(LMT)两种。在Oracle 8i之前,区管理均采用数据字典管理方式,其原理就是在Oracle基表SYS.FET 和 S Y S .