DB2高级使用

1.        检查LOCKTIMEOUT 的值

The default value for LOCKTIMEOUT is -1, which means that there will be no lock timeouts - a situation that can be catastrophic for OLTP applications. Nevertheless, I all too frequently find many DB2 users with LOCKTIMEOUT = -1. Set LOCKTIMEOUT to a very short value, such as 10 or 15 seconds. Waiting on locks for extended periods of time can have an avalanche effect on locks.

First, check the value of LOCKTIMEOUT with this command:

db2 "get db cfg for DBNAME"

 

and look for the line containing this text:

Lock timeout (sec) (LOCKTIMEOUT) = -1

 

If the value is -1, consider changing it to 15 seconds by using the following command (be sure to consult with the application developers or your vendor first to make sure the application is prepared to handle lock timeouts):

db2 "update db cfg for DBNAME using LOCKTIMEOUT 15"

 

You should also monitor the number of lock waits, lock wait time, and amount of lock list memory in use. Issue the command:

db2 "get snapshot for database on DBNAME"

 

Look for the following lines:

Locks held currently= 0  

Lock waits= 0  

Time database waited on locks (ms)= 0  

Lock list memory in use (Bytes)= 576  

Deadlocks detected= 0  

Lock escalations= 0  

Exclusive lock escalations= 0  

Agents currently waiting on locks= 0  

Lock Timeouts= 0

 

If the Lock list memory in use (Bytes) exceeds 50 percent of the defined LOCKLIST size, then increase the number of 4K pages in the LOCKLIST database configuration.

2.        计算本开发环境中BUFFER的命中率

缓冲池是内存中的一块存储区域,用于临时读入和更改数据库页(包含表行或索引项)。缓冲池的用途是为了提高数据库系统的性能。从内存访问数据要比从磁盘访问数据快得多。因此,数据库管理器需要从磁盘读取或写入磁盘的次数越少,性能就越好。对一个或多个缓冲池进行配置之所以是调优的最重要方面,是因为连接至数据库的应用程序的大多数数据(不包括大对象和长字段数据)操作都在缓冲池中进行。 缺省情况下,应用程序使用缓冲池 IBMDEFAULTBP,它是在创建数据库时创建的。当 SYSCAT.BUFFERPOOLS 目录表中该缓冲池的 NPAGES 值为 -1 ,DB2 数据库配置参数 BUFFPAGE 控制着缓冲池的大小。否则会忽略 BUFFPAGE 参数,并且用 NPAGES 参数所指定的页数创建缓冲池。 建议对于仅使用一个缓冲池的应用程序, NPAGES 更改成 -1,这样 BUFFPAGE 就可以控制该缓冲池的大小。这使得更新和报告缓冲池大小以及其它 DB2 数据库配置参数变得更加方便。 

n       查看bufferpools

$ db2 get db cfg for coredb |grep BUFF

 Buffer pool size (pages)                     (BUFFPAGE) = 1000

n       计算命中率:

db2 "update monitor switches using  lock ON sort ON bufferpool ON uow ON  table ON statement ON" 

db2 "get snapshot for all bufferpools" 
在数据库快照或缓冲池快照的快照输出中,查找下列"logical reads""physical reads",这样就可以计算出缓冲池命中率,它可以帮助调优缓冲池
缓冲池命中率表明数据库管理器不需要从磁盘装入页(即该页已经在缓冲池中)就能处理页请求的时间百分比。缓冲池的命中率越高,使用磁盘 I/O 的频率就越低。按如下计算缓冲池命中率
(1 - ((buffer pool data physical reads + buffer pool index physical reads) / 
(buffer pool data logical reads + pool index logical reads)) 
) * 100% 
这个计算考虑了缓冲池高速缓存的所有页(索引和数据)。理想情况下,该比率应当超过 95%,并尽可能接近 100%

$ db2 "get snapshot for all bufferpools"|grep logical

Buffer pool data logical reads             = 200

Buffer pool temporary data logical reads   = 0

Buffer pool index logical reads            = 0

Buffer pool temporary index logical reads  = 0

$ db2 "get snapshot for all bufferpools"|grep  physical

Buffer pool data physical reads            = 0

Buffer pool temporary data physical reads  = 0

Buffer pool index physical reads           = 0

Buffer pool temporary index physical reads = 0

这个计算考虑了缓冲池高速缓存的所有页(索引和数据)。理想情况下,该比率应当超过 95%,并尽可能接近 100%。要提高缓冲池命中率,请尝试下面这些方法增加缓冲池大小。  
考虑分配多个缓冲池,如果可能的话,为每个经常被访问的大表所属的表空间分配一个缓冲池,为一组小表分配一个缓冲池,然后尝试一下使用不同大小的缓冲池以查看哪种组合会提供最佳性能。  
如果已分配的内存不能帮助提高性能,那么请避免给缓冲池分配过多的内存。应当根据取自测试环境的快照信息来决定缓冲池的大小。 
太小的缓冲池会产生过多的、不必要的物理 I/O。太大的缓冲池使系统处在操作系统页面调度的风险中并消耗不必要的 CPU 周期来管理过度分配的内存。正好合适的缓冲池大小就在"太小""太大"之间的某个平衡点上。适当的大小存在于回报将要开始减少的点上。 

n      修改bufferpools

方法一:

Select npages from syscat.bufferpools

Alter bufferpool ibmdefaultbp immediate size 20000

方法二:

Create bufferpool hisdbbp1 immediate size 2500 pagesize 32k

Alter tablespace syscatspace bufferpool hisdbbp1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值