日期:2014-05-16  浏览次数:20382 次

Oracle 临时表空间总结(转载)

转载:http://www.itpub.net/thread-1481844-1-1.html


All operations that use sorts, including joins, index builds, ordering, computing aggregates (GROUP BY), and collecting optimizer statistics, benefit from temporary tablespaces. The performance gains are significant with Real Application Clusters.

?


首先从数据字典视图说起
v$dba_temp_files
v$sort_segment
v$tempseg_usage
dba_temp_free_space

上面这几个视图是我总结的在遇到Oracle临时空间问题时能用到的数据字典信息。
先看v$dba_temp_files
这个视图显示了数据库中临时文件的具体信息。要注意的有4列

SQL> desc dba_temp_files;
Name? ?? ?? ?? ?Type? ?? ?? ? Nullable Default Comments? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???
--------------- ------------- -------- ------- ---------------------------------------------------
FILE_NAME? ?? ? VARCHAR2(513) Y? ?? ?? ?? ?? ? Name of the database temp file? ?? ?? ?? ?? ?? ?? ?
FILE_ID? ?? ?? ?NUMBER? ?? ???Y? ?? ?? ?? ?? ? ID of the database temp file? ?? ?? ?? ?? ?? ?? ?? ?
TABLESPACE_NAME VARCHAR2(30)? ?? ?? ?? ?? ?? ? Name of the tablespace to which the file belongs? ?
BYTES? ?? ?? ???NUMBER? ?? ???Y? ?? ?? ?? ?? ? Size of the file in bytes? ?? ?? ?? ?? ?? ?? ?? ?? ?
BLOCKS? ?? ?? ? NUMBER? ?? ???Y? ?? ?? ?? ?? ? Size of the file in ORACLE blocks? ?? ? ? ?? ?? ?? ?
STATUS? ?? ?? ? VARCHAR2(7)? ?Y? ?? ?? ?? ?? ? File status: "AVAILABLE"? ?? ?? ?? ?? ?? ?? ?? ?? ?
RELATIVE_FNO? ? NUMBER? ?? ???Y? ?? ?? ?? ?? ? Tablespace-relative file number? ?? ?? ?? ?? ?? ?? ?
AUTOEXTENSIBLE??VARCHAR2(3)? ?Y? ?? ?? ?? ?? ? Autoextensible indicator:??"YES" or "NO"? ?? ?? ?? ?
MAXBYTES? ?? ???NUMBER? ?? ???Y? ?? ?? ?? ?? ? Maximum size of the file in bytes? ?? ?? ?? ?? ?? ?
MAXBLOCKS? ?? ? NUMBER? ?? ???Y? ?? ?? ?? ?? ? Maximum size of the file in ORACLE blocks? ?? ?? ???
INCREMENT_BY? ? NUMBER? ?? ???Y? ?? ?? ?? ?? ? Default increment for autoextension? ?? ?? ?? ?? ???
USER_BYTES? ?? ?NUMBER? ?? ???Y? ?? ?? ?? ?? ? Size of the useful portion of file in bytes? ?? ?? ?
USER_BLOCKS? ???NUMBER? ?? ???Y? ?? ?? ?? ?? ? Size of the useful portion of file in ORACLE blocks

这四列中, BYTES , BLOCKS 显示的是临时文件有多少BYTE大小,包含多少个数据块。而USER_BYTES,USER_BLOCKS是可用的BYTE和数据块个数。因此,我们可以知道临时文件中有一部分是被系统占用的,大概可以理解成文件头信息,在我的db中,这一部分大小是128个block,如下图所示,22784-22656=128.
SQL> select file_name, blocks , user_blocks from dba_temp_files;