浅谈临时表空间组

--关于临时表空间组
数据库中可以有多个临时表空间联机并处于活动状态,但在Oracle 10g之前,同一个用户的多个会话只可以使用同一个临时表空间,因为只有一个默认的临时表空间可以被赋予用户。为了解决这个潜在的性能瓶颈,Oracle现在支持临时表空间组。临时表空间组即为一系列临时表空间。
临时表空间组必须至少包含一个临时表空间,它不可以为空。一旦临时表空间组没有任何成员,它将不再存在。
1.临时表空间组的主要特征
[1]一个临时表空间组必须由至少一个临时表空间组成,并且无明确的最大数量限制。
[2]DBA无法用命令创建临时表空间组。只有当把一个临时表空间分配给该组时,临时表空间组才会自动创建。如果删除了一个临时表空间组的所有成员,该组也自动被删除。
[3]临时表空间的名字不能与临时表空间组的名字相同,可以将临时表空间从一个组移动到另一个组。
[4]在给用户分配一个临时表空间时,可以使用临时表空间组的名字代替实际的临时表空间名;在给数据库分配默认临时表空间时也可以使用临时表空间组的名字。
2. 临时表空间组的优点
[1]由于SQL查询可以并发使用几个临时表空间进行排序操作,因此SQL查询很少会出现排序空间超出,避免当临时表空间不足时所引起的磁盘排序问题。
[2]可以在数据库级指定多个默认临时表空间。 
[3]一个并行操作的并行服务器将有效地利用多个临时表空间。
[4]一个用户在不同会话中可以同时使用多个临时表空间。
--联机文档上的解释
A tablespace group enables a user to consume temporary space from multiple tablespaces. Using a tablespace group, rather than a single temporary tablespace, can alleviate problems caused where one tablespace is inadequate to hold the results of a sort, particularly on a table that has many partitions. A tablespace group enables parallel execution servers in a single parallel operation to use multiple temporary tablespaces.
A tablespace group has the following characteristics:
1,It contains at least one tablespace. There is no explicit limit on the maximum number of tablespaces that are contained in a group.
2,It shares the namespace of tablespaces, so its name cannot be the same as any tablespace.
3,You can specify a tablespace group name wherever a tablespace name would appear when you assign a default temporary tablespace for the database or a temporary tablespace for a user.
You do not explicitly create a tablespace group. Rather, it is created implicitly when you assign the first temporary tablespace to the group. The group is deleted when the last temporary tablespace it contains is removed from it.
The view DBA_TABLESPACE_GROUPS lists tablespace groups and their member tablespaces.
************************************我是注释符************************************
--db version
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
--当前临时表空间为temp
SQL> select TABLESPACE_NAME,STATUS,CONTENTS from dba_tablespaces;
TABLESPACE_NAME                STATUS    CONTENTS
------------------------------ --------- ---------
SYSTEM                         ONLINE    PERMANENT
SYSAUX                         ONLINE    PERMANENT
UNDOTBS1                       ONLINE    UNDO
TEMP                           ONLINE    TEMPORARY
USERS                          ONLINE    PERMANENT
EXAMPLE                        ONLINE    PERMANENT
6 rows selected.
--查看临时表空间组
SQL> desc dba_tablespace_groups;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 GROUP_NAME                                NOT NULL VARCHAR2(30)
 TABLESPACE_NAME                           NOT NULL VARCHAR2(30)
