Db2 SQLCODE

SQLCODE -904: Resource unavailable

SQLCODE -904 (SQLSTATE 57011) means Db2 couldn't run the statement because something it needed was unavailable, such as a stopped or restricted table space, a data set that couldn't extend, or a lock limit. The reason code, resource type and resource name in the message say what.

Also written as SQL -904, SQLCODE=-904, SQLCODE = -904, db2 -904, sqlstate 57011, SQL0904N, unsuccessful execution caused by an unavailable resource, 00C90096.

What it means

-904 is Db2's general error for something it can't get to right now. The statement itself is fine. Something outside the program got in the way, and the message gives three tokens that tell you what.

  • The reason code, an 8-digit hex code such as 00C90096, says why the resource was unavailable.
  • The resource type says what kind of thing it was. 00000200 is a table space, 00000201 an index space and 00000302 a page in a table space.
  • The resource name names it, such as PAYDB.PAYTS01 for a table space, with the page number in hex added for a page.

-904 doesn't roll back the unit of work. Only the failing statement is affected, and the program decides whether to retry, roll back or stop.

One reason code comes up often enough to know by heart. 00C90096 means the program holds more locks than the subsystem allows for one user, the NUMLKUS limit. For other codes, look them up in the Db2 codes manual for your release.

Common causes

  • The table space, index space or partition is stopped, for example by a -STOP DATABASE command for maintenance.
  • The object is in a restricted status that blocks the access, such as RECOVER-pending, REBUILD-pending, CHECK-pending or REORG-pending. COPY-pending blocks updates but still allows reads.
  • A utility such as REORG, LOAD or RECOVER is working on the object, or stopped partway and still holds it.
  • A data set can't extend, because its volumes are full, it reached its extent limit, or the table space is at its maximum size.
  • A batch program updated a large number of rows without a COMMIT and ran into the lock limit per user (reason 00C90096).
  • Pages are in the logical page list (LPL) after an error, so Db2 won't use them until they're recovered.

How to find the problem

  1. Note the reason code, resource type and resource name from the DSNT408I message or SQLERRMC.
  2. Run -DISPLAY DATABASE(PAYDB) SPACENAM(PAYTS01) RESTRICT to see whether the object is stopped or in a restricted status. Adding LOCKS instead of RESTRICT shows who holds locks on it.
  3. Run -DISPLAY UTILITY(*) to see whether a utility is active on the object, including one that stopped and still holds it.
  4. Look in the Db2 master address space log (the xxxxMSTR job) at the same time. DSNT501I repeats the reason code with the job's correlation ID, and DSNP007I reports a data set that failed to extend.
  5. Look up the reason code in the Db2 codes manual for your release. It names the exact condition Db2 hit.

How to fix it

  • Once the underlying problem is fixed, start the object with -START DATABASE(PAYDB) SPACENAM(PAYTS01) ACCESS(RW).
  • Clear a restricted status with the utility it calls for, such as COPY for COPY-pending, REORG for REORG-pending or RECOVER for RECOVER-pending.
  • For space problems, have the storage team or DBA add volumes, raise PRIQTY and SECQTY, or move the object to a larger data set size, then rerun.
  • For 00C90096, commit more often in the program. The DBA can also lower LOCKMAX or change LOCKSIZE so Db2 escalates to a table space lock before the limit is reached.
  • Keep batch updates out of utility windows, and give programs retry logic for short outages.

What it looks like

PAYUPD1 - UPDATE EMP_HIST FAILED, EMPNO 0047113
DSNT408I SQLCODE = -904, ERROR:  UNSUCCESSFUL EXECUTION CAUSED BY AN UNAVAILABLE RESOURCE.
         REASON 00C90096, TYPE OF RESOURCE 00000302, AND RESOURCE NAME
         PAYDB.PAYTS01.X'0001A4'
DSNT418I SQLSTATE   = 57011 SQLSTATE RETURN CODE

Questions

Is -904 the program's fault?

Usually not. The statement is valid, and something in Db2 or the storage behind it was unavailable. The exception is reason 00C90096, which comes from a program taking too many locks before it commits.

Does -904 roll back my work?

No. The work done since the last commit is still pending. Most batch programs choose to roll back and stop, then restart from their last checkpoint once the object is available.

What's the difference between -904 and -911?

-911 is a deadlock or lock timeout with another user, and Db2 rolls back your work. -904 is a resource that isn't available at all, and nothing is rolled back.