1、先查詢空閑空間
select tablespace_name,file_id,block_id,bytes,blocks from dba_free_space;
2、增加Oracle資料表空間
先查詢資料檔案名稱、大小和路徑的資訊,語句如下:
select tablespace_name,file_id,bytes,file_name from dba_data_files;
3、修改檔案大小語句如下
alter database datafile '需要增加的資料檔案路徑,即上面查詢出來的路徑'resize 800M;
4、建立Oracle資料表空間
View Code
create tablespace test datafile '/home/app/oracle/oradata/oracle8i/test01.dbf' size 8M autoextend on next 5M maxsize 10M; create tablespace sales datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M autoextend on next 50M maxsize unlimited maxsize unlimited 是大小不受限制 create tablespace sales datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M autoextend on next 50M maxsize 1000M extent management local uniform; unform表示區的大小相同,預設為1M create tablespace sales datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M autoextend on next 50M maxsize 1000M extent management local uniform size 500K; unform size 500K表示區的大小相同,為500K create tablespace sales datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M autoextend on next 50M maxsize 1000M extent management local autoallocate; autoallocate表示區的大小由隨表的大小自動動態改變,大表使用大區小表使用小區 create tablespace sales datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M autoextend on next 50M maxsize 1000M temporary; temporary建立字典管理暫存資料表空間 create temporary tablespace sales tempfile '/home/app/oracle/oradata/oracle8i/sales01.dbf' size 800M autoextend on next 50M maxsize 1000M
建立本地管理暫存資料表空間,如果是暫存資料表空間,所有語句中的datafile都換為tempfile
8i系統預設建立字典管理暫存資料表空間,要建立本地管理暫存資料表空間要加temporary tablespace關鍵字
建立本地管理暫存資料表空間時,不得使用atuoallocate參數,系統預設建立uniform管理方式
5.刪除Oracle資料表空間
DROP TABLESPACE FESCO INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS;
6.為資料表空間增加資料檔案:
alter tablespace sales add datafile '/home/app/oracle/oradata/oracle8i/sales02.dbf' size 800M autoextend on next 50M maxsize 1000M;
建立本地管理臨時Oracle資料表空間,如果是暫存資料表空間,所有語句中的datafile都換為tempfile8i系統預設建立字典管理暫存資料表空間,要建立本地管理暫存資料表空間要加temporary tablespace關鍵字建立本地管理暫存資料表空間時,不得使用atuoallocate參數,系統預設建立uniform管理方式
7、更改自動擴充屬性:
alter database datafile '/home/app/oracle/oradata/oracle8i/sales01.dbf', '/home/app/oracle/oradata/oracle8i/sales02.dbf' '/home/app/oracle/oradata/oracle8i/sales01.dbf autoextend off;
8、建立使用者並指定資料表空間:
create user username identified by passworddefault tablespace test_datatemporary tablespace test_temp;
9、改變資料表空間狀態
View Code
1.使資料表空間離線ALTER TABLESPACE game OFFLINE;如果是意外刪除了資料檔案,則必須帶有RECOVER選項ALTER TABLESPACE game OFFLINE FOR RECOVER; 2.使資料表空間聯機ALTER TABLESPACE game ONLINE;3.使資料檔案離線ALTER DATABASE DATAFILE 3 OFFLINE;4.使資料檔案聯機ALTER DATABASE DATAFILE 3 ONLINE; 5.使資料表空間唯讀ALTER TABLESPACE game READ ONLY; 6.使資料表空間可讀寫ALTER TABLESPACE game READ WRITE;
10、資料表空間分類:
View Code
1.Permanent tablespacecreate tablespace ts_something logging datafile '/dbf1/ts_sth.dbf' size 32m autoextend on next 32m maxsize 2048m extent management local;create tablespace data datafile '/home/oracle/databases/ora10/data.dbf'size 10Mautoextend on maxsize 200Mextent management local uniform size 64K;2.Temporary tablespacecreate temporary tablespace temp_mtr tempfile '/dbf1/mtr_temp01.dbf' size 32m autoextend on next 32m maxsize 2048mextent management local;Note, a temporary tablespace has tempfiles, not datafiles. 3.Undo tablespacecreate undo tablespace ts_undodatafile '/dbf/undo.dbf' size 100M;4.Misc More than one datafile can be created with a single create tablespace command: create tablespace ts_sth datafile 'c:\xx\sth_01.dbf' size 4M autoextend off, 'c:\xx\sth_02.dbf' size 4M autoextend off, 'c:\xx\sth_03.dbf' size 4M autoextend offloggingextent management local;
參考地址:
http://database.51cto.com/art/200910/158936.htm
http://www.adp-gmbh.ch/ora/sql/create_tablespace.html
http://space.itpub.net/13873293/viewspace-605134