临时表空间

临时表空间

11g之前(不包括11g)临时表空间不会自动释放其内容,除非重启数据库;但11g之后可通过shrink方法来搜索临时表空间。

临时表空间消耗的主要操作有:
1.order by
2.group by
3.distinct
4.union [all]
5.create[|rebuild] index
6.analyze

1.查询数据库默认临时表空间
select * from database_properties where property_name=upper('default_temp_tablespace');

2.更改数据库默认临时表空间
alter database default temporary tablespace temp;

3.查询临时表空间的使用情况
select  FILE_NAME
       ,TABLESPACE_NAME
       ,ROUND(BYTES/1024/1024/1024,2)||'G' BYTES
       ,AUTOEXTENSIBLE
       ,ROUND(MAXBYTES/1024/1024/1024,2)||'G' MAXBYTES
       ,INCREMENT_BY||'M' INCREMENT_BY
       ,ROUND(USER_BYTES/1024/1024/1024,2)||'G' USER_BYTES
from dba_temp_files;
select tablespace_name,tablespace_size,allocated_space,free_space from dba_temp_free_space;
注:视图dba_temp_free_space的tablespace_size等于视图dba_temp_files的bytes;
视图dba_temp_free_space的free_space等于视图dba_temp_files的bytes-user_bytes;
视图dba_temp_free_space的allocated_space表示分配(next)出去的空间大小,它既包含不可用的空间部分,同样也包含可以的空间部分,因此它不一定等于free_space。

4.创建临时表空间
create temporary tablespace temp tempfile '/u02/oradata/orcl/temp01.dbf' size 10m autoextend on next 1m maxsize unlimitied;

5.扩大临时表空间
alter database tempfile '/u02/oradata/orcl/temp01.dbf' resize 500m;
alter tablespace temp add tempfile '/u02/oradata/orcl/temp02.dbf' size 10m autoextend on next 1m maxsize unlimitied;

6.删除临时表空间
删除临时表空间的某个数据文件
alter database tempfile '/u02/oradata/orcl/temp02.dbf' drop;
删除临时表空间(彻底删除)
drop tablespace temp including contents and datafiles;
删除数据库默认的临时表空间:
create temporary tablespace ...=>alter database default tablespace ...=>drop tablespace ...

7.收缩临时表空间
将临时表空间temp收缩为10m
alter tablespace temp shrink space keep 10m;
自动收缩临时表空间的某个数据文件到最小可能的大小
alter tablespace temp shrink tempfile '/u02/oradata/orcl/temp01.dbf';

原文地址:https://www.cnblogs.com/riskyer/p/3341911.html