【原创】表空间相关操作
上一篇 / 下一篇 2008-05-05 21:58:03 / 个人分类:Oracle
实验环境:WinXP SP2
数据库版本:10.2.0.1
1. 创建普通表空间(来个最复杂,基本上用的所有的参数的)
create smallfile tablespace test
datafile 'F:\oracle\product\oradata\test\test01.dbf' size 10m
autoextend on next 100k maxsize 100m
extent management local autoallocate
segment space management auto
flashback on
force logging
blocksize 2k
2. 创建bigfile表空间
和创建普通表空间的语法差不多,区别有2个:
将smallfile改为bigfile 表空间只能包含1个数据文件
create bigfile tablespace test03
datafile 'F:\oracle\product\oradata\test\test03.dbf' size 10m
autoextend on next 100k maxsize 100m
extent management local autoallocate
segment space management auto
flashback on
force logging
blocksize 2k
online
3. 创建temp表空间
autoextend on只能设置uniform,不能设置autoallocate
create temporary tablespace "temp01" tempfile
'f:\oracle\product\oradata\test\temp01.dbf' size 10m
autoextend on next 100k maxsize 100m
extent management local uniform. size 1m
tablespace group temptbs_group1
查看temp表空间所属表空间组
sys@TEST>select * from dba_tablespace_groups;
GROUP_NAME TABLESPACE_NAME
------------------------------ ----------------
TEMPTBS_GROUP1 TEMP01
4. 创建undo表空间
create undo tablespace undo02 datafile
'f:\oracle\product\oradata\test\undo02.dbf' size 10m
autoextend on next 100k maxsize 100m
extent management local autoallocate
retention guarantee;
5. alter tablespace
create tablespace 中的除三个语句不能alter外,其余的都可以,这三个语句分别是:
- extent management local autoallocate
- segment space management auto
- blocksize
5.1 重新设置表空间的大小,只能用于bigfile表空间
alter tablespace test resize 5m;
5.2 修改表空间的名称
alter tablespace test rename to t;
5.3 开始进行表空间的在线备份,在begin backup时,会触发checkpoint,在end begin之前可能会生成更多的重做和归档日志信息
alter tablespace test begin backup;
5.4 结束表空间的在线备份
alter tablespace test end backup;
5.5 修改表空间包含的数据文件的名称、位置(需要物理上先移动)
alter tablespace test rename
datafile 'f:\oracle\product\oradata\test\test.dbf'
to 'f:\oracle\product\oradata\test\t.dbf';
5.6给表空间添加数据文件(只能用于smallfile表空间),对于临时表空间将datafile改为tempfile
alter tablespace test ADD DATAFILE 'F:\oracle\product\oradata\test\t.dbf' size 10m;
5.7 从表空间删除数据文件(最后一个文件不能删),对于临时表空间将datafile改为tempfile
alter tablespace test drop DATAFILE 'F:\oracle\product\oradata\test\t.dbf';
5.8 将表空间中的数据文件离线,离线后数据文件里的内容将不能访问,但是表空间并不离线
alter tablespace test datafile offline;
5.9 将离线的数据文件重新上线,对于临时表空间将datafile改为tempfile
alter tablespace test datafile onine;
5.10 将表空间离线
alter tablespace test offline;
5.11将表空间重新上线
alter tablespace test online;
offline的三种模式:
normal:产生checkpoint,将所有的脏块写入数据文件
temporary:产生checkpoint,将所有的脏块写入数据文件,但是不能保证所有的文件是可写的,有些文件可能在online时需要恢复
immediate:不产生checkpoint,在online后需要进行恢复
5.8-11的实验:可以看出datafile offline和 tablespace offline的状态是不一样的
sys@ABC>alter tablespace test datafile offline;
Tablespace altered.
sys@ABC>select name,status from v$datafile;
NAME STATUS
----------------------------------------- --------------
F:\ORACLE\PRODUCT\ORADATA\ABC\TEST01.DBF RECOVER
F:\ORACLE\PRODUCT\ORADATA\ABC\TEST01A.DBF RECOVER
sys@ABC>selecttablespace_name,status from dba_tablespaces;
TABLESPACE_NAME STATUS
------------------------------------------------------------ ---------
TEST ONLINE
sys@ABC>select tablespace test offline;
Tablespace altered.
sys@ABC>select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME STATUS
------------------------------------------------------------ -----------
TEST OFFLINE
5.12 将表空间设为只读
alter tablespace test read only;
5.13 将表空间设为可读可写
alter tablespace test read write;
6. 删除表空间
6.1 删除表空间并同时删除物理数据文件
drop tablespace test including contents and datafiles;
6.2 删除表空间但保留删除物理数据文件
drop tablespace test including contents keep datafiles;
6.3 删除表空间的同时删除其他表空间中表与此表空间中表之间的外键约束
drop tablespace test cascade constraints;
导入论坛 引用链接 收藏 分享给好友 推荐到圈子 管理 举报
TAG:

