表空間

一、表空間概念

oracle 表空間是一個(gè)邏輯概念,創(chuàng)建時(shí)需要指定物理文件,及實(shí)際數(shù)據(jù)分配磁盤空間,一個(gè)數(shù)據(jù)庫由多個(gè)表空間組成,一個(gè)表空間可以對(duì)應(yīng)多個(gè)數(shù)據(jù)文件

二、 表空間的分類

表空間包含3種表空間:永久表空間、臨時(shí)表空間、undo表空間

永久表空間:用于存儲(chǔ)永久化存放的東西,如:表、視圖

臨時(shí)表空間:用于存儲(chǔ)數(shù)據(jù)庫操作當(dāng)中中間執(zhí)行的過程,當(dāng)執(zhí)行結(jié)束自動(dòng)釋放數(shù)據(jù)(系統(tǒng)自帶的臨時(shí)表空間TEMP)

undo表空間:用于保存事務(wù)所修改數(shù)據(jù)的舊值,被修改之前的數(shù)據(jù),可以對(duì)數(shù)據(jù)進(jìn)行回滾及撤銷操作(系統(tǒng)自帶的undo表空間UNDOTBS1)

備注:普通用戶一般默認(rèn)的表空間為USERS,sys和system用戶默認(rèn)的表空間為SYSTEM

修改用戶默認(rèn)或臨時(shí)表空間 :alter user 用戶名 default|temporary tablespace 表空間名;例如:alter user scott default tablespace system;(管理員才有權(quán)更改)

查看用戶的默認(rèn)表空間和臨時(shí)表空間可以在數(shù)據(jù)字典dba_users中查看,查看當(dāng)前用戶的信息可在user_users中查看

三、表空間的創(chuàng)建

3.1 、永久|臨時(shí)表空間的創(chuàng)建永久表空間:create tablespace 表空間名 datafile 文件名 size 文件大小(文件后綴名為.dbf,若要一次性創(chuàng)建多個(gè)數(shù)據(jù)文件,文件大小后用逗號(hào)隔開)

臨時(shí)表空間:create temporary tablespace 表空間名 tempfile 文件名 size 文件大小(文件后綴名為.dbf)

例如:create tablespace test1 datafile 'test1file.dbf' size 10m;

create temporary tablespace temptest1 tempfile 'temptest1file.dbf' size 10m;

create tablespace test1 datafile 'test1file.dbf' size 10m,'test2file.dbf' size 10m;

數(shù)據(jù)字典:dba_data_files(永久表空間)dba_temp_files(臨時(shí)表空間)

3.2、 數(shù)據(jù)文件的擴(kuò)展

數(shù)據(jù)文件的擴(kuò)展:create tablespace 表空間名 datafile 文件名 size 文件大小 autoextend on

關(guān)閉數(shù)據(jù)文件擴(kuò)展:create tablespace 表空間名 datafile 文件名 size 文件大小 autoextend off

例如:create tablespace test1 datafile 'test1file.dbf' size 10m autoextend on;create tablespace test1 datafile 'test1file.dbf' size 10m autoextend off;

3.3、擴(kuò)展的長度及最大尺寸

指定數(shù)據(jù)文件的增長長度及最大尺度:create tablespace 表空間名 datafile 文件名 size 文件大小 autoextend on next 增長長度 ? ? ? ??maxsize 最大尺度

例如:create tablespace test1 datafile 'test1file.dbf' size 10m autoextend on next 5m maxsize 500m;

若不限制最大尺寸,maxsize 設(shè)置為unlimited例如:create tablespace test1 datafile 'test1file.dbf' size 10m autoextend on next 5m maxsize unlimited;

四、表空間的修改

4.1、表空間名字修改修改表空間名:alter tablespace 舊表空間名 rename to 新表空間名

例如:alter tablespace test1 rename to test2;

4.2、表空間狀態(tài)修改設(shè)置聯(lián)機(jī)或脫機(jī)狀態(tài)

設(shè)置聯(lián)機(jī)狀態(tài)(默認(rèn)讀寫狀態(tài)):alter tablespace 表空間名online

設(shè)置脫機(jī)狀態(tài):aleter tablespace 表空間名 offline

例如: alter tablespace test1 offline;

alter tablespace test1 online;

設(shè)置只讀或可讀寫狀態(tài)(必須聯(lián)機(jī)狀態(tài))

設(shè)置只讀狀態(tài):alter tablespace 表空間名 read only

設(shè)置可讀寫狀態(tài):alter tablespace 表空間名 read write

例如: alter tablespace test1 read only;

alter tablespace test1 read write;備注: 在數(shù)據(jù)字典dba_tablespaces中查看修改的狀態(tài)4.3、數(shù)據(jù)文件修改

增加數(shù)據(jù)文件:alter tablespace 表空間名 add datafile '文件名' size 文件大小

刪除數(shù)據(jù)文件:alter tablespace 表空間名 drop datafile '文件名' (不能刪除第一個(gè)數(shù)據(jù)文件,若要?jiǎng)h除第一個(gè)數(shù)據(jù)文件,必須刪除整個(gè)表空間)

例如:alter tablespace test1 add datafile 'addtest1.dbf' size 10m;alter tablespace test1 drop datafile 'addtest1.dbf';五、表空間的刪除

只刪除表空間,不刪除數(shù)據(jù)文件:drop 表空間名

刪除表空間和數(shù)據(jù)文件:drop 表空間名 including contents and datafiles例如:drop tablespace test1;

drop tablespace test1 including contents and datafiles;

備注:涉及到的數(shù)據(jù)字典有:dba_tablespaces、user_tablespaces、dba_data_files、dba_temp_files、dba_users、user_users

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容