Tuesday, April 26, 2022

View Job Queue Info from SQL - IBM i

Job Queue

Dealing with Job Queues (JOBQ) is part of day to day life when working with IBM i. There comes many situations where we need to check if a JOBQ is Held or Released, Which subsystem the JOBQ is attached to, No of active/held/released/scheduled jobs in JOBQ, Maximum number of active jobs etc. 

Different commands (WRKJOBQ, WRKJOBQD, WRKSBSD) are available to view this information. 

There is another easier way to access this information is by using SQL view JOB_QUEUE_INFO in QSYS2 (system name - JOBQ_INFO). 

One thing to note is, User should either have read authority to the JOBQ or have one of the special authorities *JOBCTL, *SPLCTL.

This view is helpful in many different ways like, 
  • List of Job queues present in a library. 
  • List of Job queues HELD/RELEASED in a library.
  • Retrieve Subsystem a JOBQ is attached to. 
  • List of Job queues in a Subsystem. 
  • Retrieve maximum number of active jobs in a Job queue. 
  • Retrieve number of Active/Held/Released/Scheduled jobs in a Job queue. 
E.g.:

List of Job queues present in a library. 

SELECT * FROM QSYS2/JOB_QUEUE_INFO WHERE JOB_QUEUE_LIBRARY = 'PREDDY'

List of Job queues HELD/RELEASED in a library.

SELECT * FROM QSYS2/JOB_QUEUE_INFO WHERE JOB_QUEUE_LIBRARY = 'PREDDY' AND JOB_QUEUE_STATUS = 'RELEASED'

Retrieve Subsystem a JOBQ is attached to. 

SELECT SUBSYSTEM_NAME, SUBSYSTEM_LIBRARY_NAME FROM QSYS2/JOB_QUEUE_INFO WHERE JOB_QUEUE_LIBRARY = 'PREDDY' AND JOB_QUEUE_NAME = 'TESTJOBQ'

List of Job queues in a Subsystem. 

SELECT * FROM QSYS2/JOB_QUEUE_INFO WHERE SUBSYSTEM_NAME = 'TESTSBS' AND SUBSYSTEM_LIBRARY_NAME = 'PREDDY'

Retrieve maximum number of active jobs in a Job queue. 

SELECT MAXIMUM_ACTIVE_JOBS FROM QSYS2/JOB_QUEUE_INFO WHERE JOB_QUEUE_LIBRARY = 'PREDDY' AND JOB_QUEUE_NAME = 'TESTJOBQ' 

Retrieve number of Active/Held/Released/Scheduled jobs in a Job queue. 

SELECT ACTIVE_JOBS, HELD_JOBS, RELEASED_JOBS, SCHEDULED_JOBS FROM QSYS2/JOB_QUEUE_INFO WHERE JOB_QUEUE_LIBRARY = 'PREDDY' AND JOB_QUEUE_NAME = 'TESTJOBQ' 

In addition to these number of active/held/released/scheduled job information by priority can be found. 

Below are the important columns present in this view. 

JOB_QUEUE_NAME (JOBQ) - The name of the job queue.

JOB_QUEUE_LIBRARY (JOBQ_LIB) - The name of the library that contains the job queue.

JOB_QUEUE_STATUS (STATUS) - The status of the job queue. HELD (The queue is held), RELEASED (The queue is released)

NUMBER_OF_JOBS (JOBS) - The number of jobs in the queue.

SUBSYSTEM_NAME  (SUB_NAME) - The name of the subsystem that can receive jobs from this job queue. Contains the null value if this job queue is not associated with an active subsystem.

SUBSYSTEM_LIBRARY_NAME (SUBLIB_NAM) - The library in which the subsystem description resides. Contains the null value if this job queue is not associated with an active subsystem.

SEQUENCE_NUMBER (SEQNO) - The job queue entry sequence number. The subsystem uses this number to determine the order in which job queues are processed. Jobs from the queue with the lowest sequence number are processed first. Contains the null value if this job queue is not associated with an active subsystem.

MAXIMUM_ACTIVE_JOBS (MAX_JOBS) - The maximum number of jobs that can be active at the same time through this job queue entry. A value of -1 indicates *NOMAX, no maximum number of jobs is defined. Contains the null value if this job queue is not associated with an active subsystem.

ACTIVE_JOBS (ACT_JOBS) - The current number of jobs that are active that came through this job queue entry. Contains the null value if this job queue is not associated with an active subsystem.

HELD_JOBS (HELD_JOBS) - The current number of jobs that are in *HELD status. 

RELEASED_JOBS (RLS_JOBS) - The current number of jobs that are in *RELEASED status. 

SCHEDULED_JOBS (SCHED_JOBS) - The current number of jobs that are in *SCHEDULED status. 

TEXT_DESCRIPTION (TEXT) - Text that describes the job queue. Contains the null value if there is no text description for the job queue.

OPERATOR_CONTROLLED (OPR_CTRL) - Whether users with job control authority are allowed to control this job queue and manage the jobs on the queue. Users have job control authority if SPCAUT(*JOBCTL) is specified in their user profile. *NO - This queue and its jobs cannot be controlled by users with job control authority unless they also have other special authority. *YES - Users with job control authority can control the queue and manage the jobs on the queue.

AUTHORITY_TO_CHECK (ALL_AUTH) - Whether the user must be the owner of the queue in order to control the queue by holding or releasing the queue. *DTAAUT - Any user with *READ, *ADD, or *DELETE authority to the job queue can control the queue. *OWNER - Only the owner of the job queue can control the queue.


