DB2

DB2 SQLCODE -911 and -913 in Batch Updates: Evidence-First Recovery and Retry Design

A DB2 batch step that ends with `SQLCODE -911` or `SQLCODE -913` has lost work, but it has not necessarily identified the cause. This incident guide explains how to separate a deadlock or timeout symptom from the recovery decision, collect evidence without exposing business data, and design a retry that does not duplicate processing.

ProgramPlanPackageDB2 access
Original DBala learning flow — a visual summary of this article’s practical decision path.

A DB2 batch step that ends with SQLCODE -911 or SQLCODE -913 has lost work, but it has not necessarily identified the cause. This incident guide explains how to separate a deadlock or timeout symptom from the recovery decision, collect evidence without exposing business data, and design a retry that does not duplicate processing.

The program, table names, and job flow below are fictional. DB2 release levels, reason codes, isolation rules, utilities, and local restart procedures vary; do not rerun, bind, cancel another workload, or alter lock settings merely to clear the immediate failure.

Symptom: an update step stops after processing part of its input

Consider POLUPD, a COBOL program that applies approved policy changes from a daily work file. It updates a DB2 table and writes an audit extract. Every 500 successful rows it issues COMMIT and records a checkpoint key. Midway through the run, the job log shows an SQL message with SQLCODE -911 or SQLCODE -913 and a reason code supplied by the local DB2 environment.

Both codes are commonly associated with a deadlock or timeout condition, but the operational meaning must be read from the complete message and reason code. A deadlock occurs when concurrent units of work hold resources needed by each other and DB2 chooses one as the victim. A timeout occurs when a request waits longer than the configured limit. The exact lock, duration, and rollback behavior must be confirmed from the site’s diagnostics.

The important first fact is usually this: DB2 rolls back the current unit of work for the failing transaction. Earlier committed units can remain successful. Therefore, “rerun from the start” may reapply already committed input unless the application has a documented idempotency or checkpoint design.

Evidence to capture before changing anything

Preserve the job spool and collect facts that allow the application and DB2 support teams to describe one execution, not an assumed one.

Do not infer the blocking job from a job name that happened to run at the same time. A lock trace, DB2 monitor, or site-approved diagnostic can identify relevant holders and waiters more reliably. It is also possible that the application’s own access order creates the conditions for a deadlock.

Diagnosis path: distinguish the failure mechanism from the restart scope

### 1. Establish the rollback boundary

Find the last successful commit and the key or sequence value recorded at that point. If POLUPD commits every 500 rows and fails on row 1,237, rows in the current uncommitted unit are normally rolled back, while the first 1,000 may remain committed. The actual boundary depends on application commits, error handling, and any implicit unit-of-work behavior, so confirm it from the program’s evidence rather than calculating it from an expected count.

A simplified pattern is shown below. The checkpoint update must participate in the same controlled unit-of-work design as the business update; it should not be treated as an independent proof that every side effect succeeded.

           PERFORM UNTIL END-OF-INPUT
              PERFORM READ-CHANGE-RECORD
              IF NOT END-OF-INPUT
                 PERFORM APPLY-POLICY-CHANGE
                 IF WS-SQLCODE = 0
                    ADD 1 TO WS-UOW-COUNT
                    MOVE IN-POLICY-ID TO WS-LAST-KEY
                    IF WS-UOW-COUNT = 500
                       PERFORM COMMIT-AND-CHECKPOINT
                    END-IF
                 ELSE
                    PERFORM HANDLE-SQL-ERROR
                 END-IF
              END-IF
           END-PERFORM.

COMMIT-AND-CHECKPOINT.
PERFORM WRITE-RESTART-CONTROL
EXEC SQL COMMIT END-EXEC
IF SQLCODE NOT = 0
PERFORM HANDLE-SQL-ERROR
END-IF
MOVE ZERO TO WS-UOW-COUNT.
```

This is a learning example, not a complete restart framework. In particular, a checkpoint update placed outside the correct DB2 unit of work can create a false restart position after a rollback. Follow the established application pattern and have a DB2-aware reviewer validate the transaction boundary.

### 2. Identify whether access order is plausible

Deadlocks are often made more likely when two programs update the same objects in different sequences. For example, one path updates POLICY then POLICY-AUDIT, while another updates the audit row then policy row. A timeout can arise when a large update unit, utility, or long-running online transaction holds a needed resource.

Ask focused questions:

| Observation | What it suggests | Safe next step |
| --- | --- | --- |
| Same pair of jobs repeatedly overlaps and one is a victim | A repeatable concurrency design or scheduling conflict may exist. | Compare object access order and coordinate with DB2/application owners. |
| Failure happens only during a utility or deployment window | A planned activity may be holding or changing access to an object. | Verify the approved schedule and whether the batch window should exclude that activity. |
| Timeout occurs after a long run with a large commit interval | The unit of work may hold locks too long, but this is not proven. | Review transaction size and access path under normal performance/change controls. |
| No clear concurrent workload is visible | The evidence is incomplete, or an intermittent path is involved. | Retain timestamps and escalate with the full diagnostic context. |

Do not change isolation level, lock timeout, commit frequency, or index definitions as an incident-only shortcut. Each can alter consistency, throughput, logging, recovery behavior, or contention elsewhere.

Safe correction and retry decision

If the first diagnosis shows a one-time overlap with an approved workload, the responsible teams may decide to rerun from the documented checkpoint after the conflict has cleared. That is not the same as blindly restarting the failed step. Confirm that input selection begins after the last committed key or that the update is safely idempotent for already-processed records.

If the issue is recurring, make the permanent correction explicit: serialize incompatible workloads, align update order, shorten a carefully tested unit of work, improve access paths, or redesign the handoff. The correct option depends on evidence and local standards. Test it with realistic concurrency in a non-production environment where possible.

For a program that produces an audit file, compare file behavior with DB2 behavior. A sequential record written before a later SQL rollback is not automatically removed. A safe recovery may require a run ID, a discard-and-rebuild procedure, duplicate suppression, or a controlled reconciliation. Never assume a DB2 rollback cleans up non-DB2 output.

Before rerun: support checklist

Practical takeaway

-911 and -913 are concurrency signals, not automatic instructions to restart a batch job. Prove the rollback boundary, identify the actual competing work, account for non-DB2 side effects, and use a documented checkpoint or idempotent path before retrying. That turns a transient lock event into a controlled recovery rather than a duplicate-update incident.

← Back to all articles