DB2 Version 9.7 for Linux, UNIX, and Windows

MON_GET_PKG_CACHE_STMT_DETAILS - get detailed metrics for package cache entries

The MON_GET_PKG_CACHE_STMT_DETAILS table function returns detailed metrics for one or more package cache entries.

Note: If your database was created in Version 9.7 before Fix Pack 1, to run this routine you must have already run the db2updv97 command. If your database was created before Version 9.7, it is not necessary to run the db2updv97 command (because the catalog update is automatically taken care of by the database migration). If you downgrade to Version 9.7, this routine will no longer work.

The metrics returned by the MON_GET_PKG_CACHE_STMT_DETAILS table function represent the accumulation of all metrics for statements in the package cache. Statement metrics are rolled up to the package cache upon activity completion.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-MON_GET_PKG_CACHE_STMT_DETAILS--(--section_type--,----------->

>--executable_id--,--search_args--,--member--)-----------------><

The schema is SYSPROC.

Table function parameters

section_type
An optional input argument (either "D" or "S") of type CHAR(1) that specifies information type for the returned statement. If the argument is NULL or an empty string, information is returned for all SQL statements. Not case sensitive: D stands for dynamic; S for static.
executable_id
An optional input argument of type VARCHAR (32) for bit data that specifies a unique section of the database package cache. If a null value is specified, information is returned for all SQL statements. When the executable_id is specified, the section_type argument is ignored. For example, if an executable_id is specified for a dynamic statement, the dynamic statement details will be returned by this table function even if section_type is specified as static ("S").
search_args
An optional input parameter of type CLOB(1K), that allows you to specify one or more optional search argument strings. For example:
'<modified_within>5</modified_within><update_boundary_time>myPkgEvmon
     </update_boundary_time>'
The available search argument tags are as follows:
  • '<modified_within>X</modified_within>'

    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.

  • '<update_boundary_time>evmon_name</update_boundary_time>'

    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.

  • '<stmt_details>true</stmt_details>' or '<stmt_details>false</stmt_details>'

    Includes or excludes the stmt_text and comp_env_desc data in the resulting XML document. This allows you to exclude these relatively large portions of the document when you do not need them (for example, if you are using the XML document to provide input for the MON_FORMAT_XML_* table functions that return formatted row-based output). If this argument tag is not specified, the stmt_text and comp_env_desc data are included by default.

Each input argument can be specified only once. The search argument tags must be specified in lowercase.

member
An optional input argument of type INTEGER that specifies a valid member in the same instance as the currently connected database when calling this function. Specify -1 for the current database member, or -2 for all database members. If the null value is specified, -1 is set.

Authorization

EXECUTE privilege on the MON_GET_PKG_CACHE_STMT_DETAILS function.

Examples

The first example demonstrates how to examine the package cache and select the 10 statements that have read and returned the largest number of rows. Additionally, the results show the cumulative amount of time spent executing each of these statements (in the STMT_EXEC_TIME output column).

SELECT SUBSTR(DETMETRICS.STMT_TEXT, 1, 40) STMT_TEXT,
       DETMETRICS.ROWS_RETURNED, 
       DETMETRICS.STMT_EXEC_TIME   
FROM TABLE(MON_GET_PKG_CACHE_STMT_DETAILS(CAST(NULL AS CHAR(1)),
    CAST(NULL AS VARCHAR(32) FOR BIT DATA), 
    CAST(NULL AS CLOB(1K)), -1)) AS STMT_METRICS,
    XMLTABLE (XMLNAMESPACES( DEFAULT 'http://www.ibm.com/xmlns/prod/db2/mon'),
       '$DETMETRICS/db2_pkg_cache_stmt_details' PASSING 
    XMLPARSE(DOCUMENT STMT_METRICS.DETAILS) as "DETMETRICS"
    COLUMNS "STMT_TEXT" CLOB PATH 'stmt_text', 
        "ROWS_RETURNED" BIGINT PATH 'activity_metrics/rows_returned',
        "STMT_EXEC_TIME" BIGINT PATH 'activity_metrics/stmt_exec_time'
    ) AS DETMETRICS
ORDER BY rows_returned DESC
FETCH FIRST 10 ROWS ONLY

The following example is a sample output from this query.

