Thomas Zhang的杂货铺
21 11, 2008
Oracle 11g中临时表空间的几个新功能
作者 tomszrp 11:06 | Permalink 静态链接网址 | Comments 最新回复 (0) | Trackback 引用 (0) | 解决方案

使用不同的表空间存放临时表

创建全局临时表时,所占用的空间是从哪里分配的呢?它来自用户的临时表空间。
通常这不会成为问题,但在某些特殊情况下,但我们可能要出于某种目的需要释放临时表空间(通常是为了排序)。
有时,您可能要创建临时表,以使用位于更快、更高效磁盘上的其他临时表空间来提高数据访问速度。
在这些情况下,您只能将该表空间变成用户的临时表空间。

在 Oracle 数据库 11g 中,可以使用另一个临时表空间来存放全局临时表。让我们看一看这种方案的实现方式。
首先,再创建一个临时表空间:

SQL> create temporary tablespace toms_temp tempfile 'D:ORACLE11GORADATAORA11GTOMS_TEMP.DBF' size 20m;

Tablespace created

SQL> create global temporary table my_temp (
2 str varchar2 (2000)
3 )
4 on commit preserve rows
5 tablespace toms_temp;

Table created

SQL> select temporary_tablespace from dba_users where username='STUDY';

TEMPORARY_TABLESPACE
------------------------------
TEMP

SQL> select table_name,tablespace_name,logging from user_tables where table_name='MY_TEMP';

TABLE_NAME TABLESPACE_NAME LOGGING
------------------------------ ------------------------------ -------
MY_TEMP TOMS_TEMP NO


现在,将在表空间 TOMS_TEMP 而不是用户的默认临时表空间 (TEMP) 上创建此临时表。

同时,在11g中,可以直接shrink 临时表空间

alter tablespace toms_temp shrink space;
alter tablespace toms_temp shrink space keep 10m;

比如:
SQL> select bytes,name from v$tempfile where ts#=8 and file#=2;

BYTES NAME
---------- ------------------------------------------------
20971520 D:ORACLE11GORADATAORA11GTOMS_TEMP.DBF

SQL> alter tablespace toms_temp shrink space keep 10m;

Tablespace altered

SQL> select bytes,name from v$tempfile where ts#=8 and file#=2;

BYTES NAME
---------- --------------------------------------------------
11534336 D:ORACLE11GORADATAORA11GTOMS_TEMP.DBF

SQL>


Comments
发表评论
标题:


称呼:


邮箱地址(可选):


个人主页(可选):


发表评论:
Bold Italic Link authimage




博客日历
« 三月 2010 »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
搜索
最新发表
文章分类
文章归档
网站链接
新闻聚合