DB2 快照表Snapshot

本文介绍了如何使用DB2的Snapshot功能来监视数据库的各种活动,包括DBM、FCM、应用程序、锁等待、SQL语句等信息的快照捕获。提供了SQL表函数和命令行示例,帮助用户深入了解数据库的状态和性能。

snapshot用于监视数据库对象活动快照信息。在命令中可以指明要扑捉快照的级别和数据库对象

一.Snapshot Monitor SQL Table Function
-- 查看DBM的监视器快照
SELECT * FROM TABLE( SNAPSHOT_DBM(-1)) as SNAPSHOT_DBM
--To capture a snapshot of database manager information specifically regarding the fast communication manager (FCM):
SELECT * FROM TABLE( SNAPSHOT_FCM(-1)) as SNAPSHOT_FCM
--To capture a snapshot of database manager information for a partition specifically regarding the fast communication manager(FCM):
SELECT * FROM TABLE( SNAPSHOT_FCMPARTITION(-1)) as SNAPSHOT_FCMPARTITION
--To capture the database manager's monitor switch settings:
SELECT * FROM TABLE( SNAPSHOT_SWITCHES(-1)) as SNAPSHOT_SWITCHES
--查看数据库的监视器快照(rows_read,total_log_used)
SELECT TOTAL_LOG_USED,TOTAL_LOG_AVAILABLE,ROWS_READ FROM TABLE( SNAPSHOT_DATABASE( 'ADB', -1 )) as SNAPSHOT_DATABASE ---TOTAL_LOG_USED,TOTAL_LOG_AVAILABLE,ROWS_READ
--查看数据库应用程序的监视器快照
SELECT * FROM TABLE( SNAPSHOT_APPL( 'SAMPLE', -1 )) as SNAPSHOT_APPL --ROWS_READ,ROWS_SELECTED
--查看数据库应用程序详细信息的监视器快照
SELECT * FROM TABLE( SNAPSHOT_APPL_INFO( 'SAMPLE', -1 )) as SNAPSHOT_APPL_INFO
--查询锁等待信息
SELECT * FROM TABLE( SNAPSHOT_LOCKWAIT('SAMPLE', -1 )) as SNAPSHOT_LOCKWAIT
--查询数据库执行的SQL语句
SELECT * FROM TABLE( SNAPSHOT_STATEMENT( 'SAMPLE', -1 )) as SNAPSHOT_STATEMENT
--查询数据库代理程序信息
SELECT * FROM TABLE( SNAPSHOT_AGENT( 'SAMPLE', -1 )) as SNAPSHOT_AGENT
--查询数据库子查询的快照
SELECT * FROM TABLE( SNAPSHOT_SUBSECT( 'SAMPLE', -1 )) as SNAPSHOT_SUBSECT
--查询缓冲池的监控快照
SELECT * FROM TABLE( SNAPSHOT_BP( 'SAMPLE', -1 )) as SNAPSHOT_BP
--查询表空间的监控快照
SELECT * FROM TABLE( SNAPSHOT_TBS( 'SAMPLE', -1 )) as SNAPSHOT_TBS
--查询表空间的配置信息快照
SELECT * FROM TABLE( SNAPSHOT_TBS_CFG( 'SAMPLE', -1 )) as SNAPSHOT_TBS_CFG
--查询表空间的使用情况
SELECT tablespace_id,tablespace_name,tablespace_type,sum(total_pages) as total_pages ,sum(usable_pages) as usable_pages,sum(used_pages) as used_pages FROM TABLE( SNAPSHOT_TBS_CFG( 'SAMPLE', -1 )) as SNAPSHOT_TBS_CFG GROUP BY tablespace_id,tablespace_name,tablespace_type
--表空间的使用情况视图
select tbsp_name,tbsp_total_size_kb,tbsp_usable_size_kb,tbsp_used_size_kb,tbsp_free_size_kb, tbsp_utilization_percent from sysibmadm.TBSP_UTILIZATION
--To capture a snapshot of table space quiescer information:
SELECT * FROM TABLE( SNAPSHOT_QUIESCER( 'SAMPLE', -1 )) as SNAPSHOT_QUIESCER
--查询表空间的监控器容器信息
SELECT * FROM TABLE( SNAPSHOT_CONTAINER( 'SAMPLE', -1 )) as SNAPSHOT_CONTAINER
--查看表空间的范围
SELECT * FROM TABLE( SNAPSHOT_RANGES( 'SAMPLE', -1 )) as SNAPSHOT_RANGES
--Table: To capture a snapshot of table information:
--查看数据库的锁信息
SELECT * FROM TABLE( SNAPSHOT_APPL_INFO( 'SAMPLE', -1 )) as SNAPSHOT_APPL_INFO


