CANCEL commands in DB2 for z/OS

When a thread will not commit, holds a claim that blocks STOP DATABASE, or sits in DDF until morning, operators reach for -CANCEL THREAD. This is the Db2 CANCEL command family on z/OS: one command with several options, plus the network-level follow-ups IBM documents when the thread is not inside DB2 at all. It is not the SQL ROLLBACK statement, and it is not z/OS CANCEL of a job—though you may need both in that order.

Db2 operator commands
Progress0 of 0 lessons

What -CANCEL THREAD does

-CANCEL THREAD (abbreviation -CAN THD) cancels processing for specific local or distributed threads. Db2 schedules the thread to terminate. Threads that are not currently in Db2 terminate when they next make a Db2 request—or immediately from Db2’s point of view if they have already left. Data sharing scope is member: you cancel on the member that owns the thread.

Issue it from a z/OS console, TSO DSN session, DB2I COMMANDS, IMS or CICS, or IFI. Authorization without LOCAL: SYSOPR, SYSCTRL, or SYSADM. With LOCAL, no Db2 authorization is required (IFI, same address space, RRSAF).

Finding the token or LUWID

Before you cancel, DISPLAY THREAD (often DETAIL, and LOCATION for DDF). Each thread has a token: a one- to six-digit decimal number, unique on that subsystem but not necessarily unique across a data sharing group. The token also appears after the equal sign in messages that display an LUWID. IFI READS for IFCID 147 or 148 can return the same token.

A logical unit of work identifier (LUWID) is:

  • A one- to eight-character network ID, a period, and a one- to eight-character LU name
  • An LUW instance number: 12 hexadecimal characters
  • Optionally a commit sequence number (four hex digits) in some displays

If you type three fields separated by periods, Db2 treats the value as an LUWID. Two or more distributed threads can share an LUWID—for example package-based continuous block fetch opens a secondary connection per statement, and the server DBATs share the requester LUWID. Cancelling that LUWID cancels all of them. If the thread is part of a global transaction, the command runs against all threads in that global transaction.

Options

CANCEL THREAD options
OptionMeaning
THREAD(token)Cancel the thread with this 1–6 digit token. Token 0 cannot be canceled.
DDF THREAD(luwid|token)Cancel distributed threads. An LUWID is network.luname.12-hex-instance. All threads with that LUWID are canceled (including package-based continuous block fetch secondaries).
DUMPSVC dump if the thread is active in Db2 at cancel time.
LOCALIFI-only soft cancel in the same RRSAF address space.
NOBACKOUTDo not back out data during rollback. Objects can be left inconsistent.
FORCESecond attempt to purge a remote connection hung in the network.

DUMP

Requests a dump when CANCEL THREAD is issued and the thread is active in Db2. If the thread left Db2 to run application code, Db2 performs a hard cancel and does not provide that dump.

LOCAL

Search the allied agent’s home address space for a matching token and perform a soft cancel. Valid only for CANCEL THREAD through IFI. The IFI application must run in the same address space as the thread, and the thread must use the RRS attachment facility.

NOBACKOUT

Db2 does not attempt to back out data during transaction rollback. That can leave objects inconsistent. Do not use it unless you already plan to repair the data. If back out later fails, objects are marked REFRESH PENDING (REFP) and either RECOVER PENDING (RECP) or REBUILD PENDING (RBDP or PSRBD). Resolve REFP with the RECOVER utility to a prior point in time or LOAD REPLACE. Message DSNI032I indicates a failed request; you may retry.

FORCE

Attempts to purge the thread of a remote connection from the Db2 server. FORCE is accepted only after a CANCEL THREAD without FORCE. IBM’s attention statement: FORCE can affect the subsystem; use it for threads that hurt Db2 and will not cancel otherwise. FORCE can help a thread hung in the network. It cannot help a thread hung while Db2 is processing it.

text
1
2
3
4
5
-DISPLAY THREAD(*) -CANCEL THREAD(123) DUMP -CANCEL DDF THREAD(DB2NET.LUND0.C4B23F1F4D06) -CANCEL THREAD(123) -CANCEL THREAD(123) FORCE

IBM’s recommended order