SQL> select * from dba_tablespace_groups;
no rows selected
--把temp加到组1
SQL> alter tablespace TEMP tablespace group group1;
Tablespace altered.
SQL> select * from dba_tablespace_groups;
GROUP_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
GROUP1                         TEMP
--添加zyp_temp1/2到组1
SQL> create temporary tablespace zyp_temp1 tempfile '/u01/oracle/oracle11/oradata/ora11/zyp_temp1_01.dbf' size 10m autoextend off tablespace group group1;
Tablespace created.
SQL> create temporary tablespace zyp_temp2 tempfile '/u01/oracle/oracle11/oradata/ora11/zyp_temp2_01.dbf' size 10m autoextend off tablespace group group1;
Tablespace created.
SQL>
SQL> select * from dba_tablespace_groups;
GROUP_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
GROUP1                         TEMP
GROUP1                         ZYP_TEMP1
GROUP1                         ZYP_TEMP2
--更改属组
SQL> alter tablespace zyp_temp1 tablespace group group2;    
Tablespace altered.
SQL> select * from dba_tablespace_groups;
GROUP_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
GROUP1                         TEMP
GROUP2                         ZYP_TEMP1
GROUP1                         ZYP_TEMP2
--删除组员(当删除的组员是最后的一个时,会默认删除对应改组)
SQL> drop tablespace zyp_temp1;
Tablespace dropped.
SQL> select * from dba_tablespace_groups;
GROUP_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
GROUP1                         TEMP
GROUP1                         ZYP_TEMP2
--查看当前的默认临时表空间
SQL> l
  1* select USERNAME,DEFAULT_TABLESPACE,TEMPORARY_TABLESPACE from dba_users where username = 'SCOTT'
SQL> /
USERNAME                       DEFAULT_TABLESPACE             TEMPORARY_TABLESPACE
------------------------------ ------------------------------ ------------------------------
SCOTT                          USERS                          TEMP
--更改默认临时表空间
SQL> alter database default temporary tablespace group1;
Database altered.
SQL> select USERNAME,DEFAULT_TABLESPACE,TEMPORARY_TABLESPACE from dba_users where username = 'SCOTT';
USERNAME                       DEFAULT_TABLESPACE             TEMPORARY_TABLESPACE
------------------------------ ------------------------------ ------------------------------
SCOTT                          USERS                          GROUP1
--查看临时表空间组及对应临时表空间
SQL> select * from dba_tablespace_groups;
GROUP_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
GROUP1                         TEMP
GROUP1                         ZYP_TEMP2
GROUP3                         ZYP_TEMP3
--删除临时表空间组成员
SQL> drop tablespace zyp_temp3;
Tablespace dropped.
SQL> select * from dba_tablespace_groups ;
GROUP_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
GROUP1                         TEMP
GROUP1                         ZYP_TEMP2
--使临时表空间退出临时表空间组
SQL> alter tablespace temp tablespace group '';
Tablespace altered.
SQL> select * from dba_tablespace_groups;
GROUP_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
GROUP1                         ZYP_TEMP2
--查看default临时表空间
SQL> select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE';
PROPERTY_NAME
------------------------------
PROPERTY_VALUE
--------------------------------------------------------------------------------
DESCRIPTION
--------------------------------------------------------------------------------
DEFAULT_TEMP_TABLESPACE
GROUP1
Name of default temporary tablespace
--删除组对应的表空间(注意:由于zyp_temp2是组group1的唯一成员,当删除他是group1也会被删除,但是当前group1是default tablespace,故删除会报错!)
SQL> drop tablespace zyp_temp2;
drop tablespace zyp_temp2
*
ERROR at line 1:
ORA-10921: Cannot drop tablespace belonging to default temporary tablespace
group
--切换default tablespace
SQL> alter database default temporary tablespace temp;
Database altered.
SQL> select * from database_properties where property_name='DEFAULT_TEMP_TABLESPACE';
PROPERTY_NAME
------------------------------
PROPERTY_VALUE
--------------------------------------------------------------------------------
DESCRIPTION
--------------------------------------------------------------------------------
DEFAULT_TEMP_TABLESPACE
TEMP
Name of default temporary tablespace
SQL> drop tablespace zyp_temp2;
Tablespace dropped.
SQL> select * from dba_tablespace_groups;
no rows selected
SQL>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28278387/viewspace-746939/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/28278387/viewspace-746939/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值