请教老何等DB2高手一个问题

sable93

资深人士
VIP
注册
2003-11-11
消息
1,222
荣誉分数
92
声望点数
208
DB2里open 一个cursor,FETCH a table时会不会lock这个table?

如果一个job 时不时开一个cursor,FETCH 一个table的数行data,然后关闭这个cursor。
另一个job会对同一个table UPDATE。这个job会得到-911 error。是因为lock timeout吗?
 
I am a Java guy, but let me try.
It looks like a lock timeout.
It all depends on your transaction isolation level and table locking level. The transaction isolation level by default is CS and locking level on mainframe is page. And also your query size. Of course, it also depends on
whether you are querying and updating the same rows.
When you open cursor, it will hold locks and when the size is big, the lock may escalate into a page lock or even table lock. This will prevent update to proceed. And vice versa.
Page level locking is bad when your table has small size rows. In this case, hundreds of rows may share the same page lock.
To resolve this issue.
1. Try to shorten the transaction
2. Try to use row level locking
3. See you can use dirty read
4. See your query is hitting the index and not doing a full table scan
 
咱没玩儿过这么高深的东西,跟着瞎搅和搅和,希望大家别介意。

http://pic.dhe.ibm.com/infocenter/d...pic=/com.ibm.db2z9.doc.codes/src/tpc/n911.htm
SQLERRD(3) also contains the reason-code which indicates whether a deadlock or timeout occurred. The most common reason codes are:
•00C90088 - deadlock
•00C9008E - timeout
--------------------------------------------------------------------
http://publib.boulder.ibm.com/infoc...c=/com.ibm.db2.udb.admin.doc/doc/r0000954.htm
•For an updatable cursor, a lock is obtained on a row when it is fetched.
-------------------------------------------------------------------
http://publib.boulder.ibm.com/infoc...c=/com.ibm.db2.udb.admin.doc/doc/r0000954.htm
SET CURRENT LOCK TIMEOUT statement
 
It looks like a lock timeout.
。。。
When you open cursor, it will hold locks and when the size is big, the lock may escalate into a page lock or even table lock. This will prevent update to proceed. And vice versa.
。。。
Although BINDING ISOLATION is CS, 不过你已经回答了我的问题。
第二个job是night running job, 只是个3分钟的job。原先设计时没用transaction,因为不应该有第二个人touch our DB。
最近别的部门来个job1,所以我们就有问题了。
多谢楼上两位and老何。
 
DB2里open 一个cursor,FETCH a table时会不会lock这个table?

如果一个job 时不时开一个cursor,FETCH 一个table的数行data,然后关闭这个cursor。
另一个job会对同一个table UPDATE。这个job会得到-911 error。是因为lock timeout吗?


你的判断是对的。Error Code -911 (Deadlock or timeout)是常出现的问题。

你可以通过 “db2 update db cfg" 来设置系统的 DLCHKTIME,LOCKLIST,MAXLOCKS 和 LOCKTIMEOUT 等,可通过 “diagpath” 查看 Lock timeout report files。如果在 DECLARE CURSOR 中用了 WITH HOLD 要注意用 COMMIT,在 CLOSE 中最好用 WITH RELEASE。

有问题,可以去 DB2 论坛查询,那里有很多的专家和兴趣爱好者。
 
DB2里open 一个cursor,FETCH a table时会不会lock这个table?

如果一个job 时不时开一个cursor,FETCH 一个table的数行data,然后关闭这个cursor。
另一个job会对同一个table UPDATE。这个job会得到-911 error。是因为lock timeout吗?

你居然说我们老何是DB?哈,欺负老何不懂狼京话哈 :tx:
 
后退
顶部