ADMIN_UTL_SCHEDULE stored procedure

The SYSPROC.ADMIN_UTL_SCHEDULE stored procedure executes utilities in parallel.

Environment

Begin general-use programming interface information.

ADMIN_UTL_SCHEDULE runs in a WLM-established stored procedures address space.

Authorization

To execute the CALL statement, the owner of the package or plan that contains the CALL statement must have one or more of the following privileges on each package that the stored procedure uses:

  • The EXECUTE privilege on the package for DSNADMUM
  • Ownership of the package
  • PACKADM authority for the package collection
  • SYSADM authority

The ADMIN_UTL_SCHEDULE stored procedure internally calls the following stored procedures:

  • ADMIN_COMMAND_DB2, to execute the Db2 DISPLAY UTILITY command
  • ADMIN_INFO_SSID, to obtain the subsystem ID of the connected Db2 subsystem
  • ADMIN_UTL_SORT, to sort objects into parallel execution units
  • DSNUTILU, to run the requested utilities

The owner of the package or plan that contains the CALL ADMIN_UTL_SCHEDULE statement must also have the authorization required to execute these stored procedures and run the requested utilities. To determine the privilege or authority required to call DSNUTILU, see DSNUTILU stored procedure.

Syntax

The following syntax diagram shows the SQL CALL statement for invoking this stored procedure:

Read syntax diagramSkip visual syntax diagram CALL SYSPROC.ADMIN_UTL_SCHEDULE ( max-parallel , optimize-workloadNULL , stop-conditionNULL , utility-ID-stem , shutdown-durationNULL , number-of-objects , utilities-run , highest-return-code , parallel-tasks , return-code , message )

Option descriptions

max-parallel
Specifies the maximum number of parallel threads that may be started. The actual number may be lower than the requested number based on the optimizing sort result. Possible values are 1 to 99.

This is an input parameter of type SMALLINT and cannot be null.

optimize-workload
Specifies whether the parallel utility executions should be sorted to achieve shortest overall execution time. Possible values are:
NO or null
The workload is not to be sorted.
YES
The workload is to be sorted.

This is an input parameter of type VARCHAR(8). The default value is NO.

stop-condition
Specifies the utility execution condition after which ADMIN_UTL_SCHEDULE will not continue starting new utility executions in parallel, but will wait until all currently running utilities have completed and will then return to the caller. Possible values are:
AUTHORIZ or null
No new utility executions will be started after one of the currently running utilities has encountered a return code from DSNUTILU of 12 or higher.
WARNING
No new utility executions will be started after one of the currently running utilities has encountered a return code from DSNUTILU of 4 or higher.
ERROR
No new utility executions will be started after one of the currently running utilities has encountered a return code from DSNUTILU of 8 or higher.

This is an input parameter of type VARCHAR(8). The default value is AUTHORIZ.

utility-ID-stem
Specifies the first part of the utility ID of a utility execution in a parallel thread. The complete utility ID is dynamically created in the form utility-ID-stem followed by TT followed by NNNNNN, where:
TT
The zero-padded number of the subtask executing the utility
NNNNNN
A consecutive number of utilities executed in a subtask.

For example, utilityidstem02000005 is the fifth utility execution that has been processed by the second subtask.

This is an input parameter of type VARCHAR(8) and cannot be null.

shutdown-duration
Specifies the elapsed time in seconds that ADMIN_UTL_SCHEDULE will allow utility executions before a shutdown is initiated. When a shutdown is initiated, current utility executions can run to completion, and no new utility will be started. Possible values are:
null
A shutdown will not be performed.
1 to 999999999999999
A shutdown will be performed after this many seconds.

This is an input parameter of type FLOAT(8). The default value is null.

number-of-objects
As an input parameter, this specifies the number of utility executions and their sorting objects that were passed in the SYSIBM.UTILITY_OBJECTS table. Possible values are 1 to 999999.

As an output parameter, this specifies the number of objects that were passed in SYSIBM.UTILITY_OBJECTS table that are found in the Db2 catalog.

This is an input and output parameter of type INTEGER and cannot be null.

utilities-run
Indicates the number of actual utility executions.

This is an output parameter of type INTEGER.

highest-return-code
Indicates the highest return code from DSNUTILU for all utility executions.

This is an output parameter of type INTEGER.

parallel-tasks
Indicates the actual number of parallel tasks that were started to execute the utility in parallel.

This is an output parameter of type SMALLINT.

return-code
Provides the return code from the stored procedure. Possible values are:
0
All parallel utility executions ran successfully.
4
The statistics for one or more sorting objects have not been gathered in the catalog.
12
An ADMIN_UTL_SCHEDULE error occurred or all the objects passed in the SYSIBM.UTILITY_OBJECTS table are not found in the Db2 catalog. The message parameter contains details.

