oracle臨時表空間的作用與創(chuàng)建及相關(guān)操作詳解
1.1 臨時表空間作用
用來存放用戶的臨時數(shù)據(jù),臨時數(shù)據(jù)就是在需要時被覆蓋,關(guān)閉數(shù)據(jù)庫后自動刪除,其中不能存放永久臨時性數(shù)據(jù)。
如:
當(dāng)用戶對大量數(shù)據(jù)進行排序時,排序在PGA中進行,若數(shù)據(jù)過多,導(dǎo)致內(nèi)存不足,oracle會把需要排序的數(shù)據(jù)分為多份,每次取一份在PGA中排序,其余部分放在臨時表空間,直至所有數(shù)據(jù)排序完成,不過臨時表空間在硬盤上,數(shù)據(jù)交換降低性能
1.2 臨時表空間和臨時表空間組
臨時表空間組是由一組臨時表空間組成的組,臨時表空間組和臨時表空間不能同名。臨時表空間組不能顯式地被創(chuàng)建和刪除;當(dāng)把第一個臨時表空間分配某個臨時表空間組時,會自動創(chuàng)建臨時表空間組;當(dāng)把臨時表空間組內(nèi)最后一個臨時表空間刪除時,會自動刪除臨時表空間組;
1.3 臨時表空間操作
(1) 查看表空間
select * from v$tablespace;

(2) 查看表空間詳細(xì)信息
select * from dba_tablespaces;
CONTENTS字段值為TEMPORARY,即臨時表空間

(3) 查看除臨時表空間外 表空間對應(yīng)的數(shù)據(jù)文件
select * from dba_data_files;

(4) 查看臨時表空間對應(yīng)的數(shù)據(jù)文件
select * from dba_temp_files;

select * from v$tempfile;

(5) 查看臨時表空間組信息
select * from dba_tablespace_groups;

(6) 查看默認(rèn)的臨時表空間
select * from database_properties where PROPERTY_NAME='DEFAULT_TEMP_TABLESPACE';


1.4 創(chuàng)建臨時表空間
(1) 創(chuàng)建不屬于組的臨時表空間
create temporary tablespace temp2 tempfile 'D:\software\oracle\oradata\orcl\temp2a.dbf' size 10m autoextend on ;

(2) 屬于組的臨時表空間
create temporary tablespace temp3 tempfile 'D:\software\oracle\oradata\orcl\temp3a.dbf' size 10m autoextend on tablespace group temp_group ;

(2) 臨時表空間加入或移除臨時表空間組
把temp2加入到temp_group 中
alter tablespace temp2 tablespace group temp_group;

把temp2移除emp_group
alter tablespace temp2 tablespace group '';

(3)給臨時表空間添加一個臨時文件

alter tablespace temp2 add tempfile 'D:\software\oracle\oradata\orcl\temp2b.dbf' size 10m autoextend on;

(4)修改系統(tǒng)默認(rèn)的臨時表空間
修改為一個組
alter database default temporary tablespace temp_group ;

修改為一個臨時表空間
alter database default temporary tablespace temp2;

補充:對臨時文件進行刪除
alter tablespace temp drop tempfile '/m/oracle/oradata4/temp05.dbf'; alter tablespace temp drop tempfile '/m/oracle/oradata5/temp06.dbf'; alter tablespace temp drop tempfile '/m/oracle/oradata5/temp07.dbf'; alter tablespace temp add tempfile '/m/oracle/oradata4/temp05.dbf' size 1G reuse; alter tablespace temp add tempfile '/m/oracle/oradata5/temp06.dbf' size 1G reuse; alter tablespace temp add tempfile '/m/oracle/oradata5/temp07.dbf' size 1G reuse;
刪除過程:
SQL> alter database tempfile '/u01/app/oracle/oradata/temp2' drop including datafiles;
alter database tempfile '/u01/app/oracle/oradata/temp2' drop including datafiles
*
ERROR at line 1:
ORA-25152: TEMPFILE cannot be dropped at this time
通過查看官方針對ORA-25152的描述信息,發(fā)現(xiàn)如下:
ORA-25152: TEMPFILE cannot be dropped at this time
Cause: An attempt was made to drop a TEMPFILE being used by online users
Action: The TEMPFILE has been taken offline. Try again, later
可能是臨時表空間被占用,執(zhí)行以下腳本,查詢出占用臨時表空間的會話信息,使用alter system kill命令殺掉會話進程,即可解決問題。
也可以等待一段時間之后,對臨時表空間臨時文件進行刪除即可 。
總結(jié)
到此這篇關(guān)于oracle臨時表空間的作用與創(chuàng)建及相關(guān)操作的文章就介紹到這了,更多相關(guān)oracle臨時表空間創(chuàng)建內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
一文解決ORA-01034:?ORACLE?not?available報錯
這篇文章主要給大家介紹了關(guān)于ORA-01034:?ORACLE?not?available報錯解決的相關(guān)資料,這是oracle數(shù)據(jù)庫啟動經(jīng)常會遇到的問題,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2024-03-03
oracle數(shù)據(jù)庫ORA-01196錯誤解決辦法分享
這篇文章主要介紹了oracle數(shù)據(jù)庫ORA-01196錯誤解決辦法分享,小編覺得還是挺不錯的,這里分享給大家,供需要的朋友參考。2017-10-10
Oracle數(shù)據(jù)庫中ora-12899錯誤的解決方法
大家在使用oracle數(shù)據(jù)庫時,經(jīng)常會遇到各種各樣的問題,其中ORA-12899就是前段時間我在將數(shù)據(jù)導(dǎo)入到我本地機器上的時候一直出現(xiàn)的問題.經(jīng)過一番倒騰問題順利解決,下面小編把實現(xiàn)思路分享到腳本之家平臺大家可以參考下2017-11-11
Linux系統(tǒng)下導(dǎo)出ORACLE數(shù)據(jù)庫出現(xiàn)Exporting questionable statistics.錯誤 處理
Linux系統(tǒng)下導(dǎo)出ORACLE數(shù)據(jù)庫出現(xiàn)Exporting questionable statistics.錯誤 處理...2007-03-03