二.The Snapshot Monitor
db2 "get snapshot for dynamic sql on sample" > sql_info.txt
--Dynamic SQL cache: To capture a snapshot of dynamic SQL statement cache information:Snapshot monitor 24 System Monitor Guide and Reference
Snapshot on database manager (instance)
GET SNAPSHOT FOR DBM
Snapshot on database
GET SNAPSHOT FOR DB ON SAMPLE
查询某一db2 进程的快照信息
db2 get snapshot for application agentid 55531
查询某一db2进程的锁信息
db2 get snapshot for locks for application agentid 48551
Snapshot for bufferpools
GET SNAPSHOT FOR bufferpools ON SAMPLE
Snapshot for tables
GET SNAPSHOT FOR tables ON SAMPLE
Snapshot for locks
GET SNAPSHOT FOR locks ON SAMPLE
Snapshot for dynamic sql
GET SNAPSHOT FOR dynamic sql ON SAMPLE
Snapshot for all
GET SNAPSHOT FOR all ON SAMPLE


三.The Snapshot VIEWS
--Connected database applications
SELECT * FROM SYSIBMADM.APPLICATIONS
--information about rate of rows selected versus rows read application
SELECT * FROM SYSIBMADM.APPL_PERFORMANCE
--buffer pool hit ratios,including total,data,and index
select * from SYSIBMADM.BP_HITRATIO
--buffer pool read performance information
select * from SYSIBMADM.BP_READ_IO
--contains buffer pool write performance information
select * from SYSIBMADM.BP_WRITE_IO
--information about table space containers and utilization rates
select * from SYSIBMADM.CONTAINER_UTILIZATION
--information on locks that are waiting to granted
select * from SYSIBMADM.LOCKWAITS
--The LOG_UTILIZATION administrative view returns information about log utilization for the currently connected database
db2 => select * from SYSIBMADM.LOG_UTILIZATION                                                                       
                                                                                                                     
DB_NAME   LOG_UTILIZATION_PERCENT TOTAL_LOG_USED_KB    TOTAL_LOG_AVAILABLE_KB TOTAL_LOG_USED_TOP_KB DBPARTITIONNUM   
--------- ----------------------- -------------------- ---------------------- --------------------- --------------   
SB1DM                        0.21                 8619                3975755                  8757              0   
 
  1 record(s) selected.                                                                                                                  
TOTAL_LOG_AVAILABLE_KB=(LOGPRIMARY+LOGSECOND)*LOGFILSIZ*(Log file size)-TOTAL_LOG_USED_KB
for example:
 Log file size (4KB)                         (LOGFILSIZ) = 10000
 Number of primary log files                (LOGPRIMARY) = 25
 Number of secondary log files               (LOGSECOND) = 75
