waterye

使用SQL*Plus copy command复制数据

当生产库的历史数据很大时会导致信息系统很慢, 将历史数据转移到历史库, 也许这不算好的解决方法, 但对生产库的性能将有所提高

1. 建立历史数据库(historydb)
2. 使用SQL*Plus copy command复制数据到历史数据库 (参考: http://www.itpub.net/225749.html)  
 基本表用append方式:  copy from user/pwd@db to user/pwd@historydb replace product using select * from product;
 业务表用replace方式: copy from user/pwd@db to user/pwd@historydb append sale_order using select * from sale_order;
3. 从生产库中删除业务数据


优点: 速度较快
缺点: 业务数据如果进行重复append时将出错(primary key), 生产库和历史库的表结构必须相同

note: 可以在历史库上执行Copy Command,也可以在生产库上执行Copy Command,但不要在第三台机器上执行Copy Command,原因很简单,Copy Command的执行机制是通过SQL*Net来转移数据,如果是在第三台机器上执行的话,相当于数据绕了一大段弯路才进入历史库,自然会影响效率。


sqlplus /nolog @move.sql

move.sql

conn user/pwd@db
set arraysize 5000 -- 加快速度
copy from user/pwd@db to user/pwd@historydb replace product using select * from product; 
-- 
copy from user/pwd@db to user/pwd@historydb append sale_order using select * from sale_order s where s.order_date >= add_months(sysdate, -5and s.order_date < add_months(sysdate, -3);
delete from sale_order s 
 
where s.order_date >= add_months(sysdate, -5)
   
and s.order_date < add_months(sysdate, -3);
commit;
exit

posted on 2005-12-14 10:30 waterye 阅读(645) 评论(0)  编辑  收藏 所属分类: oracle


只有注册用户登录后才能发表评论。


网站导航: