ADD_QUERY_THRESHOLD procedure
The ADD_QUERY_THRESHOLD procedure defines a new threshold to be used by the Query Supervisor. Adding a threshold only affects subsequently executed queries. Queries that are currently running continue to use the thresholds that were in effect when the query execution was initiated. The Query Supervisor only supervises user jobs. It does not affect system jobs or queries run by the operating system. The thresholds only apply to resources used by the SQL Query Engine (SQE).
Query Supervisor thresholds can include using job name, user name, and subsystem filters. The filters are combined to restrict the set of jobs for the rule. For jobs that meet the filtering criteria, when the threshold is met or exceeded, any exit programs registered with the QIBM_QQQ_QRY_SUPER exit point are called. An exit program can be used to implement actions such as query logging or real-time notification. It can also direct SQE to terminate the query. The exit program interface is described here: Query Supervisor Exit Program.
When the first threshold is defined for a system, any active jobs, including the job that runs the initial ADD_QUERY_THRESHOLD, will not be affected by Query Supervisor thresholds.
Authorization: The caller must have *JOBCTL special authority or be authorized to the QIBM_DB_SQLADM function usage ID.
The schema is QSYS2.
- threshold-name
- A character or graphic string that provides a name for the threshold. The name can be up to 30 characters long and can contain any characters including blanks. The name cannot be the same as an existing threshold name.
- threshold-type
- A character or graphic string that specifies the type of the threshold to be enforced.
- CPU TIME
- The total processing unit time used by the query, in seconds.
- ELAPSED TIME
- The total clock time, in seconds.
- TEMPORARY STORAGE
- The amount of storage, in megabytes (MB), that the query allocates.
- TOTAL IO COUNT
- The total number of I/O operations.
- threshold-value
- A big integer value that contains the threshold value, in units defined by the specified threshold-type. The value must be greater than 0.
- job-names
- A character or graphic string that specifies up to 100 job names separated by either a blank or a comma. Each job name can end with a wildcard character. For example, 'QPADEV*' indicates that any job name starting with the characters 'QPADEV' is a match.
- include-users
- A character or graphic string that specifies up to 100 user names separated by either a blank or a comma. A group profile does not expand to include all profiles that are members of the group. Each name can end with a wildcard character. For example, 'ADM*' indicates that any user name starting with the characters 'ADM' is a match.
- exclude-users
- A character or graphic string that specifies up to 100 user names separated by either a blank or a comma. A group profile does not expand to include all profiles that are members of the group. Each name can end with a wildcard character. For example, 'ADM*' indicates that any user name starting with the characters 'ADM' is a match.
- subsystems
- A character or graphic string that specifies up to 100 subsystem names separated by either a blank or a comma. Each name can end with a wildcard character. For example, 'RSBS*' indicates that any subsystem name starting with the characters 'RSBS' is a match.
- detection-frequency
- An integer value that specifies the minimum time, in seconds, between calls to exit programs registered with the QIBM_QQQ_QRY_SUPER exit point for this threshold for a specific thread. During the detection-frequency time interval following a threshold detection, the Query Supervisor does not process additional instances for this threshold in the same thread. Each time a query is run in a thread, a specific threshold can be processed at most once during the execution of that query.
- long-comment
- A character or graphic string that describes this Query Supervisor threshold. It can be up to 2000 characters long.
Examples
- Set a threshold value for total CPU time to 30 seconds for all jobs. When this value is reached,
any registered exit programs will be
called.
CALL QSYS2.ADD_QUERY_THRESHOLD(THRESHOLD_NAME => 'MAXTIME', THRESHOLD_TYPE => 'CPU TIME', THRESHOLD_VALUE => 30, LONG_COMMENT => 'Maximum runtime for all jobs');
- Set a threshold value for temporary storage to 10 megabytes for all jobs except for those
running with the BATCHRUN user profile. Set a detection frequency of 2 minutes. When the storage
threshold value is reached, any registered exit programs will be called. If the same thread reaches
this threshold for a different query within 2 minutes, the registered exit programs will not be
called.
CALL QSYS2.ADD_QUERY_THRESHOLD(THRESHOLD_NAME => 'Temp storage', THRESHOLD_TYPE => 'TEMPORARY STORAGE', THRESHOLD_VALUE => 10, EXCLUDE_USERS => 'BATCHRUN', DETECTION_FREQUENCY => 120);