This is an output parameter of type INTEGER.

message
Contains messages describing the error encountered by the stored procedure. If no error occurred, then no message is returned.

The first messages in this area are generated by the stored procedure. Messages that are generated by Db2 might follow the first messages.

This is an output parameter of type VARCHAR(1331).

Additional input

In addition to the input parameters, the stored procedure reads from the created global temporary tables SYSIBM.UTILITY_OBJECTS and SYSIBM.UTILITY_STMT.

The stored procedure reads objects for utility execution from SYSIBM.UTILITY_OBJECTS. The following table shows the format of the created global temporary table SYSIBM.UTILITY_OBJECTS:

Table 1. Format of the input objects
Column name Data type Contents
OBJECTID INTEGER A unique positive identifier for the object the utility execution is associated with. When you insert multiple rows, increment OBJECTID by 1, starting at 0 for every insert.
STMTID INTEGER A statement row in SYSIBM.UTILITY_STMT
TYPE VARCHAR(10) Object type:
  • TABLESPACE
  • INDEXSPACE
  • TABLE
  • INDEX
  • STOGROUP
QUALIFIER VARCHAR(128) Qualifier (database or creator) of the object in NAME, empty or null for STOGROUP. If the qualifier is not provided and the type of the object is TABLESPACE or INDEXSPACE, then the default database is DSNDB04. If the object is of the type TABLE or INDEX, the schema is the current SQL authorization ID.
NAME VARCHAR(128) Unqualified name of the object. NAME cannot be null. If the object no longer exists, it will be ignored and the corresponding utility will not be executed.
PART SMALLINT Partition number of the object for which the utility will be invoked. Null or 0 if the object is not partitioned.
RESTART VARCHAR(8) Restart parameter of DSNUTILU
UTILITY_NAME VARCHAR(20) Utility name. UTILITY_NAME cannot be null.
Recommendation: Sort objects for the same utility.

Possible values are:

  • CHECK DATA
  • CHECK INDEX
  • CHECK LOB
  • COPY
  • COPYTOCOPY
  • DIAGNOSE
  • LOAD
  • MERGECOPY
  • MODIFY RECOVERY
  • MODIFY STATISTICS
  • QUIESCE
  • REBUILD INDEX
  • RECOVER
  • REORG INDEX
  • REORG LOB
  • REORG TABLESPACE
  • REPAIR
  • REPORT RECOVERY
  • REPORT TABLESPACESET
  • RUNSTATS INDEX
  • RUNSTATS TABLESPACE
  • STOSPACE
  • UNLOAD

The stored procedure reads the corresponding utility statements from SYSIBM.UTILITY_STMT. The following table shows the format of the created global temporary table SYSIBM.UTILITY_STMT:

Table 2. Format of the utility statements
Column name Data type Contents
STMTID INTEGER A unique positive identifier for a single utility execution statement
STMTSEQ INTEGER If a utility statement exceeds 4000 characters, it can be split up and inserted into SYSIBM.UTILITY_STMT with the sequence starting at 0, and then being incremented with every insert. During the actual execution, the statement pieces are concatenated without any separation characters or blanks in between.
UTSTMT VARCHAR(4000) A utility statement or part of a utility statement. A placeholder &OBJECT. can be used to be replaced by the object name passed in SYSIBM.UTILITY_OBJECTS. A placeholder &THDINDEX. can be used to be replaced by the current thread index (01-99) of the utility being executed. You can use this when running REORG with SHRLEVEL CHANGE in parallel, so that you can specify a different mapping table for each thread of the utility execution.

Example