TOTAL_LOG_AVAILABLE_KB=(75+25)*10000*4=4000000-8619=3991381
--The LOCKWAITS administrative view returns information about DB2® agents working on behalf of applications that are waiting to obtain locks.
select * from SYSIBMADM.LOCKWAITS
--The LONG_RUNNING_SQL administrative view returns the longest running SQL statements in the currently connected database.
select * from SYSIBMADM.LONG_RUNNING_SQL
--The QUERY_PREP_COST administrative view returns a list of statements with information about the time required to prepare the statement.
select * from SYSIBMADM.QUERY_PREP_COST
--This administrative view allows you to retrieve agent logical data group application snapshot information for the currently connected database
select * from SYSIBMADM.SNAPAGENT
--retrieve the memory_pool logical data group snapshot information about memory usage at the agent level for the currently connected database.
select * from SYSIBMADM.SNAPAGENT_MEMORY_POOL
--retrieve appl_info logical data group snapshot information for the currently connected database
select * from SYSIBMADM.SNAPAPPL_INFO
--retrieve bufferpool logical group snapshot information for the currently connected database
select * from SYSIBMADM.SNAPBP
select * from SYSIBMADM.SNAPBP_PART
--retrieve tablespace_container logical data group snapshot information for the currently connected database.
select * from SYSIBMADM.SNAPCONTAINER
--retrieve snapshot information from the dbase logical group for the currently connected database
select * from SYSIBMADM.SNAPDB
--retrieve database level memory usage information for the currently connected database
select * from SYSIBMADM.SNAPDB_MEMORY_POOL
select * from SYSIBMADM.SNAPDBM
select * from SYSIBMADM.SNAPDBM_MEMORY_POOL
select * from SYSIBMADM.SNAPDETAILLOG
select * from SYSIBMADM.SNAPDYN_SQL
select * from SYSIBMADM.SNAPFCM
select * from SYSIBMADM.SNAPFCM_PART
select * from SYSIBMADM.SNAPHADR
select * from SYSIBMADM.SNAPLOCK
SELECT AGENT_ID, LOCK_OBJECT_TYPE, LOCK_MODE, LOCK_STATUS FROM SYSIBMADM.SNAPLOCK
select * from SYSIBMADM.SNAPLOCKWAIT
select * from SYSIBMADM.SNAPSTMT
select * from SYSIBMADM.SNAPSTORAGE_PATHS
select * from SYSIBMADM.SNAPSUBSECTION
select * from SYSIBMADM.SNAPSWITCHES
select * from SYSIBMADM.SNAPTAB
select * from SYSIBMADM.SNAPTAB_REORG
select * from SYSIBMADM.SNAPTBSP
select * from SYSIBMADM.SNAPTBSP_PART
select * from SYSIBMADM.SNAPTBSP_QUIESCER
select * from SYSIBMADM.SNAPTBSP_RANGE
select * from SYSIBMADM.SNAPUTIL
select * from SYSIBMADM.SNAPUTIL_PROGRESS
--returns table space configuration and utilization information
select * from SYSIBMADM.TBSP_UTILIZATION
select tbsp_name,tbsp_total_size_kb,tbsp_usable_size_kb,tbsp_used_size_kb,tbsp_free_size_kb, tbsp_utilization_percent
from sysibmadm.TBSP_UTILIZATION
select * from SYSIBMADM.TOP_DYNAMIC_SQL

### DB2 数据库快照功能概述 DB2 数据库确实支持快照功能,该功能允许数据库管理员获取当前数据库及其各个组件的状态信息。通过执行特定的 SQL 或者命令行工具指令,可以收集关于应用程序、动态 SQL、缓冲池、锁、以及其他对象的相关统计信息[^1]。 以下是具体的操作方式: #### 单独收集快照 可以通过以下命令分别针对不同的数据库组件来收集快照: ```bash db2 get snapshot for applications on database_name db2 get snapshot for database on database_name db2 get snapshot for dynamic sql on database_name db2 get snapshot for bufferpools on database_name db2 get snapshot for locks on database_name db2 get snapshot for tables on database_name db2 get snapshot for tablespaces on database_name ``` 每条命令都专注于某一类资源的信息采集,例如 `applications` 提供应用层面的数据,而 `locks` 则关注于锁机制的状态等[^1]。 #### 同时收集多个快照 如果希望一次性获得所有可用类型的快照,则可使用如下综合型语句简化流程: ```bash db2 get snapshot for all on database_name ``` 这条命令会返回整个指定数据库实例下几乎所有的运行状况细节,极大地方便了全面监控需求下的快速诊断工作[^1]。 另外,在某些场景下可能还需要配合其他高级特性一起运用,比如当涉及到变更事件源追踪的时候就可以利用到 Debezium 连接器所提供的 Db2SnapshotChangeEventSource 类来进行更深层次的数据同步与复制操作[^3]。 最后值得注意的是除了常规意义上的性能调优之外,对于灾难恢复计划制定同样重要;因此熟悉诸如在线备份还原(`RESTORE`)及日志前滚(`ROLLFORWARD`)之类的维护任务也是不可或缺的一部分[^2]。 ```sql -- 创建临时用户空间示例 CREATE USER TEMPORARY TABLESPACE STMASPACE PAGESIZE 32K MANAGED BY DATABASE USING ('D:\DB2_TAB\STMASPACE.F1') EXTENTSIZE 256; ``` 以上代码片段展示了如何定义一个新的页大小为32KB并由数据库自行管理存储分配路径位于本地磁盘分区中的用户级暂存区域配置选项之一[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值