create tablespace data01
datafile \’/oracle/oradata/db/data01.dbf\’ size 500m
uniform size 128k; #指定区尺寸为128k,如不指定,区尺寸默认为64k
删除表空间
drop tablespace data01 including contents and datafiles;
修改表空间大小
alter database datafile \’/path/naddate05.dbf\’ resize 100m
移动表至另一表空间
alter table move tablespace room1;
一、建立表空间
create tablespace data01
datafile \’/oracle/oradata/db/data01.dbf\’ size 500m
uniform size 128k; #指定区尺寸为128k,如不指定,区尺寸默认为64k
二、建立undo表空间
create undo tablespace undotbs02
datafile \’/oracle/oradata/db/undotbs02.dbf\’ size 50m
#注意:在open状态下某些时刻只能用一个undo表空间,如果要用新建的表空间,必须切换到该表空间:
alter system set undo_tablespace=undotbs02;
三、建立临时表空间
create temporary tablespace temp_data
tempfile \’/oracle/oradata/db/temp_data.dbf\’ size 50m
四、改变表空间状态
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;
五、删除表空间
drop tablespace data01 including contents and datafiles;
六、扩展表空间
首先查看表空间的名字和所属文件
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space
from dba_data_files
order by tablespace_name;
1.增加数据文件
alter tablespace game
add datafile \’/oracle/oradata/db/game02.dbf\’ size 1000m;
2.手动增加数据文件尺寸
alter database datafile \’/oracle/oradata/db/game.dbf\’
resize 4000m;
3.设定数据文件自动扩展
alter database datafile \’/oracle/oradata/db/game.dbf\’
autoextend on next 100m
maxsize 10000m;
4.设定后查看表空间信息
select a.tablespace_name,a.bytes total,b.bytes used, c.bytes free,
(b.bytes*100)/a.bytes \”% used\”,(c.bytes*100)/a.bytes \”% free\”
from sys.sm&ts_avail a,sys.sm&ts_used b,sys.sm&ts_free c
where a.tablespace_name=b.tablespace_name and a.tablespace_name=c.tablespace_name;
5.oracle表空间的备份与恢复方法
表空间备份与恢复主要针对于大型数据库中,某个表空间数据变化非常大,增长速度非常快的情况。表空间的备份实现脚本:
run {
allocate channel d1 type disk;
backup tablespace \”test\”,\”users\” format ’d:\\backup\\tb_%d_%s_%p_%t’;
release channel d1;
}
恢复时,如果用户是要恢复被删除的表空间中的表或视图,或者是使用者用drop tablespace正常命令删除了表空间,此时控制文件中记录的数据库结构也跟着做了改变,此时只能用不完全恢复,让数据库恢复到以前的一个时间点或scn。先恢复控制文件,再恢复表空间。
shutdown abort;
startup nomount;
run {
allocate channel d1 type disk;
restore controlfile from ‘d:\\backup\\ctl_test_0_1_6555’;
release channel d1 ;
alter database open; //要为打开状态
set until time \”to_date(’08/08/2007 10:50:00’,’mm/dd/yyyy hh24:mi:ss’)\”;
sql ’alter tablespace test, users offline immediate’;
allocate channel d1 type disk;
restore tablespace test, users;
recover tablespace test, users;
release channel d1;