嘉为Oracle OCP培训--Oracle11g 临时表存储特性(嘉为原创)
到嘉为Canway主页了解更多
Oracle11g 临时表存储特性 创建全局临时表时,所占用的空间是从哪里分配的呢?它来自用户的临时表空间。通常这不会成为问题,但在某些特殊情况下,但我们可能要出于某种目的需要释放临时表空间(通常是为了排序)。有时,您可能要创建临时表,以使用位于更快、更高效磁盘上的其他临时表空间来提高数据访问速度。在这些情况下,您只能将该表空间变成用户的临时表空间。 在 Oracle 数据库 11g 中,可以使用另一个临时表空间来存放全局临时表。让我们看一看这种方案的实现方式。
首先,再创建一个临时表空间: SQL> createtemporary tablespace test_temp tempfile 'D\:ORACLE11G\ORADATA\TEST\TEST_TEMP.DBF'size 20m; Tablespacecreated SQL> createglobal temporary table my_temp (
2 id number 3 name varchar2 (100))
4 on commit preserve rows
5 tablespace test_temp; Table created SQL> selecttemporary_tablespace from dba_users where username='HR'; TEMPORARY_TABLESPACE
------------------------------
TEMP SQL> selecttable_name,tablespace_name,logging from user_tables where table_name='MY_TEMP'; TABLE_NAMETABLESPACE_NAME LOGGING
------------------------------ ------------------------------ -------
MY_TEMP TEST_TEMP NO 现在,将在表空间 TEST_TEMP 而不是用户的默认临时表空间 (TEMP)上创建此临时表。 同时,在11g中,可以直接shrink 临时表空间 altertablespace test_temp shrink space;
alter tablespace test_temp shrink space keep 10m; 比如:
SQL> select bytes,name from v$tempfile where ts#=8 and file#=2; BYTES NAME
---------- ------------------------------------------------
20971520 D\:ORACLE11G\ORADATA\TEST\TEST_TEMP.DBF SQL> altertablespace toms_temp shrink space keep 10m; Tablespacealtered SQL> selectbytes,name from v$tempfile where ts#=8 and file#=2; BYTES NAME
---------- --------------------------------------------------
11534336 D\:ORACLE11G\ORADATA\TEST\TEST_TEMP.DBF SQL>

|