程序包高速缓存语句逐出事件监视
程序包高速缓存事件监视器将捕获与已经从数据库程序包高速缓存中写入的语句条目相关的数据。此事件监视器提供了程序包高速缓存内容的历史记录,这有助于解决 SQL 查询性能和问题确定方面的问题。
概述
程序包高速缓存事件监视器将与 MON_GET_PKG_CACHE_STMT 表函数收集相同的信息,其中包括所有可用的活动指标以及条目的可执行节信息。
从 V10.1 开始,可获取与运行时间最长的语句相关的输入自变量的相关信息。此语句是与监视元素 max_coord_stmt_exec_time 相关联的语句。与此语句相关联的输入自变量记录在 pkgcache_stmt_args 逻辑数据组中。
- 使用 WHERE 子句并根据下面的一个或多个条件来过滤条目:
- 最近一次更新某个条目的指标是否是在移除该条目之前的特定时间之后进行的 (UPDATED_SINCE_BOUNDARY_TIME)。仅当最近一次更新指标的时间晚于为事件监视器定义的边界时间时,才会收集该条目。可以使用 MON_GET_PKG_CACHE_STMT 表函数来设置事件监视器的边界时间。如果尚未对事件监视器设置边界时间,那么 UPDATED_SINCE_BOUNDARY_TIME 子句将不起作用。
- 执行某个条目的节的次数 (NUM_EXECUTIONS)
- 执行语句所耗用的总时间 (STMT_EXEC_TIME)
- COLLECT DATA 子句选项:
- COLLECT BASE DATA
与 MON_GET_PKG_CACHE_STMT 表函数收集相同的信息,以及所有可用的活动指标
- COLLECT DETAILED DATA
收集的信息与使用 COLLECT BASE DATA 子句收集的信息相同,并且还包括条目的可执行节
- COLLECT BASE DATA
当您需要调查 SQL 语句某一次的执行情况时,如果条目仍然存在于程序包高速缓存中,那么可以使用 MON_GET_PKG_CACHE_STMT 表函数来比较已高速缓存的条目相对于其他条目的行为。可将已高速缓存的条目的执行指标、编译环境和详细描述用于进行诊断。
如果已经从程序包高速缓存中写入条目,那么可以使用程序包高速缓存事件监视器来查看那些已经从程序包高速缓存中写入的已高速缓存条目的历史记录。历史记录数据中包含的信息与 MON_GET_PKG_CACHE_STMT 表函数所提供的信息相同。此外,此事件监视器还提供了该语句的可执行节。这全部都适用于动态和静态 SQL 语句。
创建程序包高速缓存事件监视器
要创建程序包高速缓存事件监视器并收集程序包高速缓存事件监视数据,您必须具有 DBADM 或 SQLADM 权限。
程序包高速缓存事件监视器可将其输出写至常规表或无格式事件表。
在创建程序包高速缓存事件监视器之前,请标识要在其中存储事件监视器的输出的表空间。如果您未指定,那么 CREATE EVENT MONITOR 语句将使用缺省表空间。但是,建议的做法是,配置专用表空间来存储与任何事件监视器相关联的输出表。如果要使用无格式事件表,请在页大小至少为 8K 的表空间中创建程序包高速缓存事件监视器,以确保事件数据包含在 UE 表的直接插入 BLOB 列中。如果不直接插入 BLOB 列,那么对无格式事件表读写事件的效率可能不高。
- 通过发出 CREATE EVENT MONITOR 语句来创建事件监视器。以下示例将尽可能使用缺省值,并且指定将无格式事件表存储在现有表空间 MY_EVMON_TABLESPACE 中:
CREATE EVENT MONITOR MY_PKGCACHE_EVMON FOR PACKAGE CACHE WRITE TO UNFORMATTED EVENT TABLE (IN MY_EVMON_TABLESPACE)
Enabling data collection
To enable data collection, you must activate the event monitor using the SET EVENT MONITOR STATE statement. The package cache event monitor is not a passive event monitor; following activation, it automatically starts collecting data whenever a statement is flushed from the package cache and meets the filter criteria set at the time of creation of the package cache event monitor.
Accessing event data captured by a package cache event monitor
工作单元事件监视器可将数据写至常规表,也可将二进制格式的数据写至无格式事件 (UE) 表。可使用 SQL 来访问常规表中的数据。
- EVMON_FORMAT_UE_TO_XML
- 将无格式事件表中的数据抽取到 XML 文档中。
- EVMON_FORMAT_UE_TO_TABLES
- 将无格式事件表中的数据抽取到一组关系表中。
The schema file ~/sqllib/misc/DB2EvmonPkgCache.xsd is used to document the expected output of the package cache event monitor report in an XML document. The schema file will reference a common monitor schema file (DB2MonCommon.xsd) to avoid duplicating the common contents.
An XML stylesheet is provided in ~/sqllib/samples/jdbc/DB2EvmonPkgCache.xsl.
Use these table functions to specify the data to extract using a SELECT statement. You have full control over selection, ordering, and other aspects provided by the SELECT statement.
- Select events of interest based on the following attributes: executable ID, section type, query cost estimate, statement package cache ID, and flush time.
- Choose whether to receive the output in the form of a text report or a formatted XML document.
- Control the output format by creating your own XSLT style sheets instead of using the ones provided by the db2evmonfmt command.
- Selects package cache events that have occurred in the past 24 hours in the database SAMPLE. These event records are obtained from the unformatted event table called SAMPLE_PKGCACHE_EVENTS.
- Provides formatted text output using the DB2EvmonPkgCache.xsl style sheet.
java db2evmonfmt -d SAMPLE -ue SAMPLE_PKGCACHE_EVENTS -ftext -ss DB2EvmonPkgCache.xsl -hours 24