Oralce tablespace表空间创建和管理
原文:http://takeme.iteye.com/blog/1622659
dba_tablespaces.dbf表空间状态扩展表空间移动数据文件
1.表空间的概述
1.表空间是数据库的逻辑组成部分。
2.从物理上讲,数据库数据存放在数据文件中;
3.从逻辑上讲,数据库是存放在表空间中,表空间由一个或者多个数据文件组成。
2.oracle的逻辑组成
1.oracle 的逻辑结构包含 表 空间 段 区 块
2.数据库是由表空间构成,表空间又是有段构成,段是由区构成,区是由 oracle的块构成,这样做是为了提高数据库的效率
3.作用
A.控制数据库占用的磁盘空间
B dba 可以将不同数据类型部署到不同的位置,这样 有利于i/0的性能,同时利于备份和恢复等管理
3.查询Oracle的表空间
select tablespace_name from dba_tablespaces;
crate tablesapce data01 datafile 'd:\test\data01.dbf' size 20m uniform size 128k; // 说明:创建一个名称为 data01 的表空间,并为该表空间建立一个名称为data.01.dbf的数据文件,区的大小为128k
1.create table mydept(deptno number(4),dname varchar2(14),loc varchar2(13)) tablespace data01;//如果不指定表空间,就默认放在 SYSTEM 表空间下 2. create table emp(empno,ename) tablespace data01 as select empno,ename from scott.emp; //利用其他方案的表创建自己的表后放在自定义表空间下
alter tablespace 表空间名 offline;
alter tablespace 表空间名 online;
alter tablespace 表空间 read only; // 当建立表空间时,表空间可以读写,如果不希望在表空间上执行update ,delete ,insert 操作,那么可以将表空间修改为只读
alter tablespace tbs001 read write;
select * from user_tables where TABLESPACE_NAME='DATA01';//个人发现在oralce系统中 系统表 或者 视图 是区分大写)
select tablespace_name,table_name from user_tables where table_name='EMP';
drop tablespace DATA01 including contents and datafiles;// 说明: including contents 表示删除表空间时候,删除该表空间的所有数据对象,而datafiles 表示将数据库文件也删除。
1.添加数据文件 alter tablespace TBS001 add datafile 'd:\tbs002.dbf' size 20m; 2.增加数据文件的大小 alter database datafile 'd:\tbs001.dbf' resize 20m; 3.设置自动增长 alter database datafile 'd:\tbs002.dbf' autoextend on next 10m maxsize 500m; //9i前每个数据文件是有大小的.之后的版本有人说没有大小限制(取决自己磁盘)
select tablespace_name from dba_data_files where file_name='D:\TBS001.DBF';
alter tablespacce tbs001 offline;
host move d:\tbs001.dbf c:\tbs001.dbf;
alter tablespace TBS001 rename datafile 'D:\TBS001.DBF' to 'E:\TBS001.DBF';
alter tablespace TBS001 online;
select * from dba_tablespaces;
select file_name,bytes from dba_data_files where tablesapce_name='TBS001
offline,online, read only, read write;