The direct way, from the command line:
WRKOBJLCK OBJ(PRODLIB/ITEMS) OBJTYPE(*FILE)
The same in SQL, useful when the result has to be collected in a program or several objects looked at together:
SELECT JOB_NAME, LOCK_STATE, LOCK_STATUS, LOCK_SCOPE
FROM QSYS2.OBJECT_LOCK_INFO
WHERE SYSTEM_OBJECT_SCHEMA = 'PRODLIB'
AND SYSTEM_OBJECT_NAME = 'ITEMS'
For database file members the lock can be on the individual member:
WRKOBJLCK OBJ(PRODLIB/ITEMS) OBJTYPE(*FILE) MBR(*ALL)
Example: the backup that fails at two in the morning
SAVLIB ends with an object not saved because somebody was holding it open. By the next
morning the lock is gone (whoever held it has closed the session) and WRKOBJLCK is no
help: it shows the situation now, not last night's.
The query, on the other hand, can sit in the backup CL under the MONMSG, and fires at the
exact moment the lock is still there. First the table, created from the query itself so names
and types come from the view:
CREATE TABLE MYLIB/DIAGLCK AS (
SELECT CURRENT TIMESTAMP AS TAKEN_AT, SYSTEM_OBJECT_NAME,
JOB_NAME, LOCK_STATE
FROM QSYS2.OBJECT_LOCK_INFO
) WITH NO DATA
Then the backup:
SAVLIB LIB(PRODLIB) DEV(TAP01)
MONMSG MSGID(CPF3771) EXEC(DO)
RUNSQL SQL('INSERT INTO MYLIB/DIAGLCK +
SELECT CURRENT TIMESTAMP, SYSTEM_OBJECT_NAME, +
JOB_NAME, LOCK_STATE +
FROM QSYS2.OBJECT_LOCK_INFO +
WHERE SYSTEM_OBJECT_SCHEMA = ''PRODLIB''') COMMIT(*NONE)
MONMSG MSGID(CPF0000)
ENDDO
CPF3771 is SAVLIB's message for "objects saved, others not saved". After three nights the
table says whether it is always the same job (then it is a program to
fix) or different users every time, in which case the problem is when the backup runs. For
objects in use SAVLIB also has the SAVACT parameter, save while active: without it, IBM
warns, an object in use is not saved.
Note
a lock held by an interactive session may be a screen left open on a record. Ask
whoever uses it before ending the job: ENDJOB interrupts whatever it was doing.
Releases. WRKOBJLCK exists on any release. The QSYS2.OBJECT_LOCK_INFO view is more
recent: if it is missing the query answers SQL0204, and the
command remains, giving the same information on screen.
Comments
No comments yet. Be the first to comment!
You need an account to comment. Log in · Sign up