臨時表空間
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';