The following C language sample shows how to invoke ADMIN_UTL_SCHEDULE:

 #include    <stdio.h>
 #include    <stdlib.h>
 #include    <string.h>

 /******************** DB2 SQL Communication Area ********************/
 EXEC SQL INCLUDE SQLCA;

 int main( int argc, char *argv[] )    /* Argument count and list    */
 {
   /****************** DB2 Host Variables ****************************/
   EXEC SQL BEGIN DECLARE SECTION;

   /* SYSPROC.ADMIN_UTL_SCHEDULE parameters                          */
   short int maxparallel;              /* Max parallel               */
   short int ind_maxparallel;          /* Indicator variable         */
   char optimizeworkload[9];           /* Optimize workload          */
   short int ind_optimizeworkload;     /* Indicator variable         */
   char stoponcond[9];                 /* Stop on condition          */
   short int ind_stoponcond;           /* Indicator variable         */
   char utilityidstem[9];              /* Utility ID stem            */
   short int ind_utilityidstem;        /* Indicator variable         */
   float shutdownduration;             /* Shutdown duration          */
   short int ind_shutdownduration;     /* Indicator variable         */
   long int numberofobjects;           /* Number of objects          */
   short int ind_numberofobjects;      /* Indicator variable         */
   long int utilitiesexec;             /* Utilities executed         */
   short int ind_utilitiesexec;        /* Indicator variable         */
   long int highestretcd;              /* DSNUTILU highest ret code  */
   short int ind_highestretcd;         /* Indicator variable         */
   long int paralleltasks;             /* Parallel tasks             */
   short int ind_paralleltasks;        /* Indicator variable         */
   long int retcd;                     /* Return code                */
   short int ind_retcd;                /* Indicator variable         */
   char errmsg[1332];                  /* Error message              */
   short int ind_errmsg;               /* Indicator variable         */

   /* Temporary table SYSIBM.UTILITY_OBJECTS columns                 */
   long int objectid;                  /* Object id                  */
   long int stmtid;                    /* Statement ID               */
   char type[11];                      /* Object type (e.g. "INDEX") */
   char qualifier[129];                /* Object qualifier           */
   short int ind_qualifier;            /* Object qualifier ind. var. */
   char name[129];                     /* Object name (qual. or unq.)*/
   short int part;                     /* Optional partition         */
   short int ind_part;                 /* Partition indicator var    */
   char restart[9];                    /* DSNUTILU restart parm      */
   char utname[21];                    /* Utility name               */

   /* Temporary table SYSIBM.UTILITY_STMT columns                    */
   long int stmtid2;                   /* Statement ID               */
   long int stmtseq;                   /* Utility stmt sequence      */
   char utstmt[4001];                  /* Utility statement          */

   /* Result set locators                                            */
   volatile SQL TYPE IS RESULT_SET_LOCATOR *rs_loc1;
   volatile SQL TYPE IS RESULT_SET_LOCATOR *rs_loc2;

   /* First result set row                                           */
   long int objectid1;                 /* Object id                  */
   long int textseq;                   /* Object utility output seq   */
   char text[255];                     /* Object utility output      */

   /* Second result set row                                          */
   long int objectid2;                 /* Object id                  */
   long int utilretcd;                 /* DSNUTILU return code       */
   EXEC SQL END DECLARE SECTION;

   /******************************************************************/
   /* Set up the objects to be sorted                                */
   /******************************************************************/
   long int objid_array[4] = {1, 2, 3, 4};
   long int stmtid_array[4] = {1, 1, 1, 1};
   char type_array[4][11] = {"TABLESPACE", "TABLESPACE",
                             "TABLESPACE", "TABLESPACE"};
   char qual_array[4][129] = {"QUAL01", "QUAL01",
                              "QUAL01", "QUAL01"};
   char name_array[4][129] = {"TBSP01", "TBSP02",
                              "TBSP03", "TBSP04"};
   short int part_array[4] = {0, 0, 0, 0};
   char restart_array[4][9] = {"NO", "NO",
                               "NO", "NO"};
   char utname_array[4][21]= {"RUNSTATS TABLESPACE",
                              "RUNSTATS TABLESPACE",
                              "RUNSTATS TABLESPACE",
                              "RUNSTATS TABLESPACE"};

   int i = 0;                          /* Loop counter               */

   /******************************************************************/
   /* Set up utility statement                                       */
   /******************************************************************/
   stmtid2 = 1;
   stmtseq = 1;
   strcpy(utstmt,
    "RUNSTATS TABLESPACE &OBJECT. TABLE(ALL) SAMPLE 25 INDEX(ALL)");

   /******************************************************************/
   /* Assign values to input parameters                              */
   /* Set the indicator variables to 0 for non-null input parameters */
   /* Set the indicator variables to -1 for null input parameters    */
   /******************************************************************/
   maxparallel = 2;
   ind_maxparallel = 0;
   strcpy(optimizeworkload, "YES");
   ind_optimizeworkload = 0;
   strcpy(stoponcond, "AUTHORIZ");
   ind_stoponcond = 0;
   strcpy(utilityidstem, "DSNADMUM");
   ind_utilityidstem = 0;
   numberofobjects = 4;
   ind_numberofobjects = 0;
   ind_shutdownduration = -1;

   /******************************************************************/
   /* Clear temporary table SYSIBM.UTILITY_OBJECTS                   */
   /******************************************************************/
   EXEC SQL DELETE FROM SYSIBM.UTILITY_OBJECTS;

   /******************************************************************/
   /* Insert the objects into the temporary table                    */
   /* SYSIBM.UTILITY_OBJECTS                                         */
   /******************************************************************/
   for (i = 0; i < 4; i++)
   {
     objectid = objid_array[i];
     stmtid = stmtid_array[i];
     strcpy(type, type_array[i]);
     strcpy(qualifier, qual_array[i]);
     strcpy(name, name_array[i]);
     part = part_array[i];
     strcpy(restart, restart_array[i]);
     strcpy(utname, utname_array[i]);
     EXEC SQL INSERT INTO SYSIBM.UTILITY_OBJECTS
                     (OBJECTID, STMTID, TYPE,
                      QUALIFIER, NAME, PART,
                      RESTART, UTILITY_NAME)
              VALUES (:objectid, :stmtid, :type,
                      :qualifier, :name, :part,
                      :restart, :utname);
   };

   /******************************************************************/
   /* Clear temporary table SYSIBM.UTILITY_STMT                      */
   /******************************************************************/
   EXEC SQL DELETE FROM SYSIBM.UTILITY_STMT;

   /******************************************************************/
   /* Insert the utility statement into the temporary table          */
   /* SYSIBM.UTILITY_STMT                                            */
   /******************************************************************/
   EXEC SQL INSERT INTO SYSIBM.UTILITY_STMT
                   (STMTID, STMTSEQ, UTSTMT)
            VALUES (:stmtid2, :stmtseq, :utstmt);

   /******************************************************************/
   /* Call stored procedure SYSPROC.ADMIN_UTL_SCHEDULE               */
   /******************************************************************/
   EXEC SQL CALL SYSPROC.ADMIN_UTL_SCHEDULE
                        (:maxparallel       :ind_maxparallel,
                         :optimizeworkload  :ind_optimizeworkload,
                         :stoponcond        :ind_stoponcond,
                         :utilityidstem     :ind_utilityidstem,
                         :shutdownduration  :ind_shutdownduration,
                         :numberofobjects   :ind_numberofobjects,
                         :utilitiesexec     :ind_utilitiesexec,
                         :highestretcd      :ind_highestretcd,
                         :paralleltasks     :ind_paralleltasks,
                         :retcd             :ind_retcd,
                         :errmsg            :ind_errmsg);

   /******************************************************************/
   /* Retrieve result set when the SQLCODE from the call is +446,    */
   /* which indicates that result sets were returned                 */
   /******************************************************************/
   if (SQLCODE == +466)               /* Result sets were returned   */
   {
     /* Establish a link between the result set and its locator      */
     EXEC SQL ASSOCIATE LOCATORS (:rs_loc1, :rs_loc2)
              WITH PROCEDURE SYSPROC.ADMIN_UTL_SCHEDULE;

     /* Associate a cursor with the first result set                 */
     EXEC SQL ALLOCATE C1 CURSOR FOR RESULT SET :rs_loc1;

     /* Associate a cursor with the second result set                */
     EXEC SQL ALLOCATE C2 CURSOR FOR RESULT SET :rs_loc2;

     /* Perform fetches using C1 to retrieve all rows from the       */
     /* first result set                                             */
     EXEC SQL FETCH C1 INTO :objectid1, :textseq, :text;
     while(SQLCODE==0)
     {
       EXEC SQL FETCH C1 INTO :objectid1, :textseq, :text;
     }

     EXEC SQL CLOSE C1;

     /* Perform fetches using C2 to retrieve all rows from the       */
     /* second result set                                            */
     EXEC SQL FETCH C2 INTO :objectid2, :utilretcd;
     while(SQLCODE==0)
     {
       EXEC SQL FETCH C2 INTO :objectid2, :utilretcd;
     }

     EXEC SQL CLOSE C2;
   }

   return(retcd);
 }

