2. 2
• 行ロック取得時(SELECT … FOR UPDATEなど)に、既に行ロックを取得しているトランザクションの完了(=
行ロックの開放)を待つときに出るログ
• トランザクションIDへのロックとは?
• それがなぜ行ロックに関係しているのか?
• 一方、LOG: process 58992 still waiting for AccessExclusiveLock on tuple (0,1) of relation 16384 of database
13021 after 1000.256 ms というログも出る
• FOR UPDATEのケースのみ解説します
LOG: process 61648 still waiting for ShareLock on transaction 710 after 1000.269 ms
DETAIL: Process holding the lock: 59735. Wait queue: 61648.
CONTEXT: while locking tuple (0,1) in relation "test"
6. 6
トランザクションIDへのロック待ちとは?
LOG: process 61648 still waiting for ShareLock on transaction 710 after 1000.269 ms
• あるトランザクションIDへの共有ロックが取得できた=そのトランザクションが完了し
た
• 行ロックはこれを利用している
• つまりこのログは「あるトランザクション(xid=710)が先に行ロックを取得していて、プ
ロセス(pid=61648)はそのトランザクションが行ロックを開放するのを待っている」と理
解できる
19. 19
BE-1
BE-2
Lmgr
Tuple
1. Acquire the XID lock in EXL
2. Acquire the tuple lock in AEL
3. Check the blocker
4. Wait for the blocker to finish
5. Write own XID to XMAX field
6. Release the tuple lock
21. 21
BE-1
BE-2
XID=100
XID=100
EXL (BE-1)
Lmgr
Tuple
1. Acquire the XID lock in EXL
2. Acquire the tuple lock in AEL
3. Check the blocker
4. Wait for the blocker to finish
5. Write own XID to XMAX field
6. Release the tuple lock
tuple=(0,1)
AEL (BE-1)
22. 22
BE-1
BE-2
XID=100
XID=100
EXL (BE-1)
Lmgr
Tuple
1. Acquire the XID lock in EXL
2. Acquire the tuple lock in AEL
3. Check the blocker
4. Wait for the blocker to finish
5. Write own XID to XMAX field
6. Release the tuple lock
tuple=(0,1)
AEL (BE-1)
26. 26
BE-1
BE-2
100
XID=100
XID=100
EXL (BE-1)
Lmgr
Tuple
1. Acquire the XID lock in EXL
2. Acquire the tuple lock in AEL
3. Check the blocker
4. Wait for the blocker to finish
5. Write own XID to XMAX field
6. Release the tuple lock
XID=200
XID=200
EXL (BE-2)
tuple=(0,1)
AEL (BE-2)
27. 27
BE-1
BE-2
100
XID=100
XID=100
EXL (BE-1)
Lmgr
Tuple
1. Acquire the XID lock in EXL
2. Acquire the tuple lock in AEL
3. Check the blocker
4. Wait for the blocker to finish
5. Write own XID to XMAX field
6. Release the tuple lock
XID=200
XID=200
EXL (BE-2)
tuple=(0,1)
AEL (BE-2)
SHL (BE-2)
28. 28
BE-1
BE-2
100
XID=100
XID=100
EXL (BE-1)
Lmgr
Tuple
1. Acquire the XID lock in EXL
2. Acquire the tuple lock in AEL
3. Check the blocker
4. Wait for the blocker to finish
5. Write own XID to XMAX field
6. Release the tuple lock
XID=200
XID=200
EXL (BE-2)
tuple=(0,1)
AEL (BE-2)
SHL (BE-2)
LOG: process 61648 still
waiting for ShareLock on
transaction 710 after
1000.269 ms
29. 29
BE-1
BE-2
100
XID=100
XID=100
EXL (BE-1)
Lmgr
Tuple
1. Acquire the XID lock in EXL
2. Acquire the tuple lock in AEL
3. Check the blocker
4. Wait for the blocker to finish
5. Write own XID to XMAX field
6. Release the tuple lock
XID=200
XID=200
EXL (BE-2)
tuple=(0,1)
AEL (BE-2)
SHL (BE-2)
BE-3
XID=300
1. Acquire the XID lock in EXL
2. Acquire the tuple lock in AEL
3. Check the blocker
4. Wait for the blocker to finish
5. Write own XID to XMAX field
6. Release the tuple lock
XID=300
EXL (BE-3)
30. 30
BE-1
BE-2
100
XID=100
XID=100
EXL (BE-1)
Lmgr
Tuple
1. Acquire the XID lock in EXL
2. Acquire the tuple lock in AEL
3. Check the blocker
4. Wait for the blocker to finish
5. Write own XID to XMAX field
6. Release the tuple lock
XID=200
XID=200
EXL (BE-2)
SHL (BE-2)
BE-3
XID=300
1. Acquire the XID lock in EXL
2. Acquire the tuple lock in AEL
3. Check the blocker
4. Wait for the blocker to finish
5. Write own XID to XMAX field
6. Release the tuple lock
AEL (BE-3)
tuple=(0,1)
AEL (BE-2)
XID=300
EXL (BE-3)
31. 31
BE-1
BE-2
100
XID=100 Lmgr
Tuple
1. Acquire the XID lock in EXL
2. Acquire the tuple lock in AEL
3. Check the blocker
4. Wait for the blocker to finish
5. Write own XID to XMAX field
6. Release the tuple lock
XID=200 BE-3
XID=300
1. Acquire the XID lock in EXL
2. Acquire the tuple lock in AEL
3. Check the blocker
4. Wait for the blocker to finish
5. Write own XID to XMAX field
6. Release the tuple lock
XID=100
EXL (BE-1)
XID=200
EXL (BE-2)
SHL (BE-2) AEL (BE-3)
tuple=(0,1)
AEL (BE-2)
XID=300
EXL (BE-3)
LOG: process 58992 still
waiting for
AccessExclusiveLock on
tuple (0,1) of relation