If you have any Suggestions or Feedback, Please leave a comment below or use Contact Form. 

Friday, April 15, 2022

Record Lock Info from SQL - IBM i

Record Locks

Record locks often causes the programs to crash if not handled properly. Identifying which job is locking the record is essential to resolve the issue (specially if the locking job is interactive idle for long time). 

One way of identifying the Record locks is by using the command DSPRCDLCK (Display Record Locks). 

This command accepts the below parameters and allows checking for the locks at the file, member and record level. Output of this command can only be either display or print. 

                       Display Record Locks (DSPRCDLCK)              
                                                                     
Type choices, press Enter.                                           
                                                                     
Physical file  . . . . . . . . . > TESTFILE      Name                
  Library  . . . . . . . . . . . >   PREDDY1     Name, *LIBL, *CURLIB
Member . . . . . . . . . . . . .   *FIRST        Name, *FIRST        
Record number  . . . . . . . . .   *ALL          1-4294967288, *ALL  
Output . . . . . . . . . . . . .   *             *, *PRINT           

Physical File - Name of the physical file for which record locks are to be checked. Locks can be checked only for one physical file at a time. 

Library - Library in which the physical file is present. Valid values are library name, *LIBL (default) and *CURLIB. 

Member - Name of the physical file member for which record locks are to be checked. Specific member name can be entered otherwise *FIRST (default) is considered. Record locks can be checked for only one member at a time. 

Record number - Record number can be entered for which we need to check if the specific record is locked. *ALL (default) checks for all the records in the file/member specified. 

Output - Output can either be displayed (by using * in Interactive job) or printed to spool file (by using * in Batch job or *PRINT in Interactive/Batch job).

This looks straight forward when we need to check the record locks for a single file or couple of files. And, If we need to resolve the locks manually. 

But, If we need to
  • Identify the record locks for a group of files.
  • Identify the record locks for all the members of a file. 
  • Identify the record locks for all the files in a Library.  
  • Identify the record locks by a specific Job. 
This can be easily achieved from SQL by running a query on the view RECORD_LOCK_INFO in QSYS2 (System name - RCD_LOCK). 

E.g.: 

Identify the record locks for a group of files. 

SELECT * FROM QSYS2/RECORD_LOCK_INFO WHERE TABLE_NAME IN ('TESTFILE', 'TESTFILE1', 'TESTFILE2') ;

Identify the record locks for all members of a file - Just querying for a file name (and library) would return the locks present in all members of the file. 

SELECT * FROM QSYS2/RECORD_LOCK_INFO WHERE TABLE_SCHEMA = 'PREDDY1' AND TABLE_NAME = 'TESTFILE' ;

Identify the record locks for all the files in a Library. 

SELECT * FROM QSYS2/RECORD_LOCK_INFO WHERE TABLE_SCHEMA = 'PREDDY1'  ;

Identify the record locks by a specific Job. 

SELECT * FROM QSYS2/RECORD_LOCK_INFO WHERE JOB_NAME = '123456/PREDDY/QPADEV1234' ;

Apart from these, the query can be run based on any of the columns available in the view RECORD_LOCK_INFO. 

Below are the columns present in the view. 

TABLE_SCHEMA (TABSCHEMA) - Name of the schema.

TABLE_NAME (TABNAME) - Name of the table.

TABLE_PARTITION (TABPART) - Name of the table partition or member that contains the locked record.

SYSTEM_TABLE_SCHEMA (SYS_DNAME) - System name of the schema.

SYSTEM_TABLE_NAME (SYS_TNAME) - System name of the table

SYSTEM_TABLE_MEMBER (SYS_MNAME) - The name of the member that contains the locked record.

RELATIVE_RECORD_NUMBER (RRN) - The relative record number (RRN) of the record that is locked.

LOCK_STATE (LOCK_STATE) - The lock condition for the record. Valid values are READ (The record is locked for read. Another job may read the same record but cannot lock the record for update intent. The record cannot be changed by another job as long as one job holds a read lock on the record.), UPDATE (The record is locked for update intent. Another job may read the record but may not obtain a read or update lock on it until the lock is released.) and INTERNAL (The row is locked internally for read. For a short time the operating system holds an internal lock to access the row. Another job may read the same row and may even have the row locked for update intent. However, if another job does have the row locked for update intent, the actual change of the row will not proceed until the internal lock is released.)

LOCK_STATUS (STATUS) - The status of the lock. Valid values are HELD (The lock is currently held by the job.), WAITING (The job is waiting for the lock.)

LOCK_SCOPE (LOCK_SCOPE) - The scope of the lock. Valid values are JOB, THREAD and LOCK SPACE

JOB_NAME (JOB_NAME) - The qualified job name.

THREAD_ID (THREAD_ID) - The thread that is associated with the lock. If a held lock is job scoped, returns the null value. If a held lock is thread scoped, contains the identifier for the thread holding the lock. If the scope of the lock is to the lock space and the lock is not held, contains the identifier of the thread requesting the lock. If the lock is requested but not yet available, contains the identifier of the thread requesting the lock.

LOCK_SPACE_ID (LOCKID) - When the LOCK_SCOPE column value is LOCK SPACE and the lock is being waited on by a thread, contains the lock space ID value for which the lock is being waited on. Otherwise, contains the null value.

If you have any Suggestions or Feedback, Please leave a comment below or use Contact Form. 

Different Ways of Sorting Data in a List - Python

Sorting Data in a List List is a collection of data (of different data types), much like an array. Like any data structure or data set, dat...