Output

This stored procedure returns the following output parameters, which are described in Option descriptions:

  • number-of-objects
  • utilities-run
  • highest-return-code
  • parallel-tasks
  • return-code
  • message

In addition to the preceding output, the stored procedure returns two results sets.

The first result set is returned in the created global temporary table SYSIBM.UTILITY_SYSPRINT and contains the output from the individual utility executions. The following table shows the format of the created global temporary table SYSIBM.UTILITY_SYSPRINT:

Table 3. Result set row for first ADMIN_UTL_SCHEDULE result set
Column name Data type Contents
OBJECTID INTEGER A unique positive identifier for the object the utility execution is associated with
TEXTSEQ INTEGER Sequence number of utility execution output statements for the object whose unique identifier is specified in the OBJECTID column
TEXT VARCHAR(254) A utility execution output statement

The second result set is returned in the created global temporary table SYSIBM.UTILITY_RETCODE and contains the return code for each of the individual DSNUTILU executions. The following table shows the format of the output created global temporary table SYSIBM.UTILITY_RETCODE:

Table 4. Result set row for second ADMIN_UTL_SCHEDULE result set
Column name Data type Contents
OBJECTID INTEGER A unique positive identifier for the object the utility execution is associated with
RETCODE INTEGER Return code from DSNUTILU for this utility execution

End general-use programming interface information.