If you need to cancel or purge jobs that have active Db2 threads, issue CANCEL THREAD first. Db2 then abnormally terminates the thread at predictable locations, which is an orderly termination from the database’s point of view. Purging the job first can leave Db2 holding resources or create a messier abend.

  • Local batch/TSO: CANCEL THREAD, wait, DISPLAY THREAD. If the thread remains because it is in application code, z/OS CANCEL the job.
  • CICS/IMS: cancel the transaction the way that subsystem expects after (or in coordination with) CANCEL THREAD, so the transaction manager and Db2 agree.
  • Distributed: cancel can leave the thread indoubt. DSNL450I means the DDF thread converted from active to indoubt. Resources stay until automatic indoubt resolution with the coordinator or RECOVER INDOUBT.

When CANCEL THREAD is not enough

Hung in VTAM

DISPLAY THREAD(*) LUWID(token) DETAIL. Session IDs appear under SESSID. An N in the status column means the thread is processing in VTAM. Record positions 3–16 of SESSID, match them on DISPLAY NET for the LU, then VARY NET,TERM for those VTAM SIDs.

Hung in TCP/IP

DETAIL shows the partner IP and ports. Use D TCPIP,,NETSTAT,CONN,IPADDR= to find CONN, then V TCPIP,,DROP,CONN=. Requester and server threads differ in which port is local versus foreign—match the DISPLAY THREAD IP pair carefully. The same DROP technique applies to accelerated threads: DISPLAY THREAD(*) ACCEL(*) DETAIL, look for ST AC, then DROP the connection to the accelerator IP.

NOT LOGGED table spaces

Cancelling an updater of a NOT LOGGED table space can put the space in the LPL. Recover that space before you treat the incident as closed.

CANCEL THREAD versus other “cancel” words

  • STOP DDF MODE(SUSPEND) CANCEL(n) — time limit after which remaining DDF DBATs are canceled during a suspend, not a general-purpose thread cancel
  • RECOVER POSTPONED CANCEL — stop processing postponed abort URs (leaves objects inconsistent)
  • z/OS CANCEL or FORCE of MSTR/DBM1 — last resort and a different kind of disaster than cancelling one user thread
  • SQL ROLLBACK — the application asking to undo its own UR, not an operator cancel

Explain It Like I'm Five

A thread is a person standing at the checkout with a basket. CANCEL THREAD is the manager tapping that person on the shoulder and saying “please leave.” If they are still in the aisle (inside the application, not at the register), they might not hear until they walk back to the register (the next SQL call). DUMP is taking a photo while they are at the register so you can see what they were doing. FORCE is calling security for someone stuck in the revolving door (the network). NOBACKOUT is letting them leave without putting the groceries back—which makes a mess you must clean up later.

Exercises

  1. From a sample DISPLAY THREAD line that shows TOKEN 45162, write the cancel command with a diagnostic dump.
  2. Explain why cancelling LUWID DB2NET.LUNSITE0.A11A7D7B2057 might cancel more than one DBAT.
  3. A DDF thread remains after CANCEL THREAD and DETAIL shows N on the session. What two network commands (VTAM or TCP/IP) might come next?
  4. Write the two-step CANCEL THREAD sequence that includes FORCE, and state when IBM says FORCE will not help.
  5. A cancelled distributed thread issues DSNL450I. Which command family resolves the indoubt UR if automatic resolution fails?

Quiz

Test Your Knowledge

1. How do you identify the thread to cancel in most cases?

  • By SMF job number only
  • By the one- to six-digit token from DISPLAY THREAD (or the LUWID / DDF THREAD form for distributed work)
  • By the database name
  • By the buffer pool ID

2. Should you z/OS CANCEL a job before -CANCEL THREAD?

  • Yes, always purge JES first
  • No—IBM’s best practice is CANCEL THREAD first so Db2 abends the thread at a predictable location
  • Order does not matter
  • Only CANCEL DDF THREAD first from VTAM

3. What does DUMP on CANCEL THREAD do?

  • Always dumps even if the thread is not in Db2
  • Generates a dump when the thread is currently active in Db2; if the thread has left Db2, Db2 does a hard cancel and no dump
  • Dumps only IRLM
  • Writes SMF 30

4. When is FORCE accepted on CANCEL THREAD?

  • On the first cancel attempt always
  • Only after a CANCEL THREAD without FORCE was already issued; it tries to purge a remote connection hung in the network—not a thread hung inside Db2
  • Only with NOBACKOUT
  • Only for utilities

5. Why is NOBACKOUT dangerous?

  • It commits the thread
  • Db2 does not attempt to back out during rollback, which can leave objects inconsistent (REFP plus RECP or RBDP if backout later fails)
  • It only affects read-only threads
  • It is required for UR isolation