查询挂甲骨文 10g更新:更新日期: (15.03.2011)更新: (16.03.2011)
我的软件有这个奇怪的问题。正在生产5年,我们没有这样的问题...
问题:
我们有一个spring作业(调度程序),它通过休眠进行查询,检索对象并修改它们。
好吧,这工作了几年,但一个月前,查询每天挂起5-10次(查询每10分钟调用一次)。当它挂起时,我们必须重新启动该服务。
下面的代码执行查询:
@SuppressWarnings("unchecked")
public List<Delivery> findScheduledForDelivery(final String inType, final int max, final String benefitType ) {
//getHibernateTemplate().clear();
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session) throws SQLException {
Criteria criteria = session.createCriteria(Delivery.class);
criteria.createAlias("reward","r");
criteria.createAlias("r.customer","c");
criteria.createAlias("c.inNe","i");
criteria.createAlias("r.promotion","p");
criteria.createAlias("benefit","b");
String sqlCustAlias = StringHelper.generateAlias("c", 2);
criteria.add(Expression.disjunction()
.add(Expression.eq("inStatus", INStatus.InterfaceFailure))
.add(Expression.eq("inStatus",INStatus.Initial)));
criteria.add(Expression.le("deliverAt", new Date()));
String dateString = "2000/01/01";
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date startDate = new Date();
try {
startDate = dateFormat.parse(dateString);
criteria.add(Expression.ge("deliverAt", startDate));
}
catch(ParseException e) {
e.printStackTrace();
}
String sqlEqual = "decode(delivered,null,0,1) = 0";
criteria.add(Expression.sql(sqlEqual));
sqlEqual = "decode(" + sqlCustAlias + ".deleteDate,null,1,0) = 1";
criteria.add(Expression.sql(sqlEqual));
if(inType != null ) {
for(INType i : INType.values())
if(i.toString().equals(inType)) {
criteria.add(Expression.eq("i.inType", i));
break;
}
}
criteria.add(Expression.eq("p.active", true));
if(benefitType != null) {
if(benefitType.equals("FREECREDIT"))
criteria.add(Expression.disjunction()
.add(Expression.eq("b.type", BenefitType.FREE_CREDIT))
.add(Expression.eq("b.type", BenefitType.FREE_CREDIT_FTAM)));
else if(benefitType.equals("NONFREECREDIT")) {
criteria.add(Expression.conjunction()
.add(Expression.ne("b.type", BenefitType.FREE_CREDIT))
.add(Expression.ne("b.type", BenefitType.OTHER))
.add(Expression.ne("b.type", BenefitType.VOUCHER)));
criteria.add(Expression.isNull("b.md3Profile"));
}
if(max != 0)
criteria.setMaxResults(max);
}
criteria.addOrder( Order.desc("p.priority") );
criteria.addOrder( Order.asc("deliverAt") );
return criteria.list(); <===== hangs here
}
});
}
数据源被定义为这样的(我知道这不应该在生产中,但这是它工作的唯一方式 - 我试图使用oracle连接池,但后来查询更频繁地挂起..):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="connectionProperties">
<props>
<prop key="tcp.nodelay">yes</prop>
<prop key="delayRowPrefetch">20</prop>
<prop key="defaultBatchSize">5</prop>
</props>
</property>
</bean>
</beans>
使用的软件:
- 弹簧 1.2.7
- 休眠 3.0.5
- 预言机 10.2.0.1 (RAC)
- oracle jdbc 10.1.0.2
- 红帽 3 EL
- Java 1.5_06
到目前为止,我尝试过什么:
- 使用 oracle 连接池作为数据源 ->失败且连接挂起
- 使用oracle jdbc 10.2.0.5 ->我以为我已经解决了它...几个小时后,它又挂了:(
据我所知,预言机上没有数据库锁...
可能是什么问题?
更新:
在甲骨文 EM 中:
ADDM 结果:发现 SQL 语句占用了大量数据库时间。查询会消耗大量数据库时间。影响 81%.用户 I/O 等待 97%。
- 发现了负责大量用户 I/O 等待的单个 SQL 语句。
- 发现了负责大量用户 I/O 等待的单个数据库段。
- I/O 子系统的吞吐量明显低于预期。
更新日期: (15.03.2011)
目前,该服务可工作近48小时而不会挂起。
我怀疑这会解决问题,但我对代码做了一些更改:
删除了查询中的 和 函数,并用语句替换了它们。
已对交付的字段编制索引,但无法在函数中使用索引。decode(delivered,null,0,1) = 0
decode(" + sqlCustAlias + ".deleteDate,null,1,0) = 1
is null
decode
你认为这只是巧合吗?
更新: (16.03.2011)
alert.log现在显示许多条目,如下所示:
ORA-01555 caused by SQL statement below (SQL ID: affkpm4j7azc4, Query Duration=232624 sec, SCN: 0x0003.dca70559):
Tue Mar 15 17:43:06 2011
select * from ( select this_.id as id5_, this_.deliverAt as deliverAt68_5_, this_.delivered as delivered68_5_, this_.inDelivery as inDelivery68_5_, this_.lastDeliveryTry as lastDeli5_68_5_, this_.tries as tries68_5_, this_.sentAt as sentAt68_5_, this_.sent as sent68_5_, this_.retry as retry68_5_, this_.inStatus as inStatus68_5_, this_.errorMessage as errorMe11_68_5_, this_.inCvsDelivery as inCvsDe12_68_5_, this_.cvsDelivered as cvsDeli13_68_5_, this_.cvsLastDeliveryTry as cvsLast14_68_5_, this_.cvsTries as cvsTries68_5_, this_.collectedPoints as collect16_68_5_, this_.smsMessage as smsMessage68_5_, this_.inOldStatus as inOldSt18_68_5_, this_.replacedDate as replace19_68_5_, this_.oldMsisdn as oldMsisdn68_5_, this_.deletedDate as deleted21_68_5_, this_.addManualDate as addManu22_68_5_, this_.stornoPromiseDate as stornoP23_68_5_, this_.stornoINDate as stornoI24_68_5_, this_.activationCode as activat25_68_5_, this_.activationExpirationDate as activat26_68_5_, this_.rewardId as rewardId68_5_, this_.benefitId as b
它似乎来自3天前的会议..232624秒!