您的位置:首页 > 数据库 > Oracle

Oracle Tablespace

2015-08-25 21:47 489 查看
我们知道oarcle数据库真正存放数据的是数据文件(data files),Oarcle表空间(tablespaces)实际上是一个逻辑的概念,他在物理上是并不存在的,那么把一组data files 捻在一起就成为一个表空间。

表空间属性:

一个数据库可以包含多个表空间,一个表空间只能属于一个数据库

一个表空间包含多个数据文件,一个数据文件只能属于一个表空间

表这空间可以划分成更细的逻辑存储单元

1、创建表空间

1) 创建表空间ts01

SQL> create tablespace ts01 datafile 'D:\install\oracle\product\10.2.0\oradata\orcl\df01.dbf' size 10M uniform size 128k;


2) 创建表table01放入表空间ts01
SQL> create table table01(id number,name varchar2(10)) tablespace ts01;

2、扩展表空间

1) 增加数据文件

SQL> alter tablespace ts01 add datafile 'D:\install\oracle\product\10.2.0\oradata\orcl\df02.dbf' size 10M;
2) 手工改变已存在数据文件的大小
SQL> alter database datafile 'D:\install\oracle\product\10.2.0\oradata\orcl\df01.dbf' resize 20M;
3) 允许已存在的数据文件自动增长
SQL> alter database datafile 'D:\install\oracle\product\10.2.0\oradata\orcl\df01.dbf' autoextend on next 10M maxsize 500M;
4) 新增数据文件,并且允许数据文件自动增长
SQL> alter tablespace ts01 add datafile 'D:\install\oracle\product\10.2.0\oradata\orcl\df03.dbf'
size 10M autoextend on next 10M maxsize 500M;


3、移动数据文件

1) 确定数据文件所在表空间

SQL> select tablespace_name from dba_data_files where
file_name='D:\INSTALL\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\DF01.DBF';
2) 使表空间脱机(确保数据文件一致性)
SQL> alter tablespace ts01 offline;
3) 移动数据文件到指定位置(Command Window)
CMD> host move D:\install\oracle\product\10.2.0\oradata\orcl\df01.dbf D:\df01.dbf
4) 执行alter tablespace命令
SQL> alter tablespace ts01 rename datafile 'D:\install\oracle\product\10.2.0\oradata\orcl\df01.dbf' to 'D:\df01.dbf';
5) 使表空间联机
SQL> alter tablespace ts01 online;


4、删除表空间(drop tablespace ts01)

1) 删除表空间中的segments

SQL> drop tablespace ts01 including contents;
2) 删除表空间中的segments和datafiles
SQL> drop tablespace ts01 including contents and datafiles;
3) 删除所有与该空间相关的完整性约束条件
SQL> drop tablespace ts01 cascade constraints;


5、修改表空间状态

1) 使表空间脱机

SQL> alter tablespace ts01 offline;
2) 使表空间联机
SQL> alter tablespace ts01 online;
3) 只读表空间(不能在该表空间上执行update、delete、insert)
SQL> alter tablespace ts01 read only;
4) 取消表空间只读
SQL> alter tablespace ts01 read write;


6、其它

1) 显示该表空间所有表

SQL> select * from all_tables where tablespace_name='TS01';
2) 查询表属于哪个表空间
SQL> select tablespace_name,table_name from user_tables where table_name='TABLE01';
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: