DB2 timeouts, deadlocks, and claim/drain

When two programs want incompatible locks, someone waits. If the wait is a cycle, IRLM calls it a deadlock and picks a victim. If the wait simply lasts too long, it is a timeout. Utilities do not use those row locks to empty a partition; they drain claims. This page ties IS/IX/SIX, timeout detection, claim classes, and data-sharing contention together for DB2 for z/OS.

Locking · operations
Progress0 of 0 lessons

IRLM in brief

The Internal Resource Lock Manager serializes Db2 transaction locks (and drain locks). Db2 asks IRLM for S, U, X, IS, IX, SIX, and related modes. If the lock is free, IRLM grants it. If not, the thread is suspended. IRLM also runs a timer loop:

Timeout and deadlock controls
ControlMeaning
IRLMRWTDefault lock timeout seconds (installation; often 30)
DEADLOK (START irlmproc)How often IRLM hunts deadlocks and overdue timeouts (often 1 second, can be 100 ms)
CURRENT LOCK TIMEOUTSession override: null = IRLMRWT, 0 = NOWAIT, -1 = WAIT forever, 1–32767 seconds
NUMLKUS / NUMLKTSLock ceilings per user / per table space (escalation vs -904)

IS, IX, and SIX are the parent intent locks described on the lock-types page. They show up in timeout traces because a drain or LOCK TABLE that needs a gross S/X will wait on those intent locks just as a row X waits on a row S.

Timeouts and timeout detection

A timeout is “this request waited longer than allowed.” IRLMRWT (RESOURCE TIMEOUT on DSNTIPI) is the subsystem default, commonly 30 seconds. IRLM notices overdue waiters on the same interval it uses for deadlock detection (DEADLOK on the IRLM start procedure).

SET CURRENT LOCK TIMEOUT overrides the wait for this session (APPLCOMPAT V13R1M500 and later for the full register behavior):

sql
1
2
3
4
SET CURRENT LOCK TIMEOUT = 5; -- seconds SET CURRENT LOCK TIMEOUT = 0; -- NOT WAIT: fail immediately SET CURRENT LOCK TIMEOUT = WAIT; -- or -1: do not time out VALUES CURRENT LOCK TIMEOUT;
  • WAIT / -1 — no timeout (can stall a thread forever; use with care)
  • NOT WAIT / 0 — if the lock is not available now, error immediately; no DSNT376I wait message, no IFCID 196 for that wait
  • Integer 1–32767 — seconds to wait
  • Null / default — IRLMRWT

CURRENT LOCK TIMEOUT also covers many claim and drain waits, not only row locks. It does not apply to P-locks or some plan/package allocation locks.

Typical timeout story: program 2 wants a lock program 1 holds and will not commit for minutes. Program 2 waits, then Db2 returns an error. Fix the holder (commit more often, shorter UR, avoid lock escalation) rather than only raising IRLMRWT to 300 seconds.

Deadlocks and deadlock detection

A deadlock is a cycle. Program 1 holds page A and wants page B; program 2 holds B and wants A. Neither timeout clock needs to expire: on the DEADLOK interval IRLM finds the cycle and fails one request so the other can run.

The victim sees SQLCODE -911 or -913 (SQLSTATE 40001 is the usual deadlock/timeout state). -911 rolls back the whole unit of work to the last commit. -913 rolls back the statement and leaves the rest of the UR for the program to COMMIT or ROLLBACK. Know which one your bind/environment produces before you write retry logic.

SQLCODEs you will handle
SQLCODETypical meaning
-911Deadlock or timeout; unit of work rolled back
-913Deadlock or timeout; statement rolled back, UR may continue
-904Resource unavailable (lock, drain, max locks, …)

Prevention: lock the same objects in the same order, prefer row locks on hot pages, keep URs short, avoid RR unless you need it, and do not mix LOCK TABLE with random row updates. Db2 13 adds DEADLOCK_RESOLUTION_PRIORITY so a chosen process is less likely to be the victim — useful for scheduled DDL, not a license to ignore access order.

Isolation reminder: RR, RS, UR, CS

Isolation changes how often you wait:

  • UR — almost no data locks; you rarely timeout on row S locks (you can still wait on other resources)
  • CS — short S locks; still waits on X held by an updater
  • RS — qualifying rows locked until commit: more waiters
  • RR — accessed rows locked until commit: the timeout magnet of the four

Currently committed and SKIP LOCKED DATA (CS/RS) are ways to not wait on some insert/delete or locked rows. They trade completeness for progress.

