IBM i message

CPF2113: Cannot allocate library

CPF2113 means the command needed a lock on a library and couldn't get it, because another job holds a lock that conflicts. ADDLIBLE, CHGLIBL, CRTDUPOBJ and RNMOBJ are common senders.

Other names for this code

Also written as CPF2113 cannot allocate library, MSGID CPF2113, ADDLIBLE CPF2113, library locked IBM i, MONMSG CPF2113.

What it means

CPF2113 is an escape message from QCPFMSG with the text "Cannot allocate library &1". Allocate is IBM i's word for taking a lock. Libraries are objects, of type *LIB, and jobs lock them like any other object.

Every library on a job's library list is held with a shared lock for as long as it stays on the list. Shared locks get along with each other, so thousands of jobs can have the same library on their lists. A command that needs the library to itself, such as renaming or deleting it, asks for an exclusive lock, and that conflicts with every shared lock.

So CPF2113 usually shows up in one of two ways. A command like ADDLIBLE can't get its shared lock because some other job holds the library exclusively. Or a command that needs the library exclusively, such as a rename, can't get it because other jobs are using the library. In both cases the system waited for the job's wait time and then gave up.

Common causes

  • Another job has the library locked exclusively, for example with ALCOBJ OBJ((QSYS/ACCTLIB *LIB *EXCL)) during a nightly process.
  • A job is renaming or deleting the library, or doing other work on it that needs it to itself.
  • Your own command needs the library exclusively, and other jobs, including idle interactive sessions, still have it on their library lists.
  • The job's default wait time is short, so even a brief lock by another job is enough to make the command fail.

How to find the problem

  1. Run WRKOBJLCK OBJ(QSYS/ACCTLIB) OBJTYPE(*LIB). It lists each job holding a lock on the library and the lock state. Look for *EXCL or *EXCLRD if your command wanted a shared lock, or for any lock at all if it wanted an exclusive one.
  2. Take option 5 next to a job in that list to see what it is doing.
  3. In the job that failed, open the job log with DSPJOBLOG, put the cursor on CPF2113 and press F1 to confirm the library. The command logged just before it shows which command wanted the lock.

How to fix it

  • Wait until the other job finishes and try again, or schedule your job outside that job's window.
  • If you need the library to yourself, ask users to sign off or remove it from their lists, and end any server jobs that hold it. Do this only when it is safe.
  • In a CL program, monitor for CPF2113, wait with DLYJOB, and retry a few times before failing.
  • If a nightly process locks the library exclusively, check that it really needs to. A weaker lock may be enough and would let other jobs keep running.

What it looks like

Cannot allocate library ACCTLIB.

IBM documentation

IBM Display Message Descriptions (DSPMSGD). Use the documentation for your installed release.

This link opens the relevant IBM reference library or lookup instructions. Match the complete code and your installed product release; it is not a code-specific review.

Read the installed message description:

DSPMSGD MSGID(CPF2113) MSGF(QSYS/QCPFMSG)

Also inspect the full job log and second-level message text, including substitution values.

Report a correction to WND Software.

Questions

What is the difference between CPF2113 and CPF9803?

Both mean a lock couldn't be obtained. CPF2113 is about a library, and CPF9803 is about another object in a library.

Why can't I rename or delete a library that nobody seems to be using?

Any job that has the library on its library list holds a shared lock on it, even if it is sitting idle. WRKOBJLCK on the library shows those jobs.

Can I see library locks with SQL?

On recent releases the QSYS2.OBJECT_LOCK_INFO view shows object locks, including locks on libraries. WRKOBJLCK works on every release.