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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章