DB2

DB2 SQLCODE -904 in Batch: Triage an Unavailable Resource Without Mistaking It for a Lock

A DB2 batch program that receives SQLCODE `-904` has found a resource that DB2 cannot currently use. This guide shows how to turn that broad message into evidence and a safe decision, rather than treating it as an ordinary lock wait or immediately rerunning the job.

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

A DB2 batch program that receives SQLCODE -904 has found a resource that DB2 cannot currently use. This guide shows how to turn that broad message into evidence and a safe decision, rather than treating it as an ordinary lock wait or immediately rerunning the job.

The symptom is useful, but incomplete

-904 is commonly described as “unavailable resource.” That wording is accurate but not enough for production support. The unavailable item might be a table space, index space, database object, storage group, utility-related state, or another DB2-managed resource. The important details are usually in SQLERRMC, job output, DB2 messages, and the timing of the failure.

A dangerous shortcut is to put -904 in the same recovery bucket as -911 or -913. Lock contention and deadlock conditions often have retry considerations. A resource-unavailable condition may instead reflect an object state, an administrative operation, or a capacity problem. Repeating the same SQL before understanding the resource can create repeated failures, confusing logs, or a partial business cycle.

Consider a fictional nightly account-update job. It reads an approved transaction file, inserts audit rows, then updates account balances. The program stops on the first update:

           EXEC SQL
               UPDATE ACCT_BALANCE
                  SET AVAILABLE_AMT = AVAILABLE_AMT + :WS-DELTA-AMT,
                      LAST_UPD_TS   = CURRENT TIMESTAMP
                WHERE ACCOUNT_NO    = :WS-ACCOUNT-NO
           END-EXEC

IF SQLCODE NOT = 0
MOVE SQLCODE TO WS-SQLCODE
PERFORM WRITE-DB2-ERROR
PERFORM CONTROLLED-STOP
END-IF
```

The code correctly stops rather than continuing after a failed update. But SQLCODE alone cannot tell the operator whether no changes occurred, some changes were committed, or which resource needs attention. The recovery decision belongs to the job’s unit-of-work design and the evidence collected after the failure.

Capture this evidence before changing anything

Keep the original spool, program log, and scheduler context available. A short evidence set is more useful than a long list of guesses:

Do not paste sensitive account identifiers into a ticket or chat channel. A masked key, a sequence number, or an approved correlation ID is normally enough to locate the event under local procedures.

Diagnosis path: classify the resource before selecting recovery

Use the application and DB2 messages together. The following decision flow is intentionally generic because the exact text and administrative commands vary by DB2 release and site standards.

-904 received
  |
  +-- Is the resource name/type identified in SQLERRMC or DB2 messages?
  |      |
  |      +-- No: preserve diagnostics; ask the DB2 support team to identify it.
  |
  +-- Yes: is there approved utility, maintenance, or an outage on that object?
         |
         +-- Yes: wait for the owning team to confirm the object is available.
         |
         +-- No: is the message consistent with capacity, allocation, or another
                  subsystem resource limit?
                |
                +-- Yes: escalate with time, resource identity, and job impact.
                |
                +-- No: investigate object status and recent change activity with DB2 support.

The aim is classification, not self-service repair. A batch developer may be able to identify the statement and commit boundary, while a DB2 administrator is the appropriate owner for object availability and administrative state. Do not assume that a similarly named object in another subsystem has the same status.

### Why the commit boundary changes the answer

Suppose the fictional program commits every 1,000 input transactions. It has successfully committed records 1 through 12,000 and receives -904 while processing record 12,417. The input file has not failed; the output and DB2 changes must still be reconciled.

A simple control record can make that state visible:

RUN-ID=20261106-ACCT
LAST-COMMITTED-SEQ=12000
INPUT-COUNT=12417
DB2-UPDATE-COUNT=12000
DB2-INSERT-COUNT=12000
STATUS=STOPPED-DB2-904

This record is an aid to investigation, not authority to restart automatically. First confirm that the control record itself is written only after the matching DB2 commit succeeds. If it is written before the commit, it can overstate progress. Also determine whether the job writes a downstream extract before, after, or within the same recoverable unit of work. A rerun based only on input count can duplicate outbound activity even if DB2 updates are protected.

Safe correction is owned by the resource, not the application

When an authorized team confirms a transient, resolved resource condition, the batch team still needs a controlled restart plan. When the resource is an object undergoing a utility or administrative process, wait for that team’s explicit availability confirmation. Do not cancel a utility, force object changes, rebind packages, alter space settings, or issue administrative commands merely because the application saw -904.

A correct application-side correction may be quite small: improve the error log so it includes the SQL operation, SQLCODE, SQLSTATE, and masked business sequence; preserve a durable checkpoint after commit; or ensure the scheduler does not launch the job during an approved maintenance window. Those changes should follow normal code review, test, and change-control practices.

Retry logic also needs restraint. An automatic retry is only defensible when the service owner has defined the resource condition as transient, the SQL operation is safe to repeat, and the program can prove where the prior unit of work ended. Retrying a non-idempotent insert or an external interface call without that proof is not a resilience feature.

Before rerun

Use this support checklist after the unavailable resource has been investigated:

If a checkpoint is absent or contradictory, stop and escalate rather than selecting a convenient restart record. A clean RC=0 after a replay does not prove that duplicate business activity was avoided.

Practical takeaway

Treat DB2 -904 as a request to identify an unavailable resource and establish the last committed business boundary. Once the resource owner confirms availability and the application’s prior work is reconciled, a controlled restart can be considered; until then, a rerun is only another unproven attempt.

← Back to all articles