通过v$tempseg_usage可以查看临时段的使用情况
session 1:
SQL> drop table test;
表已丢弃。
SQL> create table test as select * from dba_objects;
表已创建。
SQL> insert into test select * from dba_objects;
已创建30024行。
SQL> commit;
提交完成。
SQL> insert into test select * from dba_objects;
已创建30024行。
SQL> commit;
提交完成。
SQL> insert into test select * from dba_objects;
已创建30024行。
SQL> commit;
提交完成。
SQL> create index testindex on test(object_name);
在索引没有建成功之前
session 2:
SQL> select * from v$tempseg_usage;
USERNAME USER SESSION_ADDR SESSION_NUM SQLADDR SQLHASH TABLESPACE CONTENTS SEGTYPE SEGFILE# SEGBLK# EXTENTS BLOCKS SEGRFNO#
------------------------------ ------------------------------ ------------ ----------- -------- ---------- ------------------------------- --------- --------- ---------- ---------- ---------- ---------- ----------
NBA NBA 1BA7DE9C 19 1D25317C 2296808019 TEMP TEMPORARY SORT 201 113545 5 640 1
索引创建成功后再次查询v$temgseg_usage
SQL> /
USERNAME USER SESSION_ADDR SESSION_NUM SQLADDR SQLHASH TABLESPACE CONTENTS SEGTYPE SEGFILE# SEGBLK# EXTENTS BLOCKS SEGRFNO#
------------------------------ ------------------------------ ------------ ----------- -------- ---------- ------------------------------- --------- --------- ---------- ---------- ---------- ---------- ----------
为什么表空间是TEMP,而不是其他的临时表空间,是因为:
SQL> select temporary_tablespace from dba_users where username='NBA';
TEMPORARY_TABLESPACE
------------------------------
TEMP
创建用户时指定的默认的临时表空间是TEMP
为什么索引创建后,v$temgseg_usage不在有记录
concepts中有这样一段
When Oracle completes the execution of a statement requiring a temporary segment,
Oracle automatically drops the temporary segment and returns the extents allocated
for that segment to the associated tablespace.
A single sort allocates its own temporary
segment in a temporary tablespace of the user issuing the statement and then returns
the extents to the tablespaces.
Multiple sorts, however, can use sort segments in temporary tablespaces designated
exclusively for sorts. These sort segments are allocated only once for the instance, and
they are not returned after the sort, but remain available for other multiple sorts.
可知Mulitiple sorts使用的segment的空间是不回收的,但什么是single sor什么是mulitple sorts,现在不情况区别点在哪里
默认的临时表空间是TEMP
9i之前不指定临时表空间,将使用SYSTEM作为临时表空间
9i会有一个默认的临时表空间
SQL> select property_name,property_value from database_properties where property_name = 'DEFAULT_TEMP_TABLESPACE';
PROPERTY_NAME PROPERTY_VALUE
------------------------------ --------------------------------------------------------------------------------
DEFAULT_TEMP_TABLESPACE TEMP
而默认的临时表空间是不能删除的
SQL> drop tablespace temp;
drop tablespace temp
*
ERROR 位于第 1 行:
ORA-12906: 不能删除默认的临时表空间
最后来看看临时表中临时段的使用情况
session 1:
SQL> drop table test;
表已丢弃。
SQL> create global temporary table test(x int,y varchar2(10));
表已创建。
SQL> insert into test values(1,'a');
已创建 1 行。
session 2:
SQL> select * from v$tempseg_usage;
USERNAME USER SESSION_ADDR SESSION_NUM SQLADDR SQLHASH TABLESPACE CONTENTS SEGTYPE SEGFILE# SEGBLK# EXTENTS BLOCKS SEGRFNO#
------------------------------ ------------------------------ ------------ ----------- -------- ---------- ------------------------------- --------- --------- ---------- ---------- ---------- ---------- ----------
NBA NBA 1BA7DE9C 32 1D233E70 1010750936 TEMP TEMPORARY DATA 201 113033 1 128 1
SQL> select sql_text from v$sqlarea where hash_value=1010750936;
SQL_TEXT
--------------------------------------------------------------------------------
insert into test values(1,'a')
可以看出当对临时表进行第一次insert时,临时段就被分配了
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22111412/viewspace-617072/ ,如需转载,请注明出处,否则将追究法律责任。