码迷,mamicode.com
首页 > 其他好文 > 详细

删除LOB数据后, LOB空间不能重用的问题.

时间:2015-04-23 13:48:08      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:lob空间重用


As records are deleted, the LOB data segments are marked as psuedo-deleted and they can only be reused when the ‘readLSN‘ of the table progresses past the LSN of when the deletes were performed(you can think of this as allowing read-stability isolation for any older open read transactions in case the pseudo-deleted LOB data is still needed by it). So, a new insert statement must constantly search the entire LOB space looking for free segments without being able to reuse the pseudo-delete LOB segments it comes by (not until whoever is holding up the readLSN is gone).


窗口1(session 1):

db2 "create table lob01 like sysibm.systables long in userspace1"
rm lob01*
db2 inspect check table name lob01 schema e97q7a results keep lob01.out
db2inspf lob01.out lob01.txt
cat lob01.txt

LOB Object Summary: Total Pages 0 - Used Pages 0
LBA Object Summary: Total Pages 1 - Used Pages 0


插入数据:

db2 "insert into lob01 select * from sysibm.systables"  
db2 "insert into lob01 select * from lob01"
db2 "insert into lob01 select * from lob01"
db2 "insert into lob01 select * from lob01"
db2 "insert into lob01 select * from lob01"
db2 "insert into lob01 select * from lob01"
db2 "select count(1) from lob01"


LOB Object Summary: Total Pages 15168 - Used Pages 15160
LBA Object Summary: Total Pages 16 - Used Pages 16


db2 "delete from (select * from lob01 fetch first 2000 rows only)"
db2 "delete from (select * from lob01 fetch first 2000 rows only)"
db2 "delete from (select * from lob01 fetch first 2000 rows only)"
db2 "delete from (select * from lob01 fetch first 2000 rows only)"
db2 "delete from (select * from lob01 fetch first 2000 rows only)"
db2 "delete from lob01"
db2 "select count(1) from lob01"

LOB Object Summary: Total Pages 15168 - Used Pages 15045
LBA Object Summary: Total Pages 16 - Used Pages 16


db2 "insert into lob01 select * from sysibm.systables"  
db2 "insert into lob01 select * from lob01"
db2 "insert into lob01 select * from lob01"
db2 "insert into lob01 select * from lob01"
db2 "insert into lob01 select * from lob01"
db2 "insert into lob01 select * from lob01"
db2 "select count(1) from lob01"

LOB Object Summary: Total Pages 15168 - Used Pages 15160
LBA Object Summary: Total Pages 16 - Used Pages 16

Used Pages没涨, delete的lob空间这里重用了.



窗口2(session 2):

readlsn(读操作hold住lob01表当前的lsn)

db2 +c "declare c1 cursor for select * from lob01"
db2 +c "open c1"
db2 +c "fetch from c1"



窗口1(session 1):

观察锁的情况.

db2pd -d sample -locks

Locks:
Address            TranHdl    Lockname                   Type       Mode Sts Owner      Dur HoldCount  Att        ReleaseFlg rrIID
0x0700000040FF9980 12         00000001000000010001652056 Internal V ..S  G   12         1   0          0x00000000 0x40000000 0     
0x0700000040FF9B80 12         4141414141424263C34A726E41 Internal P ..S  G   12         1   0          0x00000000 0x40000000 0     
0x0700000040FF9A80 12         00030021000000000000000054 Table      .IS  G   12         1   0          0x00003000 0x40000000 0     

lob01表上了一个IS锁.

继续删除数据:

delete操作会更新lowTranLSN.

db2 "delete from (select * from lob01 fetch first 2000 rows only)"
db2 "delete from (select * from lob01 fetch first 2000 rows only)"
db2 "delete from (select * from lob01 fetch first 2000 rows only)"
db2 "delete from (select * from lob01 fetch first 2000 rows only)"
db2 "delete from (select * from lob01 fetch first 2000 rows only)"
db2 "delete from lob01"
db2 "select count(1) from lob01"

插入数据:


db2 "insert into lob01 select * from sysibm.systables"  
db2 "insert into lob01 select * from lob01"
db2 "insert into lob01 select * from lob01"
db2 "insert into lob01 select * from lob01"
db2 "insert into lob01 select * from lob01"
db2 "insert into lob01 select * from lob01"
db2 "select count(1) from lob01"


LOB Object Summary: Total Pages 30528 - Used Pages 30512
LBA Object Summary: Total Pages 31 - Used Pages 31

窗口2 hold住的readLSN< delete操作的LSN, readLSN之后的空间都不会被重用.


db2 "delete from (select * from lob01 fetch first 2000 rows only)"
db2 "delete from (select * from lob01 fetch first 2000 rows only)"
db2 "delete from (select * from lob01 fetch first 2000 rows only)"
db2 "delete from (select * from lob01 fetch first 2000 rows only)"
db2 "delete from (select * from lob01 fetch first 2000 rows only)"
db2 "delete from lob01"
db2 "select count(1) from lob01"

db2 "insert into lob01 select * from sysibm.systables"  
db2 "insert into lob01 select * from lob01"
db2 "insert into lob01 select * from lob01"
db2 "insert into lob01 select * from lob01"
db2 "insert into lob01 select * from lob01"
db2 "insert into lob01 select * from lob01"
db2 "select count(1) from lob01"

LOB Object Summary: Total Pages 45888 - Used Pages 45864
LBA Object Summary: Total Pages 46 - Used Pages 46



窗口3(Session 3):

在readLSN未释放的情况下, 对lob01表做reorg操作. 在U锁convert to Z锁的时候会发生锁等待, 因为z锁和IS锁冲突, 锁转换不受locktimeout参数控制(working as designed, 另外一个话题了), 导致reorg会hang住.

Locks being waited on :
AppHandl [nod-index] TranHdl    Lockname                   Type       Mode Conv Sts CoorEDU    AppName  AuthID   AppID                           
28       [000-00028] 12         00030021000000000000000054 Table      .IS       G   7713       db2bp    E97Q7A   *LOCAL.e97q7a.150423030505       
7        [000-00007] 2          00030021000000000000000054 Table      ..U  ..Z  C   2572       db2bp    E97Q7A   *LOCAL.e97q7a.150423025731       

删除LOB数据后, LOB空间不能重用的问题.

标签:lob空间重用

原文地址:http://masaly.blog.51cto.com/9302075/1637504

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!