Oracle表空间管理

--查看默认表空间
select * from dba_tablespaces;
--6个默认表空间
EXAMPLE:用于安装Oracle11g数据库使用的示例数据库。
SYSAUX:作为EXAMPLE的辅助表空间。
SYSTEM:由于存储sys用户的表、视图以及存储过程等数据对象。
TEMP:由于存储SQL语句处理的表和索引的信息。
UNDOTBS1:由于存储撤销信息。
USERS:存储数据库用户创建的数据库对象。


--查看用户的默认表空间
select * from dba_users;
select * from v$datafile;


--创建表空间
create tablespace tablespace_name
datafile filename size [大小]
[autoextend [on/off]] next [大小]
[maxsize] [大小]
[permanent | temporary]
[extent management [dictionary 
| local [autoallocate 
| uniform.[size integer[K|M]]]]]

--语法说明
tablespace_name:表空间名称。
datafile filename:指定表空间中存放文件的文件名,必须指出文件存放路径。
autoextend :指定数据文件的扩展方式,on 代表自动扩展, off 代表非自动扩展
next :自动扩展的大小。
maxsize :表空的扩展上线,也就是表空间的最大值。
permanent | temporary :表空间的类型,permanent 永久表空间; temporary 临时表空间。
extent management [dictionary | local]:表空间的管理模式。dictionary 字典管理模式,local 本地管理模式。默认为本地管理模式。


--重命名表空间
Alter tablespace oldname rename newname;

--修改表空间的读写状态
alter tablespace sapce_name read [only | write];

--设置表空间的可用状态
alter tablespace space_name [online | offline [ normal | temporary | immediate]]
online:联机状态、即可用状态。
offline:脱机状态,不可用状态。
normal:脱机状态,正常状态。
temporary:脱机状态,临时状态。
immediate:脱机状态,立即状态。

--创建大文件表空间
create bigfile tablespace space_name
datafile filename size [大小]

--删除表空间
drop tablespace space_name [including contents] [ cascade constraints]
including contents:删除表空间时把表空间里的数据也删除。
cascade constraints:删除表空间时把表空间的完整性也删除。

--临时表空间管理
临时表空间一般指在数据库中存储数据,当内存不够时写入的空间,当执行完对数据的操作后,临时
表空间会自动清空。
--创建临时表空间
create temporary tablespace space_name
tempfile 'tempspace.dbf' size 10M;
--设置临时表空间为默认表空间
alter database default temporary tablespace space_name;

--查询临时表空间
select * from dba_temp_files;

--创建临时表空间组
--创建临时表空间是添加到临时表空间组
create temporary tablespace space_name
tempfile 'tempspace.dbf' size 10M tablespace group group_name;
--将临时表空间移动到临时表空间组
alter tablespace space_name tablespace group group_name;

--查询临时包空间组
select * from dba_tablespace_groups;

--删除临时表空间组
drop tablespace space_name including contents and datafiles;

--数据文件管理
--移动数据文件
1、设置数据文件所用的表空间设置为脱机状态
alter tablespace sapce_name offline;
2、可以手动将移动的文件移动到其他的表空间或其他数据库内。
3、更改数据文件的名称。
alter tablespace space_name rename datafile oldfilename to new filename;
4、把该表空间设置为联机状态。
alter tablespace space_name online;


--删除数据文件
alter tablespace space_name drop datafile 'filename';

 

posted on 2017-03-15 20:22  拿着菜刀  阅读(506)  评论(0编辑  收藏  举报

导航