查看錶空間和資料檔案的資訊
select tablespace_name,file_name,ceil(bytes/1024/1024) mb
from dba_data_files order by 1;
建立資料表空間
CREATE TABLESPACE tanzugan LOGGING DATAFILE 'H:\APP\ZUGANTAN\ORADATA\ORCL2012\tanzugan.dbf'
SIZE 100M REUSE EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
---查看錶空間資訊
select * from dba_data_files order by 1;
------穿插 order by 1 order by2
order by 1按照第一列排序
order by 2 按照第二列排序
若只有2列 寫成了 order by 3就會報錯。
-------------------
加入新的資料檔案
alter tablespace ts1 add datafile 'D:\Oracle\ORADATA\Ora10\ts1.2' size 2m;
資料檔案只能加入,不能刪除,除非將資料表空間刪除。但在10G資料庫版本可以刪除
--------------------刪除資料表空間 資料檔案
alter tablespace ts1 drop datafile 'D:\ORACLE\ORADATA\ORA10\TS1.2';
-----------------------------------------
改變資料檔案的大小
可以加大,也可以縮小
Alter database datafile ‘…..’ resize 100m;
資料檔案的自動擴充
select FILE_NAME,AUTOEXTENSIBLE,MAXBLOCKS,
INCREMENT_BY from dba_data_files;
改為自動擴充
alter database datafile 'D:\ORACLE\ORADATA\O10\TS1.1'
autoextend on next 1m maxsize 100m;
改為手工擴充
alter database datafile 'D:\ORACLE\ORADATA\O10\TS1.1'
Autoextend off;
資料表空間唯讀
Alter tablespace users read only;
驗證
select TABLESPACE_NAME,STATUS from dba_tablespaces;
讀寫
Alter tablespace users read write;
唯讀資料表空間內的表不能dml,但可以drop .
因為DROP操作的是system資料表空間,SYSTEM資料表空間不能設為唯讀。
Offline資料表空間
alter tablespace users offline;
驗證
select TABLESPACE_NAME,STATUS from dba_tablespaces;
線上
alter tablespace users online;
只有完整的資料檔案才可以online,如果不完整請恢複。
恢複一致後再online;
檔案online時使用者才可以訪問
更多Oracle相關資訊見Oracle 專題頁面 http://www.bkjia.com/topicnews.aspx?tid=12