Claims and claim classes

A claim is not a row lock. It is a flag that this unit of work is using a page set or partition. Claims are taken on first access and released at the next commit — except WITH HOLD cursors and utility claimers. They exist so a REORG can wait for “everyone out” without hunting every row lock.

Claim classes
ClassWho takes itDrain implication
WriteINSERT, UPDATE, DELETEDRAIN WRITERS stops changers; readers may continue
Repeatable readReads under RR isolationNeeded when the drainer must block RR readers
Cursor stability readReads under RS, CS, or URDRAIN ALL includes this class plus write and RR

DISPLAY DATABASE(…) CLAIMERS shows who is holding claims when a utility will not start.

Drains and drain locks

A drain takes over an object: acquire drain locks for the classes you need, refuse new claims of those classes, wait until existing claims of those classes are gone, then run. Applications may still hold transaction locks on rows, but they cannot make a new claim until the drainer finishes.

  • CHECK INDEX — often drains writers only
  • RECOVER — drains all claim classes
  • REORG — DRAIN WRITERS or DRAIN ALL
  • Some ALTER/CREATE/DROP and STOP DATABASE — drain as needed

Drain locks are real IRLM locks in write, repeatable-read, and cursor-stability-read classes. If applications never commit, the drain waits until timeout (utility RETRY/TIMEOUT options, IRLMRWT, or CURRENT LOCK TIMEOUT). WITH HOLD cursors are a classic reason a “I committed!” batch still blocks REORG: the claim survived the commit.

Partition independence: drain part 3, leave part 4’s claimers running. That only works when the table space is partitioned and the utility states the part.

Global contention and false contention

In data sharing, a lock may be granted locally and still wait in the coupling facility.Global contention is that real cross-member wait (XES contention plus IRLM contention). Tune commit rate, lock size, and GBP so members are not fighting over the same hot page.

False contention is a hash collision in the lock structure: two different resources map to one table entry. The workload is not actually conflicting; the structure is too small or poorly proportioned. Enlarge the lock structure / lock table. Do not “fix” false contention by making every program UR.

Practical response

  • Log SQLCODE, SQLSTATE, and whether the UR was lost (-911 vs -913)
  • Retry -913 on the statement; restart -911 from last commit
  • For utilities: DISPLAY CLAIMERS, find held cursors, add COMMITs
  • For data sharing: separate false from real contention before buying CF CPU

Explain It Like I'm Five

A timeout is waiting for the bathroom until a timer rings and you give up. A deadlock is two people each standing in a doorway the other needs — a teacher picks one person to step back. A claim is a sticky note on the classroom door saying “someone is still inside.” A drain is the janitor putting up “no new sticky notes” and waiting until the last kid leaves before mopping. False contention is two different classrooms sharing one coat-hook number by mistake and arguing about a coat that is not even theirs.

Exercises

  1. Draw a two-program deadlock on EMP page 1 and DEPT page 2. Who waits for whom?
  2. Your batch gets SQLCODE -911 after 30 seconds. Name two application changes that help more than doubling IRLMRWT.
  3. SET CURRENT LOCK TIMEOUT = 0. What does the next blocked UPDATE do?
  4. Why can REORG DRAIN ALL wait even after the application COMMITs, if a WITH HOLD cursor is open?
  5. Explain false contention in one sentence and one tuning action.

Quiz

Test Your Knowledge

1. What is IRLM’s role in a timeout?

  • It writes SMF type 30 only
  • It waits up to the lock timeout interval (IRLMRWT, default 30 seconds, or CURRENT LOCK TIMEOUT), then returns the request to Db2 as unsatisfiable
  • It always chooses a deadlock victim first
  • It REORGs the table space

2. SQLCODE -911 versus -913 typically means:

  • -911 is a warning
  • -911 rolls back the unit of work; -913 rolls back the failing statement and lets the program decide
  • They are identical always
  • -913 means successful commit

3. A CS claim is taken when:

  • Only utilities run
  • The process reads with RS, CS, or UR isolation (cursor-stability read class)
  • Only LOCK TABLE IN EXCLUSIVE MODE
  • Only at IPL

4. What does a drain do?

  • Deletes the table
  • Stops new claims of the drained classes and waits for existing claims to drop (usually at commit) so a utility or command can take over the object
  • Always waits forever
  • Is the same as an X row lock

5. False contention in data sharing is:

  • Two users updating the same row
  • Different resources hashing to the same coupling-facility lock-table entry, so they wait even though the rows are different
  • A claim class name
  • SQLCODE 0