Oracle10g新特性:临时表空间组(temporary tablespace group)

    技术2022-05-20  46

    Oracle10g新特性:临时表空间组(temporary tablespace group) 

     

     

    一个临时表空间组至少包含一个临时表空间。

     

    临时表空间组无法显式创建,当第一个临时表空间分配给该组时自动创建,当组内所有临时表空间被移除时自动删除。

     

    临时表空间组支持的操作:

     

    可以将临时表空间从一个组移动到另外一个组(如果组不存在,则自动创建)。 

    可以将组中的临时表空间从组中移除。 

    可以将目前不属于任何组的临时表空间加入一个组。 

    使用临时表空间组的好处:

     

    防止一个临时表空间出现空间不足的问题。 

    同一个用户同时连接多个session时可以使用不同的临时表空间。 

    在并行操作中可以并行使用多个临时表空间。 

    下面给出几个例子:

     

     

     

    1.创建临时表空间组

    SQL> create temporary tablespace temp1

      2  tempfile 'e:/oracle/ora10/oradata/ning/temp101.dbf' size 10m

      3  tablespace group group1;

     

    表空间已创建。

     

    SQL> create temporary tablespace temp2

      2  tempfile 'e:/oracle/ora10/oradata/ning/temp201.dbf' size 10m

      3  tablespace group group1;

     

    表空间已创建。

     

     

     

    2.查看系统中目前存在的临时表空间组的信息

    SQL> select * from dba_tablespace_groups;

     

    GROUP_NAME                     TABLESPACE_NAME

    ------------------------------ ------------------------------

    GROUP1                         TEMP1

    GROUP1                         TEMP2

     

     

     

    3.移动临时表空间到新的临时表空间组

    SQL> alter tablespace temp2 tablespace group group2;

     

    表空间已更改。

     

    SQL> select * from dba_tablespace_groups;

     

    GROUP_NAME                     TABLESPACE_NAME

    ------------------------------ ------------------------------

    GROUP1                         TEMP1

    GROUP2                         TEMP2

     

     

     

    4.将临时表空间从临时表空间组中移出

    SQL> alter tablespace temp2 tablespace group '';

     

    表空间已更改。

     

    SQL> select * from dba_tablespace_groups;

     

    GROUP_NAME                     TABLESPACE_NAME

    ------------------------------ ------------------------------

    GROUP1                         TEMP1

     

     

     

    5.临时表空间组的名字不能和表空间的名字冲突

    SQL> create temporary tablespace temp3

      2  tempfile 'e:/oracle/ora10/oradata/ning/temp301.dbf' size 10m

      3  tablespace group temp3;

    create temporary tablespace temp3

    *

    第 行出现错误:

    ORA-10918: TABLESPACE GROUP name cannot be the same as tablespace name

     

    SQL> create temporary tablespace temp3

      2  tempfile 'e:/oracle/ora10/oradata/ning/temp301.dbf' size 10m

      3  tablespace group temp1;

    create temporary tablespace temp3

    *

    第 行出现错误:

    ORA-01543: 表空间 'TEMP1' 已存在

     

     

    6.删除组中所有的临时表空间后,组会自动删除

    SQL> select * from dba_tablespace_groups;

     

    GROUP_NAME                     TABLESPACE_NAME

    ------------------------------ ------------------------------

    GROUP1                         TEMP1

     

    SQL> drop tablespace temp1 including contents and datafiles;

     

    表空间已删除。

     

    SQL> select * from dba_tablespace_groups;

     

    未选定行

     

     

     

    7.可以将数据库或者用户的默认临时表空间指定为临时表空间组

    SQL> create temporary tablespace temp1

      2  tempfile 'e:/oracle/ora10/oradata/ning/temp101.dbf' size 10m

      3  tablespace group group1;

     

    表空间已创建。

     

    SQL> alter tablespace temp2 tablespace group group1;

     

    表空间已更改。

     

    SQL> select * from dba_tablespace_groups;

     

    GROUP_NAME                     TABLESPACE_NAME

    ------------------------------ ------------------------------

    GROUP1                         TEMP1

    GROUP1                         TEMP2

     

    SQL> alter database default temporary tablespace group1;

     

    数据库已更改。

     

    SQL> alter user ning temporary tablespace group1;

     

    用户已更改。

     

     

     

    8.同一个用户的不同session可以使用不同的临时表空间

     

    首先用sys用户查询

    SQL> select username, session_num, tablespace from v$sort_usage;

     

    未选定行

     

    新开session1执行

    SQL> conn ning/ning

    已连接。

     

    select a.table_name, b.table_name from dict A, dict B order by a.table_name;

     

    新开session2执行

    SQL> conn ning/ning

    已连接。

     

    select a.table_name, b.table_name from dict A, dict B;

     

    sys查询:

    SQL> select username, session_num, tablespace from v$sort_usage;

     

    USERNAME   SESSION_NUM TABLESPACE

    ---------- ----------- ----------

    NING                74 TEMP2

    NING                62 TEMP1

     

    可以发现,同一个用户ning的两个session分别使用了两个不同的临时表空间。

     

     

    参考:Metalink 245645.1

     

     

     


    最新回复(0)