Oracle临时表空间组

时间:2023-03-09 04:34:44
Oracle临时表空间组

Oracle 10g之前,同一用户的多个会话只可以使用同一个临时表空间,因为在给定的时间只有一个临时表空间默认给用户,为了解决这个潜在的瓶颈,Oracle支持临时表空间组即包含多个临时表空间的集合。临时表空间组逻辑上就相当于一个临时表空间。

Example:

 SQL>create temporary tablespace temp1 tempfile '/u01/app/oracle/oradata/orcl/temp01.dbf' size 10M;

 SQL>create temporary tablespace temp2 tempfile '/u01/app/oracle/oradata/orcl/temp02.dbf' size 10M;

 SQL>create temporary tablespace temp3 tempfile '/u01/app/oracle/oradata/orcl/temp03.dbf' size 10M;

 SQL>select name from v$tempfile;

 NAME

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

 /u01/app/oracle/oradata/orcl/temp01.dbf

 /u01/app/oracle/oradata/orcl/temp02.dbf

 /u01/app/oracle/oradata/orcl/temp01.dbf

 SQL>select tablespace_name from dba_tablespaces where contents='TEMPORARY';

 TABLESPACE_NAME

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

 TEMP1

 TEMP2

 TEMP3

 添加temp1,temp2,temp3到临时表空间组tempgrp中

 SQL>alter tablespace temp1 tablespace group tempgrp;

 SQL>alter tablespace temp2 tablespace group tempgrp;

 SQL>alter tablespace temp3 tablespace group tempgrp;

 启用临时表空间组

 SQL>alter database default temporary tablespace tempgrp;

 SQL>select * from dba_tablespace_groups;

 GROUP_NAME                               TABLESPACE_NAME

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

 TEMPGRP                 TEMP1

 TEMPGRP                 TEMP2

 TEMPGRP                 TEMP3

 此时数据库所有用户的默认临时表空间为tempgrp

 SQL>select username,defualt_tablespace,temporary_tablespace from dba_user where username='SCOTT';

 USERNAME                  DEFAULT_TABLESPACE                                  TEMPORARY_TABLESPACE

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

 SCOTT                        USERS                                                          TEMPGRP

 删除临时表空间组

 .必须先删除成员

 SQL>alter tablespace temp1 tablespace group '';(表示删除temp1)

 SQL>select * from dba_tablespace_groups;

 GROUP_NAME                               TABLESPACE_NAME

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

 TEMPGRP                 TEMP2

 TEMPGRP                 TEMP3

 同理将temp2,temp3删除

 当表空间组是数据库默认表空间时,最后一个成员删除报错:ORA-:Defualt temporary tablespace group must be have at least one tablespace

 SQL>alter database default temporary tablespace temp;

 此时再删除最后一个成员,临时表空间组自动消失

 SQL>select * from dba_tablespace_groups;

 no rows selected

 删除temp1表空间及数据文件

 SQL>drop temporary tablespace temp1 including contents and datafiles;