SYSIBM: 基本系统编目,不建议直接访问
SYSCAT: 默认授权给Public组.只读编目视图,一般通过这个来获取编目信息
SYSSTAT: 可更新编目视图,会影响优化器的优化策略
SYSFUN: 用户定义函数
SYSPROC: 存放一组系统的存储过程
如果你需要知道具体的每个编目表所产生的作用,可以去info center里面去搜索关键字: Road map to the catalog views, 可以得到所有以syscat.开头的编目视图(一般情况下用的也是这个).当然我还自己mark了一些牛大师的书里头提到的常用的对系统编目表的SQL语句,仅供参考(飞鹏大牛的书看完了还没做笔记...他的书里面也有许多有用的SQL语句):
1. 监控缓冲池命中率:
select substr(db_name,1,8) as DB_NAME, substr(bp_name,1,8) as BP_NAME, total_hit_ratio_percent as TOTAL_HR, data_hit_ratio_percent as DATA_HR, index_hit_ratio_percent as INDEX_HR, xda_hit_ratio_percent as XDA_HR from SYSIBMADN.BP_HITRATIO where bp_name not like ‘%IBMSYSTEM%’;
2. 监控PACKAGE CACHE大小:
with dbcfg1 as (select int(value) as pckcachesz from sysibmadm.dbcfg where name ‘pckcachesz’ ) select pckcachesz as “Package Cache Size”, pkg_cache_lookups as “Lookups”, pkg_cache_inserts as “Inserts”, pkg_cache_num_overflows as “Overflows”, 100 * pkg_cache_size_top / (pckcachesz * 4096) as “%PKG Cache alloc” from dbcfg1, sysibmadm.snapdb;
3. 监控执行成本最高的SQL语句
select AGENT_ID, ROWS_SELECTED, ROWS_READ from sysibmadm.SNAPAPPL fetch first 10 rows only;
通过对比SELECT 和READ的值来进行判断.
4. 监控运行最长的SQL语句:
select substr(appl_name,1,15) as Appl_name, elapsed_time_min as Elapsed_Min, appl_status as Status, substr(auth,1,10) as auth_id, substr(inbound_comm_address,1,15) as IP_Address, substr(stmt_text,1,30) as SQL_Statement from sysibmadm.long_running_sql order by 2 desc;
5. 监控SQL准备和预编译时间最长的SQL语句:
select num_executions, average_execution_time_s(SQL语句平均执行时间), prep_time_ms(最长的SQL预编译时间), prep_time_percent(预编译时间占整个执行时间的百分比), substr(stmt_text,1,40) as SQL_TEXT from sysibmadm.query_prep_cost where average_execution_time_s > 0 order by prep_time_percent desc;
6. 监控执行次数最多的SQL语句:
select num_executions as Num_Excus, average_execution_time_s as Avg_times_s, stmt_sorts as Num_Sorts, sorts_per_execution as Sort_per_stmt, substr(stmt_text,1,35) as SQL_stmt from sysibmadm.top_dynamic_sql where num_execution > 0 order by 1 desc fetch first 5 rows only;
7. 监控排序次数最多的SQL语句:
select STMT_SORTS, SORTS_PER_EXECUTION, substr(stmt_text,1,60) as STMT_TEXT from sysibmadm.top_dynamic_sql by STMT_SORTS desc fetch first 5 rows only;
8. 监控LOCK WAIT时间:
select substr(ai.appl_name,1,20) as appl_name, substr(ai.primary_auth_id,1,10) as auth_id, ap.lock_waits as lock_waits, ap.lock_waits_time / 1000 as Total_waits_s, ap.lock_waits_time / ap.lock_waits as Avg_waits_ms from sysibmadm.snapappl_info ai, sysibmadm.snapappl ap where ai.agent_id = ap.agent_id and ap.lock_waits > 0;
9. 监控LOCK CHAIN:
select substr(ai_h.appl_name,1,0) as Hold_App, substr(ai_h.primary_auth_id,1,10) as Holder, substr(lw.appl_name,1,10) as Wait_app, substr(lw.authid,1,10) as Waiter, lw.lock_mode, lw.lock_object_type, substr(lw.tabname,1,10) as TabName, substr(lw.tabschema,1,10) as Schema, timestampdiff(2,char(lw.snapshot_timestamp - lw.lock_wait_start_time)) as waiting_s from sysibmadm.lockwaits lw, sysibmadm.snapappl_info ai.h where lw.agent_id_holding_lk = ai_h.agent_id;
10. 监控锁内存使用:
with dbcfg1 as (select float(int(value) * 4096) as locklist from sysibmadm.dbcfg where name = ‘locklist’), dbcfg2 as (select float (int(value) ) as maxlock from sysibmadm.dbcfg where name = ‘maxlock’) select dec ((lock_list_in_use/locklist) * 100,4,1) as % Lock_List, dec((lock_list_in_use/(locklist*(maxlocks/100))*100),4,1) as %_to_Maxlock(Maxlock的配置大小是多少), appls_cur_cons as Number_of_cons, lock_list_in_use/appl_cur_cons as Avg_Lock_Mem_per_Con_bytes from dbcfg1, dbcfg2, sysibmadm.snapdb;
11. 监控锁升级,死锁和锁超时:
select substr(ai.appl_name,1,10) as Application, substr(ai.primary_auth_id,1,10) as AuthID, int(ap.locks_held) as Locks, int(ap.lock_escals) as Escalations, int(ap.lock_timeouts) as Lock_timeouts, int(ap.deadlocks) as Deadlocks, int(ap.int_deadlock_rollbacks) as Dlock_Victim, substr(inbound_comm_address,1,15) as IP_Address from sysibmadm.snapappl ap, sysibmadm.snapappl_info ai where ap.agent_id = ai.agent_id;
12. 监控全表扫描的SQL:
select substr(authid,1,10) as authid, substr(appl_name,1,20) as appl_name, percent_rows_selected from sysibmadm.appl_performance;
13. 检查page cleaner是否足够:
wuth db_snap as (select float(pool_drty_pg_steal_clns) as pg_steal, float(pool_drty_pg_thrsh_clns) as chg_pg_thrsh, float(pool_lsn_gap_clns) as softmax, float(pool_drty_pg_steal_clns + pool_drty_pg_thrsh_cls + pool_lsn_gap_clns) as total_clns from sysibmadm.snapdb) select dec(( pg_steal/toal_clns) * 100,4,1) as %steals, dec(( chg_pg_thrsh/total_clns) * 100,4,1) as %Threshold, dec(( softmax / total_clns) * 100,4,1) as %Softmax from db_snap;
14. 监控PREFETCHER是否足够:
with bp_snap as (select substr(br_name,1,30) as bp_name, unread_prefetch_pages, pool_async_data_reads + pool_async_index_reads as async_reads, pool_data_p_reads + pool_index_p_reads + pool_temp_data_p_reads + pool_temp_index_p_reads as Total_Reads from sysibmadm.snapbp where bp_name not like ‘IBMSYSTEM%’) select bp_name, unread_prefetch_pages, dec (100 *(Total_reads * Async_reads ) / Total_reads,5,2) as %Synch_Reads, dec (100 * unread_prefetch_pages /Total_reads, 5,2) as %Unread_Pages(异步I/O服务器预存取到缓冲池没有使用的页) from bp_snap;
15. 监控数据库内存使用(未启用STMM情况下):
select pool_id, pool_secondary_id, pool_current_size, pool_watermark from sysibmadm.snapdb_memory_pool;
16. 监控日志使用情况:
select int (total_log_used/1024/1024) as Log_used_Meg, int(total_log_available/1024/1024) as Log_Space_Free_meg, int((float(total_log_used) / float(total_log_used + total_log_available)) * 100) as Pct_Used, int (tot_log_used_top/1024/1024) as Max_Log_Used_Meg, int(sec_log_used_top/1024/1024) as Max_Sec_Used_Meg(日志使用的高水位), int(sec_logs_allocated) as Secondaries from sysibmadm.snapdb;
17. 监控占用日志空间最旧的交易:
select substr(ai.appl_status,1,20) as Status, substr(ai.primary_auth_id,1,10) as Authid, substr(ai.appl_name,1,15) as Appl_name, int(ap.UOW_LOG_SPAC_USED/1024/1024) as Log_Used_MB, Int(ap.appl_idle_time/60) as Idle_for_min, ap.appl_con_time as Connected_Since from sysibmadm.snapdb db, sysibmadm.snapappl ap, sysibmadm.snapappl_info ai where ai.agent_id = db.APPL_ID_OLDEST_XACT and ap.agent_id = ai.agent_id;
18. 监控存储路径:
select substr(type,1,20) as type, substr(path,1,50) as path from sysibmadm.dbpaths order by type;
19. 监控表空间使用情况:
select substr(tbsp_name,1,18), tbsp_type, tbsp_free_size_kb, tbsp_utilization_percent from sysibmadm.tbsp_utilization;
20. 利用系统编目表写脚本:
例1: 以表名为名称大批量导出表:
select ‘export to ‘||tabname||’.ixf of ixf select * from ‘||rtrim(tabschema)||’.’||tabname||’;’ from syscat.tables where type=’T’ and tabschema not in (‘SYSIBM’, ‘SYSCAT’, ‘SYSSTAT’, ‘SYSTOOLS’)”
例2: 大批量授权:
select ‘grant select on table ‘||rtrim(tabschema)||’.’||tabname||’ to user username; ‘ from syscat.tables where type = ‘T’ and tabeschema not in (‘SYSIBM’, ‘SYSCAT’, ‘SYSSTAT’, ‘SYSTOOLS’)”
每个数据库都有它自己的系统目录表和视图。它们存储关于数据对象的元数据。
sysibm:基本表,对于db2使用进行最优化
syscat:基于sysibm表的视图,对平常轻负荷使用进行优化
sysstat:数据库分析
=====================================================================================
sysibm.syschecks:存放系统中check约束的信息,系统为每个表的每一个check约束建立一条记录。
sysibm.syscolumns:表中存放系统中所有表的数据列的描述信息,系统为db2里定义的每个表的每一行建立一条记录。
sysibm.sysdatabase:系统为每个database保存一条记录。
sysibm.sysforeignkeys:为每个foreign key约束建立一条记录。
sysibm.sysindexes:为每个索引建立一条记录。
sysibm.syskeys:系统为每个index的每个键值创建一条记录。
sysibm.systables:系统为每一个表,视图和别名在该表中创建一行记录。
sysibm.syspackstmt:每个package中的每条sql语句有一条记录。
sysibm.syspackage每个package有一条记录。
sysibm.syspacklist:每个plan相关的每个package list有一条或一条以上记录。
sysibm.sysplan:每个plan有一条记录。
联邦对象 | syscat编目视图 | 描述 |
包装器 | syscat.wrappers syscat.wrapoptions |
这两个视图显示被注册的包装器和它们特定的选项 |
servers | syscat.servers syscat.serveroptions |
这两个视图显示被注册的远程数据源和它们的特定选项 |
用户映射 | syscat.useroptions | 这个视图显示被注册的一个db2用户用于特定服务器的用户认证。 秘密设置存储在encrypted中 |
昵称 | syscat.tables syscat.taboptions syscat.columns syscat.coloptions syscat.indexes syscat.indoptions syscat.indexcoluse syscat.keycoluse |
这组视图显示和被注册昵称相关的信息 在 SYSCAT.TABLES 中,昵称是通过被设为“N”的 TYPE 来标识的。 SYSCAT.TABOPTIONS 显示关于昵称的特定选项 SYSCAT.COLOPTIONS 显示关于昵称列的特定选项 SYSCAT.INDEXCOLUSE 列出参与一个索引的列 SYSCAT.KEYCOLUSE 存储关于主键的信息 |
索引规范 | syscat.indexes syscat.indexcoluse |
这两个视图显示为昵称创建的索引规范 |
信息约束 | syscat.tabconst syscat.checks syscat.colchecks syscat.peferences |
这组视图显示为昵称定义的信息约束 SYSCAT.TABCONST 显示每个定义的约束 SYSCAT.CHECKS 和 SYSCAT.COLCHECKS 显示关于检查约束的信息 SYSCAT.CONSTDEP 列出约束所依赖的对象 SYSCAT.REFERENCES 列出参照约束 |
类型映射 | syscat.typemappings | 这个视图显示在昵称注册和远程表创建中使用的用户定义类型映射。 默认的内置类型映射不存储在这个编目视图中 |
函数映射 | syscat.funcmappings syscat.funcmapoptions syscat.funcmapparmoptions |
这个视图显示在昵称注册和远程表创建中使用的用户定义类型映射。 默认的内置类型映射不存储在这个编目视图中 |
Passthru权限 | syscat.passthruauth | 这个视图显示允许用户使用 PASSTHRU 查询特定服务器的授权 |
函数模版 | syscat.functions syscat.routines |
这两个视图显示被注册的用户定义函数 在 V8 中,SYSCAT.ROUTINES 取代了 SYSCAT.FUNCTIONS (SYSCAT.FUNCTIONS 仍然存在,但是文档中没有说明) |