1. 程式人生 > >管理表空間和資料檔案常用指令碼

管理表空間和資料檔案常用指令碼

1.新建表空間(本地管理方式)
(1)普通表空間
create tablespace autotbs
datafile '/oracle/autotbs01.dbf' size 100M
extent management local autoallocate;
(2)臨時表空間
create temporary tablespace lmtemp
tempfile 'I:\oracle\oradata\lmtemp01.dbf' size 50M reuse
extent management local uniform size 136K;
要建立本地管理方式的 臨時表空間,必須使用create temporary tablespace,並且區的分配管理方式
只能是uniform,而不能是autoallocate,這樣才能保證不會在臨時段中產生過多的儲存碎片。

2.設定表空間離線聯機
alter tablespace autotbs offline;
alter tablespace autotbs online;

3.設定表空間為只讀/可讀可寫
alter tablespace autotbs read only;
alter tablespace autotbs read write;

4.新增表空間資料檔案
為普通表空間新增資料檔案:
alter tablespace autotbs add datafile '/oracle/autotbs02.dbf' size 100M
為臨時表空間新增資料檔案:
alter tablespace lmtemp add tempfile '/oracle/lmtemp02.dbf' size 10M reuse;

5.改變資料檔案大小
(1)設定資料檔案為自動增長方式
-----------------
alter tablespace autotbs
add datafile '/oracle/autotbs02.dbf' size 50M
autoextend on next 5M maxsize 100M;
-----------------
alter database datafile '/oracle/autotbs01.dbf'
autoextend on next 1M maxsize 200M;
(2)手工改變資料檔案的大小
alter database datafile '/oracle/autotbs01.dbf' resize 500M;

6.改變資料檔案可用性
alter database datafile '/oracle/autotbs01.dbf' online/offline;

7.刪除表空間
drop tablespace autotbs including contents and datafiles;

8.查詢
(1)查詢表空間的預設儲存引數
select tablespace_name,initial_extent,next_extent,min_extents,max_extents,pct_increase
from dba_tablespaces;
(2)查詢表空間的資料檔案資訊
select file_name,blocks,tablespace_name
from dba_data_files;
(3)查詢資料檔案的基本資訊
select name,file#,Rfile#,status,bytes,checkpoint_change# lase_scn
from v$datafile;
(4)查詢資料檔案的自動增長方式
select tablespace_name,file_name,autoextensible from dba_data_files;