STMT_TEXT                                ROWS_RETURNED STMT_EXEC_TIME
---------------------------------------- ------------- --------------
SELECT CREATOR, NAME, CTIME FROM SYSIBM.           134            38
SELECT SUBSTR(DETMETRICS.STMT_TEXT, 1, 4            44           336
SELECT SUBSTR(DETMETRICS.STMT_TEXT, 1, 4            10           333
SELECT COLNAME, TYPENAME FROM  SYSCAT.CO            10             6
SELECT SUBSTR(DETMETRICS.STMT_TEXT, 1, 4            10           334
SELECT TRIGNAME FROM  SYSCAT.TRIGGERS WH             8             1
SELECT COUNT(*) FROM SYSCAT.TABLESPACES              2             0
SELECT POLICY FROM SYSTOOLS.POLICY WHERE             1             0
CALL SYSPROC.POLICY_INSTALL ('I','DB2Tab             1            62
CALL SYSPROC.POLICY_INSTALL ('I','DB2Tab             1            64

  10 record(s) selected.

The second example shows, for dynamic SQL statements that have waited on a lock while executing, the number of executions, number of lock waits and average time spent per lock wait. The output shows values accumulated over the lifetime of the package cache entries, but restricts information to statements that have executed within the last minute (by setting the modified_within argument tag to 1). The query excludes the statement details (stmt_text and comp_env_desc data) because they are not required and they are computationally expensive to report (by setting the stmt_details argument tag to false).

SELECT NUM_EXEC_WITH_METRICS, LOCK_WAITS, 
  (LOCK_WAIT_TIME / LOCK_WAITS) AVG_LOCK_WAIT_TIME
FROM TABLE(MON_GET_PKG_CACHE_STMT_DETAILS('D', CAST(NULL
   AS VARCHAR(32) FOR BIT DATA), 
   CLOB(
      '<modified_within>1</modified_within><stmt_details>false</stmt_details>')
        , -1))
   AS STMT_METRICS, 
   XMLTABLE (XMLNAMESPACES( DEFAULT 'http://www.ibm.com/xmlns/prod/db2/mon'),
      '$DETMETRICS/db2_pkg_cache_stmt_details' PASSING 
   XMLPARSE(DOCUMENT STMT_METRICS.DETAILS) as "DETMETRICS" 
   COLUMNS "NUM_EXEC_WITH_METRICS" BIGINT PATH 'num_exec_with_metrics',
      "LOCK_WAITS" BIGINT PATH 'lock_waits',          
      "LOCK_WAIT_TIME" BIGINT PATH 'activity_metrics/lock_wait_time'
   ) AS DETMETRICS 
WHERE LOCK_WAITS <> 0 
ORDER BY AVG_LOCK_WAIT_TIME DESC

The following example is a sample output from this query.

NUM_EXEC_WITH_METRICS LOCK_WAITS           AVG_LOCK_WAIT_TIME       
--------------------- -------------------- --------------------
                    4                    2                  139
                    9                    3                   90

Usage notes

The metrics returned by this function represent the accumulation of all metrics for statements in the package cache. Statement metrics are rolled up to the package cache upon activity completion.

The schema for the XML document that is returned in the DETAILS column is available in the file sqllib/misc/DB2MonRoutines.xsd. Further details can be found in the file sqllib/misc/DB2MonCommon.xsd.

Information returned

Table 1. Information returned for MON_GET_PKG_CACHE_STMT_DETAILS
Column Name Data Type Description or corresponding monitor element
MEMBER SMALLINT member- Database member
SECTION_TYPE CHAR(1) section_type - Section type indicator.
EXECUTABLE_ID VARCHAR(32) FOR BIT DATA executable_id - Executable ID.
DETAILS BLOB(8M) XML document containing detailed metrics for the unit of work. See Table 2 for a description of the elements in this document.
Table 2. Detailed metrics returned for MON_GET_PKG_CACHE_STMT_DETAILS
Element Name Data Type Description
member xs:short member- Database member
valid xs:string(1) valid - Section validity indicator
executable_id xs:hexBinary(32) executable_id - Executable ID.
section_type xs:string(1) section_type - Section type indicator.
num_executions xs:nonNegativeInteger num_executions - Statement executions
num_exec_with_metrics xs:nonNegativeInteger num_exec_with_metrics - Number of executions with metrics collected.
prep_time xs:nonNegativeInteger prep_time - Preparation time Note that PREP_TIME is only valid for dynamic SQL statements. PREP_TIME is reported as 0 for static SQL statements.
effective_isolation xs:string(2) effective_isolation - Effective isolation. This is the isolation value in effect for the section; it can be different from what it was originally requested at compilation time.
stmt_pkg_cache_id xs:long stmt_pkgcache_id - Statement package cache identifier
query_cost_estimate xs:long query_cost_estimate - Query cost estimate
stmt_type_id xs:string stmt_type_id - Statement type identifier
insert_timestamp xs:dateTime insert_timestamp - Statement insert timestamp
last_metrics_update xs:dateTime last_metrics_update - Metrics last update timestamp
package_name xs:string(128) package_name - Package name . This output is valid for static SQL statements only. A NULL value is returned if the statement is dynamic.
package_schema xs:string(128) package_schema - Package schema . This output is valid for static SQL statements only. A NULL value is returned if the statement is dynamic.
package_version_id xs:string(64) package_version_id - Package version. This output is valid for static SQL statements only. This element is not produced if the statement is dynamic or if you did not specify the package version for static statement. If you did not specify the package version identifier when the package was created, an empty string is returned for a static statement.
section_number xs:short section_number - Section number. This element is not produced if the statement is dynamic.
stmt_text xs:string(2097152) stmt_text - SQL statement text
comp_env_desc xs:hexBinary(10240) comp_env_desc - Compilation environment handle. You can use the existing COMPILATION_ENV table function to get the detailed compilation environment of the specific statement if needed.
wlm_queue_time_total xs:long wlm_queue_time_total - Workload manager total queue time
wlm_queue_assignments_total xs:long wlm_queue_assignments_total - Workload manager total queue assignments
fcm_tq_recv_wait_time xs:long fcm_tq_recv_wait_time - FCM tablequeue recv wait time
fcm_message_recv_wait_time xs:long fcm_message_recv_wait_time - FCM message recv wait time
fcm_tq_send_wait_time xs:long fcm_tq_send_wait_time - FCM tablequeue send wait time
fcm_message_send_wait_time xs:long fcm_message_send_wait_time - FCM message send wait time
lock_wait_time xs:long lock_wait_time - Time waited on locks
lock_waits xs:long lock_waits - Lock waits
direct_read_time xs:long direct_read_time - Direct read time
direct_read_reqs xs:long direct_read_reqs - Direct read requests
direct_write_time xs:long direct_write_time - Direct write time
direct_write_reqs xs:long direct_write_reqs - Direct write requests
log_buffer_wait_time xs:long log_buffer_wait_time - Log buffer wait time
num_log_buffer_full xs:long num_log_buffer_full - Number of full log buffers
log_disk_wait_time xs:long log_disk_wait_time - Log disk wait time
log_disk_waits_total xs:long log_disk_waits_total - Log disk waits total
pool_write_time xs:long pool_write_time - Total buffer pool physical write time
pool_read_time xs:long pool_read_time - Total buffer pool physical read time
audit_file_write_wait_time xs:long audit_file_write_wait_time - Audit file write wait time
audit_file_writes_total xs:long audit_file_writes_total - Total Audit files written
audit_subsystem_wait_time xs:long audit_subsystem_wait_time - Audit subsystem wait time
audit_subsystem_waits_total xs:long audit_subsystem_waits_total - Total audit subsystem waits
diaglog_write_wait_time xs:long diaglog_write_wait_time - Diag log write time
diaglog_writes_total xs:long diaglog_writes_total - Diag log total writes
fcm_send_wait_time xs:long fcm_send_wait_time - FCM send wait time
fcm_recv_wait_time xs:long fcm_recv_wait_time - FCM recv wait time
total_act_wait_time xs:long total_act_wait_time - Total activity wait time
total_section_sort_proc_time xs:long total_section_sort_proc_time - Total section sort processing time
total_section_sort_time xs:long total_section_sort_time - Total section sort time
total_section_sorts xs:long total_section_sorts - Total section sorts
total_act_time xs:long total_act_time - Total activity time
rows_read xs:long rows_read - Rows read
rows_modified xs:long rows_modified - Rows modified
pool_data_l_reads xs:long pool_data_l_reads - Buffer pool data logical reads
pool_index_l_reads xs:long pool_index_l_reads - Buffer pool index logical reads
pool_temp_data_l_reads xs:long pool_temp_data_l_reads - Buffer pool temporary data logical reads
pool_temp_index_l_reads xs:long pool_temp_index_l_reads - Buffer pool temporary index logical reads
total_cpu_time xs:long total_cpu_time - Total CPU time
pool_data_p_reads xs:long pool_data_p_reads - Buffer pool data physical reads
pool_temp_data_p_reads xs:long pool_temp_data_p_reads - Buffer pool temporary data physical reads
pool_xda_p_reads xs:long pool_xda_p_reads - Buffer pool XDA data physical reads
pool_temp_xda_p_reads xs:long pool_temp_xda_p_reads - Buffer pool temporary XDA data physical reads
pool_index_p_reads xs:long pool_index_p_reads - Buffer pool index physical reads
pool_temp_index_p_reads xs:long pool_temp_index_p_reads - Buffer pool temporary index physical reads
pool_data_writes xs:long pool_data_writes - Buffer pool data writes
pool_xda_writes xs:long pool_xda_writes - Buffer pool XDA data writes
pool_index_writes xs:long pool_index_writes - Buffer pool index writes
direct_reads xs:long direct_reads - Direct reads from database
direct_writes xs:long direct_writes - Direct writes to database
rows_returned xs:long rows_returned - Rows returned
deadlocks xs:long deadlocks - Deadlocks detected
lock_timeouts xs:long lock_timeouts - Number of lock timeouts
lock_escals xs:long lock_escals - Number of lock escalations
fcm_sends_total xs:long fcm_sends_total - FCM sends total
fcm_recvs_total xs:long fcm_recvs_total - FCM recvs total
fcm_send_volume xs:long fcm_send_volume - FCM send volume
fcm_recv_volume xs:long fcm_recv_volume - FCM recv volume
fcm_message_sends_total xs:long fcm_message_sends_total - FCM message sends total
fcm_message_recvs_total xs:long fcm_message_recvs_total - FCM message recvs total
fcm_message_send_volume xs:long fcm_message_send_volume - FCM message send volume
fcm_message_recv_volume xs:long fcm_message_recv_volume - FCM message recv volume
fcm_tq_sends_total xs:long fcm_tq_sends_total - FCM tablequeue send total
fcm_tq_recvs_total xs:long fcm_tq_recvs_total - FCM tablequeue recvs total
fcm_tq_send_volume xs:long fcm_tq_send_volume - FCM tablequeue send volume
fcm_tq_recv_volume xs:long fcm_tq_recv_volume - FCM tablequeue recv volume
tq_tot_send_spills xs:long tq_tot_send_spills - Total number of table queue buffers overflowed
post_threshold_sorts xs:long post_threshold_sorts - Post threshold sorts
post_shrthreshold_sorts xs:long post_shrthreshold_sorts - Post shared threshold sorts
sort_overflows xs:long sort_overflows - Sort overflows
audit_events_total xs:long audit_events_total - Total audit events
total_sorts xs:long total_sorts - Total Sorts
stmt_exec_time xs:long stmt_exec_time - Statement execution time
coord_stmt_exec_time xs:long coord_stmt_exec_time - Execution time for statement by coordinator agent

total_routine_non_
   sect_proc_time

xs:long total_routine_non_sect_proc_time - Non-section processing time
total_routine_non_sect_time xs:long total_routine_non_sect_time - Non-section routine execution time
total_section_proc_time xs:long total_section_proc_time - Total section processing time
total_section_time xs:long total_section_time - Total section time
total_app_section_executions xs:long total_app_section_executions - Total section executions

total_routine_user_
  code_proc_time

xs:long total_routine_user_code_proc_time - Total routine user code processing time
total_routine_user_code_time xs:long total_routine_user_code_time - Total routine user code time
total_routine_time xs:long total_routine_time - Total routine time
num_coord_exec xs:long num_coord_exec - Number of executions by coordinator agent
num_coord_exec_with_metrics xs:long num_coord_exec_with_metrics - Number of executions by coordinator agent with metrics
thresh_violations xs:long thresh_violations - Number of threshold violations
num_lw_thresh_exceeded xs:long num_lw_thresh_exceeded - Number of thresholds exceeded
total_routine_invocations xs:long total_routine_invocations - Total routine invocations
ida_send_wait_time xs:nonNegativeInteger ida_send_wait_time - Time spent waiting to send data
ida_sends_total xs:nonNegativeInteger ida_sends_total - Number of times data sent
ida_send_volume xs:nonNegativeInteger ida_send_volume - Total data volume sent
ida_recv_volume xs:nonNegativeInteger ida_recv_volume - Total data volume received
ida_recv_wait_time xs:nonNegativeInteger ida_recv_wait_time - Time spent waiting to receive data
ida_recvs_total xs:nonNegativeInteger ida_recvs_total - Number of times data received