1.
查看錶空間的資訊 Java代碼
- select f.tablespace_name,a.total,u.used,f.free,round((u.used/a.total)*100) "% used",
- round((f.free/a.total)*100) "% Free"
- from
- (select tablespace_name, sum(bytes/(1024*1024)) total
- from dba_data_files group by tablespace_name) a,
- (select tablespace_name, round(sum(bytes/(1024*1024))) used
- from dba_extents group by tablespace_name) u,
- (select tablespace_name, round(sum(bytes/(1024*1024))) free
- from dba_free_space group by tablespace_name) f
- WHERE a.tablespace_name = f.tablespace_name
- and a.tablespace_name = u.tablespace_name;
select f.tablespace_name,a.total,u.used,f.free,round((u.used/a.total)*100) "% used", round((f.free/a.total)*100) "% Free" from (select tablespace_name, sum(bytes/(1024*1024)) total from dba_data_files group by tablespace_name) a, (select tablespace_name, round(sum(bytes/(1024*1024))) used from dba_extents group by tablespace_name) u, (select tablespace_name, round(sum(bytes/(1024*1024))) free from dba_free_space group by tablespace_name) fWHERE a.tablespace_name = f.tablespace_nameand a.tablespace_name = u.tablespace_name;
2.建立資料表空間 Java代碼
- SQL> create tablespace testspace
- datafile 'd:/OracleTest/test001.dbf' size 10m autoextend on next 5m maxsize unlimited
- extent management local ;
SQL> create tablespace testspace datafile 'd:/OracleTest/test001.dbf' size 10m autoextend on next 5m maxsize unlimited extent management local ;
2.給資料表空間添加資料檔案
Java代碼
- SQL> alter tablespace testspace add datafile 'd:/OracleTest/test002.dbf' size 5m
- autoextend on next 3m maxsize 50m;
-
- SQL> alter tablespace testspace add datafile 'd:/OracleTest/test002.dbf' size 5m
- autoextend on next 3m maxsize 50m;
SQL> alter tablespace testspace add datafile 'd:/OracleTest/test002.dbf' size 5m autoextend on next 3m maxsize 50m; SQL> alter tablespace testspace add datafile 'd:/OracleTest/test002.dbf' size 5m autoextend on next 3m maxsize 50m;
3.刪除資料表空間中的資料檔案 Java代碼
- SQL> alter tablespace testspace drop datafile 'd:/OracleTest/test002.dbf';
-
- SQL> alter tablespace testspace drop datafile 'd:/OracleTest/test002.dbf';
SQL> alter tablespace testspace drop datafile 'd:/OracleTest/test002.dbf'; SQL> alter tablespace testspace drop datafile 'd:/OracleTest/test002.dbf';
4.修改資料表空間檔案的資料檔案大小
Java代碼
- SQL> alter database datafile 'd:/OracleTest/test001.dbf' resize 10m;
-
- SQL> alter database datafile 'd:/OracleTest/test001.dbf' resize 10m;
SQL> alter database datafile 'd:/OracleTest/test001.dbf' resize 10m; SQL> alter database datafile 'd:/OracleTest/test001.dbf' resize 10m;
5.修改資料表空間資料檔案的自動成長屬性
Java代碼
- SQL> alter database datafile 'd:/OracleTest/test001.dbf' autoextend off;
-
- SQL> alter database datafile 'd:/OracleTest/test001.dbf' autoextend off;
SQL> alter database datafile 'd:/OracleTest/test001.dbf' autoextend off; SQL> alter database datafile 'd:/OracleTest/test001.dbf' autoextend off;
6.修改資料表空間的讀寫屬性
Java代碼
- SQL> alter tablespace testspace read only;(唯讀)
-
- SQL> alter tablespace testspace read write;(讀寫)
-
- SQL> alter tablespace testspace read only;(唯讀)
-
- SQL> alter tablespace testspace read write;(讀寫)
SQL> alter tablespace testspace read only;(唯讀) SQL> alter tablespace testspace read write;(讀寫) SQL> alter tablespace testspace read only;(唯讀) SQL> alter tablespace testspace read write;(讀寫)
7.設定資料表空間脫/聯機
Java代碼
- SQL> alter tablespace testspace offline;
-
- SQL> alter tablespace testspace online;
-
- SQL> alter tablespace testspace offline;
-
- SQL> alter tablespace testspace online;
SQL> alter tablespace testspace offline; SQL> alter tablespace testspace online; SQL> alter tablespace testspace offline; SQL> alter tablespace testspace online;
8.轉移物理檔案路徑的操作
Java代碼
- (1)設定資料表空間離線 alter tablespac testspace offline;
-
- (2)物理跳躍表空間檔案;即把你的資料表空間物理檔案轉移到你想移動的路徑
-
- (3)邏輯轉移:alter tablespace testspace rename datafile 'd:/OracleTest/test001.dbf' to 'e:/test001.dbf';
-
- (4)設定資料表空間聯機 alter tablespace testspace online;
-
- (1)設定資料表空間離線 alter tablespac testspace offline;
-
- (2)物理跳躍表空間檔案;即把你的資料表空間物理檔案轉移到你想移動的路徑
-
- (3)邏輯轉移:alter tablespace testspace rename datafile 'd:/OracleTest/test001.dbf' to 'e:/test001.dbf';
-
- (4)設定資料表空間聯機 alter tablespace testspace online;
(1)設定資料表空間離線 alter tablespac testspace offline; (2)物理跳躍表空間檔案;即把你的資料表空間物理檔案轉移到你想移動的路徑 (3)邏輯轉移:alter tablespace testspace rename datafile 'd:/OracleTest/test001.dbf' to 'e:/test001.dbf'; (4)設定資料表空間聯機 alter tablespace testspace online; (1)設定資料表空間離線 alter tablespac testspace offline; (2)物理跳躍表空間檔案;即把你的資料表空間物理檔案轉移到你想移動的路徑 (3)邏輯轉移:alter tablespace testspace rename datafile 'd:/OracleTest/test001.dbf' to 'e:/test001.dbf'; (4)設定資料表空間聯機 alter tablespace testspace online;
9.刪除資料表空間
Java代碼
- (1)不刪檔案 drop tablespace testspace;
-
- (2)刪除檔案 drop tablespace testspace including contents and datafiles;
-
- (1)不刪檔案 drop tablespace testspace;
-
- (2)刪除檔案 drop tablespace testspace including contents and datafiles;
(1)不刪檔案 drop tablespace testspace; (2)刪除檔案 drop tablespace testspace including contents and datafiles; (1)不刪檔案 drop tablespace testspace; (2)刪除檔案 drop tablespace testspace including contents and datafiles;
10.物理檔案被非法刪除時,怎樣啟動資料庫
Java代碼
- (1)關閉資料庫服務 shutdown
-
- (2)alter database datafile 'd:/test001.dbf' offline drop;
-
- (3)alter database open;
-
- (4)開啟資料庫服務 startup;
(1)關閉資料庫服務 shutdown (2)alter database datafile 'd:/test001.dbf' offline drop; (3)alter database open; (4)開啟資料庫服務 startup;
11、查看錶空間名
Sql代碼
- Select distinct Tablespace_Name from tabs;
- select tablespace_name from user_tablespaces;
Select distinct Tablespace_Name from tabs; select tablespace_name from user_tablespaces;
執行個體: 建立表時關聯資料表空間 Java代碼
- -- Create tablespace
- create tablespace tab_news datafile 'F:\oradata\NPMS\tab_news.dbf' size 5m autoextend on next 2m maxsize unlimited extent management local;
-
- autoextend on next 2m 代表 以2m的大小自增
-
- -- Create table
- create table NEWS_BBS
- (
- BBSID NUMBER(10) not null,
- PROJECT VARCHAR2(128) not null,
- USERID NUMBER(10),
- CONTENT CLOB,
- ANSWERID NUMBER(10),
- ANSWERCOUNT NUMBER(10),
- PUBLISHTIME DATE
- )
- tablespace NEWS_TAB
- pctfree 10
- initrans 1
- maxtrans 255
- storage
- (
- initial 64
- minextents 1
- maxextents unlimited
- );
-
- -- Create/Recreate primary, unique and foreign key constraints
- alter table NEWS_BBS
- add constraint PK_NEWS_BBS primary key (BBSID)
- using index
- tablespace ET_TAB
- pctfree 10
- initrans 2
- maxtrans 255
- storage
- (
- initial 64K
- minextents 1
- maxextents unlimited
- );