过期数据的定期清理机制来提高系统稳定性

最近应用系统响应速度偶尔出现缓慢,今天应用日志报了如下错误:

2011-10-20 11:55:18,757 ERROR - 2011-10-20 11:55:18 org.apache.tomcat.util.threads.ThreadPool logFull

????: All threads (75) are currently busy, waiting. Increase maxThreads (75) or check the servlet status

从该日志看系统慢的时候做了重复操作,导致等待的线程越来越多,最终达到最大线程数。

当系统性能出现问题时,我们很多时候考虑购买高档设备来解决日益猛增的业务数据和需求。但是对过期数据(所谓垃圾数据)不建立合理的归档清理机制,恐怕再好的硬件也是无法保证应用的稳定性。

[@more@]

如下是清理归档过程相关的SQL脚本的简单模板,供大家参考:

1、确定系统中数据量猛增而影响性能的大表

2、为此建立归档机制,即清空某某日之前数据

定义了以上两点后,就需要Oracle的相关命令来实现清理归档。如下为案例模板:

--清理归档之前的备份

expdp system/system directory= EXPDIR dumpfile=test_dmpback.dmp logfile=test_dmpback.log schemas=test

exp system/system owner=test file=/backup/test.dmp log=/backup/test.log direct=y statistics=none buffer=20480000 recordlength=65534

--根据大表的表间关系找到需要清理归档的时间所对应的表的主键ID

select * from test1 d where d.test_id = 1268

select * from test2 c where c.test2 = 12686; -- test2_Id > 47088

--如果没有提前准备好的Directory则新建一个:

$sqlplus / as sysdba

create directory so_dumpdir as '/backup/dmp';

grant read,write on directory DUMPDIR to system;

--对需要清理的表进行清理(只导出今后需要用到的)

expdp system/system@ora DIRECTORY=DUMPDIR DUMPFILE=test1.dmp tables=(test.test1) content=all query="where test_id>1268" LOGFILE=exptest1_1.log

expdp system/system@xjboss1 DIRECTORY=DUMPDIR DUMPFILE=test2.dmp tables=(test.test2) content=all query="where record_id>47088" LOGFILE=test2_2.log

--为了避免导入过程中产生表锁冲突而无法导入,需要将应用停止

--开始导入刚导出过的有用的数据

impdp system/system@ora DIRECTORY=DUMPDIR DUMPFILE=test1.dmp TABLE_EXISTS_ACTION=truncate REMAP_SCHEMA=test:test logfile=imptest.log;

impdp system/system@ora DIRECTORY=DUMPDIR DUMPFILE=test2.dmp TABLE_EXISTS_ACTION=truncate REMAP_SCHEMA=test:test logfile=imptest_2.log;

在导入过程中可能会报ORA-39153错误:

ORA-39153: Table "test"."test1" exists and has been truncated. Data will be loaded but all dependent metadata will be skipped due to table_exists_action of truncate

--应用的启用

--导入后的检查

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/18841027/viewspace-1055845/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/18841027/viewspace-1055845/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值