Oracle資料表空間

來源:互聯網
上載者:User

標籤:

建立資料表空間等等

select tablespace_name from dba_tablespaces;--dba許可權使用者查詢資料庫中的資料表空間
select * from all_tables where tablespace_name=‘tablespace_name‘;--查詢資料表空間中的表,注意大寫
select tablespace_name,table_name from user_tables where table_name=‘tb_Employee‘;--查詢表處於哪個資料表空間

--建立使用者的時候定義預設資料表空間,設定使用者預設的資料表空間和臨時的資料表空間,並設定使用者建立的資料對象最大隻能是3m,設定初始賬戶為鎖定狀態
create user db_user identified by password default tablespace tablespace_name temporary tablespace tablespace_name quota 3m on tablespace_name account lock;
create tablespace tablespace_name datafile ‘E:\tablespace_name.dbf‘ size 20m uniform size 128k;--建立資料表空間
create table table_name(deptno number(4),dname varchar2(14),loc varchar2(13)) tablespace tablespace_name;--為表指定資料表空間
create index index_name on table_name(column_name) tablespace tablespace_name;--為索引指定資料表空間
alter user db_user default tablespace tablespace_name;--修改使用者預設資料表空間
擁有unlimited tablespace許可權的使用者可在任意資料表空間上操作(grant unlimited tablespace to db_user)。沒有unlimited tablespace許可權的使用者要在非預設資料表空間上操作需要在目標資料表空間有一定的配額,即在目標資料表空間分配給使用者一定的空間或者不限制空間。
alter user db_user quota 100m||unlimited on tablespace_name;

 

改變資料表空間的狀態

當建立資料表空間時,資料表空間處於聯機的(online)狀態,此時該資料表空間是可以訪問的,並且該資料表空間是可以讀寫的,即可以查詢該資料表空間的資料,而且還可以在資料表空間執行各種語句。但是在進行系統維護或是資料維護時,可能需要改變資料表空間的狀態。一般情況下,由特權使用者或是dba來操作。
alter tablespace tablespace_name offline;--1. 使資料表空間離線
alter tablespace tablespace_name online;--2. 使資料表空間聯機 
當建立資料表空間時,資料表空間可以讀寫,如果不希望在該資料表空間上執行update,delete,insert操作,那麼可以將資料表空間修改為唯讀
alter tablespace tablespace_name read only;--3. 唯讀資料表空間
(修改為可寫是 alter tablespace tablespace_name read write;)
我們給大家舉一個執行個體,說明唯讀特性:
select * from all_tables where tablespace_name=‘tablespace_name‘;--知道tablespace_name,顯示該資料表空間包括的所有表,查詢資料表空間中的表,注意大寫
select tablespace_name, table_name from user_tables where table_name=‘tb_Employee‘;--知道table_name,查看該表屬於那個資料表空間
通過2.我們可以知道system.tb_Employee是在system這個資料表空間上,現在我們可以將system改為唯讀但是我們不會成功,因為system是系統資料表空間,如果是普通資料表空間,那麼我們就可以將其設為唯讀,給大家做一個示範,可以加強理解。
alter tablespace tablespace_name read only;
alter tablespace tablespace_name read write;--使資料表空間可讀寫

一般情況下,由特權使用者或是dba來操作,如果是其它使用者操作,那麼要求使用者具有drop tablespace系統許可權。
drop tablespace tablespace_name including contents and datafiles;--刪除資料表空間
說明:including contents表示刪除資料表空間時,刪除該空間的所有資料庫物件,而datafiles表示將資料庫檔案也刪除。

 

 

擴充資料表空間

資料表空間是由資料檔案組成的,資料表空間的大小實際上就是資料檔案相加後的大小。那麼我們可以想象,假定表emp存放到tablespace_name資料表空間上,初始大小就是2m,當資料滿2m空間後,如果在向emp表插入資料,這樣就會顯示空間不足的錯誤。
案例說明:
1. 建立一個資料表空間 fj01
2. 在該資料表空間上建立一個普通表 mydment 其結構和dept一樣
3. 向該表中加入資料 insert into mydment select * from dept;
4. 當一定時候就會出現無法擴充的問題,怎麼辦?
5. 就擴充該資料表空間,為其增加更多的儲存空間。有三種方法:
1. 增加資料檔案
alter tablespace fj01 add datafile ‘E:\fj01.dbf‘ size 20m;
2. 增加資料檔案的大小
alter tablespace tablespace_name ‘E:\fj01.dbf‘ resize 20m;
這裡需要注意的是資料檔案的大小不要超過500m。
3. 設定檔案的自動成長。
alter tablespace tablespace_name ‘E:\fj01.dbf‘ autoextend on next 10m maxsize 500m extend management local;

刪除資料表空間及其所有內容,同時刪除其所對應的資料檔案:
drop tablespace tablespace_name including contents and datafiles;
刪除資料表空間及其所有內容,同時刪除其所對應的資料檔案,以及其他資料表空間中與資料表空間相關的參照完整性條件約束:
drop tablespace tablespace_name including contents and datafiles cascade constraints;

Oracle資料表空間

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.