Oracle表空间管理
2011-09-17 19:21
369 查看
1.创建表空间
SQL> create tablespace testspace
datafile 'd:/OracleTest/test001.dbf' size 10m autoextend on next 5m maxsize unlimited extent management local;
2.给表空间添加数据文件
SQL> alter tablespace testspace add datafile 'd:/OracleTest/test002.dbf' size 5m autoextend on next 3m maxsize 50m;
3.删除表空间中的数据文件
SQL> alter tablespace testspace drop datafile 'd:/OracleTest/test002.dbf';
4.修改表空间文件的数据文件大小
SQL> alter database datafile 'd:/OracleTest/test001.dbf' resize 10m;
5.修改表空间数据文件的自动增长属性
SQL> alter database datafile 'd:/OracleTest/test001.dbf' autoextend off;
6.删除表空间
(1)不删文件
SQL> drop tablespace testspace;
(2)删除文件
SQL> drop tablespace testspace including contents and datafiles;
7.先查询空闲空间
SQL> select tablespace_name,file_id,block_id,bytes,blocks from dba_free_space;
8.查询数据文件名称、大小和路径的信息
SQL> select tablespace_name,file_id,bytes,file_name from dba_data_files;
表做空间迁移时,使用如下语句:
例1:alter table tb_name move tablespace tbs_name;
索引表空间做迁移,使用如下语句:
例2:alter index index_name rebuild tablespace tbs_name;
对于含有lob字段的表,在建立时,oracle会自动为lob字段建立两个单独的segment,一个用来存放数据,另一个用来存放索引,并且它们都会存储在对应表指定的表空间中,而例1:只能移动非lob字段以外的数据,所以在对含有lob字段的表进行空间迁移,需要使用如下语句:
例3:alter table tb_name move tablespace tbs_name lob (col_lob1,col_lob2) store as(tablesapce tbs_name);
项目实例:
表空间迁移
select 'alter table' ||table_name|| 'move tablespace tbs_name;' from dba_tables where owner='%***%' and table_name like '%***%'
带lob字段
select 'alter table' ||table_name|| 'move lob('||index_name||') store as (tablespace tbs_name);' from dba_indexes where owner='%***%' and index_name like '%***%'
索引表空间
select 'alter index' ||index_name|| 'rebuild tablespace tbs_name;' from dba_indexes where owner='%***%' and table_name like '%***%'
SQL> create tablespace testspace
datafile 'd:/OracleTest/test001.dbf' size 10m autoextend on next 5m maxsize unlimited extent management local;
2.给表空间添加数据文件
SQL> alter tablespace testspace add datafile 'd:/OracleTest/test002.dbf' size 5m autoextend on next 3m maxsize 50m;
3.删除表空间中的数据文件
SQL> alter tablespace testspace drop datafile 'd:/OracleTest/test002.dbf';
4.修改表空间文件的数据文件大小
SQL> alter database datafile 'd:/OracleTest/test001.dbf' resize 10m;
5.修改表空间数据文件的自动增长属性
SQL> alter database datafile 'd:/OracleTest/test001.dbf' autoextend off;
6.删除表空间
(1)不删文件
SQL> drop tablespace testspace;
(2)删除文件
SQL> drop tablespace testspace including contents and datafiles;
7.先查询空闲空间
SQL> select tablespace_name,file_id,block_id,bytes,blocks from dba_free_space;
8.查询数据文件名称、大小和路径的信息
SQL> select tablespace_name,file_id,bytes,file_name from dba_data_files;
表做空间迁移时,使用如下语句:
例1:alter table tb_name move tablespace tbs_name;
索引表空间做迁移,使用如下语句:
例2:alter index index_name rebuild tablespace tbs_name;
对于含有lob字段的表,在建立时,oracle会自动为lob字段建立两个单独的segment,一个用来存放数据,另一个用来存放索引,并且它们都会存储在对应表指定的表空间中,而例1:只能移动非lob字段以外的数据,所以在对含有lob字段的表进行空间迁移,需要使用如下语句:
例3:alter table tb_name move tablespace tbs_name lob (col_lob1,col_lob2) store as(tablesapce tbs_name);
项目实例:
表空间迁移
select 'alter table' ||table_name|| 'move tablespace tbs_name;' from dba_tables where owner='%***%' and table_name like '%***%'
带lob字段
select 'alter table' ||table_name|| 'move lob('||index_name||') store as (tablespace tbs_name);' from dba_indexes where owner='%***%' and index_name like '%***%'
索引表空间
select 'alter index' ||index_name|| 'rebuild tablespace tbs_name;' from dba_indexes where owner='%***%' and table_name like '%***%'
相关文章推荐