The MON_GET_PKG_CACHE_STMT table function returns a point-in-time view of both static and dynamic SQL statements in the database package cache.
>>-MON_GET_PKG_CACHE_STMT--(--section_type--,-------------------> >--executable_id--,--search_args--,--member--)-----------------><
The schema is SYSPROC.
'<modified_within>5</modified_within><update_boundary_time>myPkgEvmon
</update_boundary_time>'
Returns only those statement entries that have either been inserted into the cache or executed within the last X minutes (where X is a positive integer value). If the argument is not specified, all entries in the cache are returned.
Updates the event monitor boundary timestamp to the current time for the package cache event monitor specified by evmon_name. If this event monitor specifies where updated_since_boundary_time as an output criteria in its WHERE clause, only package cache entries that subsequently have their metrics updated are captured when evicted from the package cache. This operation only has an effect if the specified package cache event monitor is active when the command is issued.
Each input argument can be specified only once. The search argument tags must be specified in lowercase.
EXECUTE privilege on the MON_GET_PKG_CACHE_STMT function.
List all the dynamic SQL statements from the database package cache ordered by the average CPU time.
db2 SELECT MEMBER,
SECTION_TYPE ,
TOTAL_CPU_TIME/NUM_EXEC_WITH_METRICS as
AVG_CPU_TIME,EXECUTABLE_ID
FROM TABLE(MON_GET_PKG_CACHE_STMT ( 'D', NULL, NULL, -2)) as T
WHERE T.NUM_EXEC_WITH_METRICS <> 0 ORDER BY AVG_CPU_TIME
The following example is a sample output from this query.
MEMBER SECTION_TYPE AVG_CPU_TIME EXECUTABLE_ID
------ ------------ -------------------- -------------------------------------------------------------------
0 D 754 x'01000000000000007A0000000000000000000000020020081126171554951791'
0 D 2964 x'0100000000000000790000000000000000000000020020081126171533551120'
0 D 5664 x'01000000000000007C0000000000000000000000020020081126171720728997'
0 D 5723 x'01000000000000007B0000000000000000000000020020081126171657272914'
0 D 9762 x'01000000000000007D0000000000000000000000020020081126172409987719'
5 record(s) selected.
db2 SELECT STMT_TEXT FROM TABLE(MON_GET_PKG_CACHE_STMT
(null, x'01000000000000007D0000000000000000000000020020081126172409987719', null, -2))
STMT_TEXT
-------------------------------------------------------------------------------------------
SELECT * FROM EMPLOYEE
SELECT count(*) FROM syscat.tables
all
metrics are returned as 0 and the value of num_exec_with_metrics is
also 0. Then Alex executes the same statement afterwards, but the
metrics are collected this time for the execution of the statement
and num_exec_with_metrics increments. So, after
Brent and Alex execute that statement, the result of this query:SELECT num_executions, num_exec_with_metrics, SUBSTR(stmt_text,1,50) AS stmt_text
FROM TABLE (MON_GET_PKG_CACHE_STMT('d', null, null, -1)) AS tf
WHERE stmt_text LIKE 'SELECT count%'
shows that the
SELECT statement ran twice and one of the execution times had the
activity metrics collected. NUM_EXECUTIONS NUM_EXEC_WITH_METRICS STMT_TEXT
-------------- --------------------- --------------------
2 1 SELECT count(*) FROM syscat.tables
1 record(s) selected.
The MON_GET_PKG_CACHE_STMT table function returns a point-in-time view of both static and dynamic SQL statements in the database package cache. This allows you to examine the aggregated metrics for a particular SQL statement, allowing you to quickly determine the reasons for poor query performance. The metrics returned are aggregates of the metrics gathered during each execution of the statement.
It also allows you to compare the behavior of an individual cached section, relative to the other statements, to assist in identifying the most expensive section or statements (in terms of the execution costs).
The activity metrics reported by this function are rolled up to the global package cache at the end of the execution of the activity.
Metrics collection for the execution of any statement is controlled through the COLLECT ACTIVITY METRICS clause on workloads, or the mon_act_metrics database configuration parameter at the database level. Metrics are only collected for executions of the statement if the statement was submitted by a connection associated with a workload or database for which activity metrics are enabled. The num_exec_with_metrics element returned by the MON_GET_PKG_CACHE_STMT function indicates how many executions of the statement have had metrics collected and have contributed to the aggregate metrics reported. If no metrics are collected for any execution of the statement, then the num_exec_with_metrics element is 0 and all metric values are returned as 0.