Oracle表空间整合例子

上传人:壹****1 文档编号:477415775 上传时间:2022-08-31 格式:DOCX 页数:9 大小:15.15KB
返回 下载 相关 举报
Oracle表空间整合例子_第1页
第1页 / 共9页
Oracle表空间整合例子_第2页
第2页 / 共9页
Oracle表空间整合例子_第3页
第3页 / 共9页
Oracle表空间整合例子_第4页
第4页 / 共9页
Oracle表空间整合例子_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《Oracle表空间整合例子》由会员分享,可在线阅读,更多相关《Oracle表空间整合例子(9页珍藏版)》请在金锄头文库上搜索。

1、数据库表空间整合方案1. 问题描述 目前,某服务系统数据库存在多个表空间,对数据库表的维护造成了一定的 影响。2. 问题解决方案 解决方案:采用脚本来转移数据库表、索引及特殊字段 (lob 字段类型)第一、表做表空间迁移时,首先使用查询语句把表迁移语句拼接起来,然后再执行结 果中的语句,查询语句如下:select table_name,alter table | table_name | move tablespace tablespaceNameA; exewordsfrom all_tableswhere owner二表拥有者表拥有者如:USERAQ己住一定要大写)and tablespa

2、ce_name tablespaceNameA -不属于表空间 tablespaceNameA注释:请保留结果 table_name 列的结果,第三步要用到这些表,并执行 exewords 列中产生的结果语句。以下以 UserA 为例:Select table_name, alter table |table_name| move tablespace tablespaceNameA; exewords from all_tables where owner=USERA and tablespace_name tablespaceNameA;结果语句略,执行 exewords 列中产生的语句。

3、第二、索引做表空间做迁移时,首先使用查询语句把索引迁移语句拼接起来,然 后再执行结果中的语句,查询语句如下:select index_name,alter index | index_name | rebuild tablespace tablespaceNameA; exewordsfrom all_indexeswhere owner二索引拥有者-索引拥有者如:USERA己住一定要大写)and tablespace_name tablespaceNameA-表空间结果略,执行 exewords 列产生的结果。以下以 UserA 为例:select index_name,alter inde

4、x | index_name | rebuild tablespace tablespaceNameA; exewordsfrom all_indexeswhere owner = USERA-数据库用户名and tablespace_name tablespaceNameA-表空间(将要转移过去的表空间)结果略,执行 exewords 列产生的结果。第三,转移lob字段,对于这种字段,在建立含有lob字段的表时,oraCe会自动为 lob字段建立两个单独的segment,一个用来存放lob数据,另一个用来存放lob索引, 并且它们都会存储在对应表指定的表空间中。但是当我们用 alter ta

5、ble tb_name move tablespace tbs_name;对表做表空间之间迁移时只能迁移非lob字段以外的 segment,而如果要在移动表数据同时移动lob相关字段,就必需用如下的含有特 殊参数的语句来完成:alter table tb_name move tablespace tbs_name lob (column_lob1,column_lob2) store as(tablesapce tbs_name);具体步骤如下(以USERA为例):第 (1 )、select rs.exewords from(Select select | alter table | tabl

6、e_name | move tablespace tablespaceNameA lob(| | column_name |) store as(tablespace tablespaceNameA);exewords | from user_tab_columns where table_name= | table_name | and (data_type = BLOB or data_type = CLOB or data_type = NCLOB) union exewordsfrom all_tableswhere owner = USERA- 数据库用户and tablespace

7、_name tablespaceNameA-转移后的表空间名称and table_name =MYTEST) rs-第一个步骤保存的表名unionselect select temp exewords from dual where 1=2 exewords from dual;第(2)、从第(1)步中得到结果,并继续执行结果语句。第(3)、从第(2)步中得到结果,并继续执行结果语句。利用如下语句可以验证转移前和转移后的差别:select*from all_tables where owner=USERAand tablespace_nametablespaceNameAselect*from

8、 all_indexeswhere owner=USERAand tablespace_name tablespaceNameA例子:-=转移 Blob 字段例子 create table MyTest(id number,id2 number,myname varchar2(10),img1 blob,img2 clob)tablespace tablespaceNameBpctfree 10initrans 1maxtrans 255storage(initial 64Kminextents 1maxextents unlimited);alter table MyTestadd cons

9、traint PK_mytest primary key (ID) using indextablespace DEFCpctfree 10initrans 2maxtrans 255storage(initial 64Kminextents 1maxextents unlimited);create index ind_on_mytest_id2 on myTest (id2) tablespace tablespaceNameBpctfree 10initrans 2maxtrans 255storage(initial 64Kminextents 1maxextents unlimite

10、d);create index ind_on_mytest_myname on myTest (myname)tablespace tablespaceNameBpctfree 10initrans 2maxtrans 255storage(initial 64Kminextents 1maxextents unlimited);select*from Mytest;-第一步骤(执行如下语句,查询出需要转移的数据库表,并保留table_name列的结果,最后一步要用)select table_name,alter table | table_name | move tablespace tab

11、lespaceNameA; exewordsfrom all_tableswhere owner = USERA - 表拥有者and tablespace_name tablespaceNameA - 不属于表空间 tablespaceNameA-第二步骤 (执行上面生成的 exewords 列的结果)alter table MYTEST move tablespace tablespaceNameA;-第三步骤(执行如下语句,查出需要转移索引)select index_name,alter index | index_name | rebuild tablespace tablespaceN

12、ameA; exewordsfrom all_indexeswhere owner = USERA- 数据库用户名and tablespace_name tablespaceNameA -表空间(将要转移过去的表空 间)-第四步骤 (执行上面生成的 exewords 列的结果)alter index PK_MYTEST rebuild tablespace tablespaceNameA;alter index IND_ON_MYTEST_ID2 rebuild tablespace tablespaceNameA; alter index IND_ON_MYTEST_MYNAME rebui

13、ld tablespace tablespaceNameA;-第五步骤(执行如下语句,查出大字段,并将其转移)-1 )执行一下语句,拼出查询大字段的语句。select rs.exewords from(Select select | alter table | table_name | move tablespace tablespaceNameA lob(| | column_name |) store as(tablespace tablespaceNameA);exewords | from user_tab_columns where table_name= | table_name

14、| and (data_type = BLOB or data_type = CLOB or data_type = NCLOB) union exewordsfrom all_tableswhere owner = USERA- 数据库用户and tablespace_name tablespaceNameA-转移后的表空间名称and table_name =MYTEST) rs- 第一个步骤保存的表名unionselect select temp exewords from dual where 1=2 exewords from dual;-2 )执行以上语句执行后生成的 exewords 列的结果。-3) 执行以上语句执行后生成的 exewords 列的结果

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 建筑资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号