1、Application Support Layer Heap Size (ASLHEAPSZ)
它是app和agent通信的buffer,,占用實例共享內(nèi)存空間,。
監(jiān)控:
get snapshot for all on | grep –i “Rejected Block Remote Cursor requests”
Rejected Block Remote Cursor requests = 2283
如果Rejected Block Remote Cursor requests值比較高,,增大ASLHEAPSZ值,,直到該值為0
配置:
update dbm cfg using aslheapsz 20
2、Maximum Requester I/O Block Size (RQRIOBLK)
它是client和
server通信的buffer,,占用每個agent的私有內(nèi)存空間,。
監(jiān)控:無法監(jiān)控
配置:建議設(shè)置為最大值64K,缺省32767bytes,,(設(shè)到最大值不會影響其它性能)
update dbm cfg using rqrioblk 65536
3,、Sort Heap Threshold (SHEAPTHRES)
私有模式排序空間最大閥值,值=并發(fā)數(shù)×SORTHEAP
監(jiān)控:
需要打開sort監(jiān)控開關(guān)-
db2 update monitor switches using sort on
get snapshot for dbm | grep –i “sort”
如果Post threshold sorts值比較大,,增加SORTHEAP ,、SHEAPTHRES參數(shù)值
如果(Piped sorts accepted/Piped sorts requested)值比較低,增加SORTHEAP ,、SHEAPTHRES參數(shù)值
配置:
update dbm cfg using sheapthres 80000
4,、Enable Intra-Partition Parallelism (INTRA_PARALLEL)
在SMP環(huán)境中打開該選項,,提高表和索引掃描速度
監(jiān)控:
list applications
看application對應(yīng)的Agents(# of Agents)數(shù)目是否大于1
配置:
update dbm cfg using intra_parallel yes
5,、Maximum Query Degree of Parallelism (MAX_QUERYDEGREE)
指定一個
SQL語句的最大subagent數(shù)目,當INTRA_PARALLEL值為yes時該參數(shù)起作用。如果該值為 ANY (-1),,那么優(yōu)化器將使用服務(wù)器的最大cpu數(shù)目,。
監(jiān)控:
list applications
看application對應(yīng)的Agents(# of Agents)數(shù)目是否大于1
配置:
update dbm cfg using MAX_QUERYDEGREE 4 IMMEDIATE
6、Query Heap Size (QUERY_HEAP_SZ)
占用agent的私有內(nèi)存空間,,存儲每個agent運行時所有的sql文,,包括the input SQLDA,the output SQLDA,,the statement text,,the SQLCA,the package name,,the package creator,,the section number,a consistency token,,the cursor control block for any blocking cursors,。
監(jiān)控:
無法監(jiān)控
配置:
一般不需要修改,如果訪問大的LOB,,可能需要增加該值
update dbm cfg using query_heap_sz 10000
7,、Number of FCM Buffers (FCM_NUM_BUFFERS)
在multi-partitioned database(partition之間)和intra-partition parallelism enabled(subagent之間)環(huán)境中通信緩存。
在AIX上,,如果DBM有充足的空間,,每個partition依照FCM配置擁有獨立的空間,如果不夠,,所有partition依照FCM配置共享空間,;
在其它操作系統(tǒng)上,所有partition依照FCM配置共享空間,;
如果DB2_FORCE_FCM_BP注冊變量設(shè)置為YES,,所有partition將一直共享空間,但大小將受32bit的OS限制
監(jiān)控:
get snapshot for FCM for all dbpartitionnums
配置:
update dbm cfg using fcm_num_buffers 4096 immediate
8,、Connection,、Agent配置
監(jiān)控:
db2 get snapshot for dbm | grep -i agent
High water mark for agents registered = 2
High water mark for agents waiting for a token = 0
Agents registered = 2
Agents waiting for a token = 0
Idle agents = 1
Agents assigned from pool = 146
Agents created from empty pool = 3
Agents stolen from another application = 0
High water mark for coordinating agents = 2
Max agents verflow = 0
Gateway connection pool agents stolen = 0
9、Keep Fenced Process (KEEPFENCED)
UDF和SP按照運行模式分為兩種:fenced和unfenced,,fenced模式是一種c/s的通信方式,,存儲過程為客戶端請求server的一個 agent為其執(zhí)行業(yè)務(wù)邏輯。unfenced模式是一種直接調(diào)用db2進程并在進程的地址空間內(nèi)執(zhí)行,,有不
安全性,,但該模式可以讀取運行的PID,而 fenced模式做不到,。
如果KEEPFENCED設(shè)置為YES,,可以使UDF或SP所調(diào)用fenced進程或線程一直保持并被重復使用,,一直到實例關(guān)閉才銷毀,但這將占用一定資源(如內(nèi)存),。例如,,使用
java寫的sp,sp運行完成后不會結(jié)束JVM,,下次運行sp將省去啟動JVM的時間,。
配置:
update dbm cfg using keepfenced YES
10、Maximum Total of Files Open (MAXFILOP)
服務(wù)器打開文件的最大數(shù)目,,如果使用SMS容器,,要求該值比較高,也需要檢查操作系統(tǒng)對該值的限制,。
配置:
update db cfg using maxfilop 2000
監(jiān)控:(需要bufferpool的monitor:db2 update monitor switches using bufferpool on)
db2 get snapshot for db on testdb |grep -i ‘close’
11,、Default Buffer Pool Size (BUFFPAGE)
調(diào)整緩沖池的大小辦法:
1、alter bufferpool IBMDEFAULTBP size -1,,修改所有bufferpool大小為-1,,然后依賴BUFFPAGE參數(shù)控制,緩沖池的數(shù)量:4(隱藏的)+創(chuàng)建的緩沖池(含 IBMDEFAULTBP),,每個創(chuàng)建的緩沖池大?。絧agesize×buffpage×(1+5%)
2、直接修改bufferpool大小,,建議使用該方法,,可以控制pagesize大小不同緩沖池的大小。
配置:
update db cfg for using BUFFPAGE bigger_value
alter bufferpool IBMDEFAULTBP size -1
監(jiān)控:
get snapshot for db on db_name
12,、Log Buffer Size (LOGBUFSZ)
從logbuff寫到磁盤的激活條件:
1)A transaction commits (or MINCOMMIT transactions commit). (最小提交事務(wù)數(shù)時flush)
2)The log buffer is full(日志緩沖滿時flush)
3)One second has elapsed since the last log buffer flush.(間隔1秒時flush)
配置:
update database cfg for using LOGBUFSZ 256
監(jiān)控:
get snapshot for database on | grep –i “Log space”
Log space available to the database (Bytes) = 4549916
Log space used by the database (Bytes) = 550084
Maximum secondary log space used (Bytes) = 0
Maximum total log space used (Bytes) = 550084
CLSA(current amount of log space available ) = Log space available to the database - Log space used by the database, CLSA就是LOGBUFSZ參數(shù)可以配置的最大值,。
get snapshot for database on | grep –i “Log pages”
Log pages read = 0
Log pages written = 12644
日志頁面讀(Log pages read)是日志記錄器(logger)從磁盤讀取的日志頁面的數(shù)目,而日志頁面寫(Log pages written)是日志記錄器(logger)寫入磁盤的日志頁面的數(shù)目,。理想狀態(tài),,Log pages read為0,如果該值比較大,,考慮增加LOGBUFSZ值,。
13、Application Heap Size (APPLHEAPSZ)
存放agent或subagent當前sql文處理的所需內(nèi)存,,大小決定于sql文的復雜度及宿主變量大小,。如果是分區(qū)
數(shù)據(jù)庫,這部分內(nèi)存使用APP_CTL_HEAP_SZ堆,,而不在應(yīng)用程序堆,。在運行時按需要分配內(nèi)存,這個值僅是上限值,。
配置:
update database cfg for using applheapsz 1024
監(jiān)控:
無法監(jiān)控,,如果應(yīng)用報錯,,加倍該值,看應(yīng)用錯誤是否消失
14,、Sorting (SORTHEAP, SHEAPTHRES_SHR)
只有 INTRA_PARALLEL 數(shù)據(jù)庫
管理器配置參數(shù)是 ON 或啟用集中器(concentrator)時(即當 MAX_CONNECTIONS 大于 MAX_COORDAGENTS 時),,才可以使用共享排序,。
對私有排序,,SHEAPTHRES 在實例級是一個軟限制,如果超過這個值,,系統(tǒng)將分配很小的排序堆,,性能會下降
對共享排序,SHEAPTHRES_SHR在數(shù)據(jù)庫級是一個硬限制,。
當并發(fā)用戶為10個,,sortheap為100,如果是私有排序,,SHEAPTHRES =10×sortheap,,如果是共享排序,SHEAPTHRES_SHR=5×sortheap
15,、Locking (LOCKLIST, MAXLOCKS, LOCKTIMEOUT, DLCHKTIME)
LOCKLIST 表明分配給鎖列表的存儲容量,。每個數(shù)據(jù)庫都有一個鎖列表,鎖列表包含了并發(fā)連接到該數(shù)據(jù)庫的所有應(yīng)用程序所持有的鎖,。鎖定是數(shù)據(jù)庫管理器用來控制多個應(yīng)用程序并發(fā)訪問數(shù)據(jù)庫中數(shù)據(jù)的機制,。行和表都可以被鎖定。根據(jù)對象是否還持有其它鎖,,每把鎖需要 32 個或 64 個字節(jié)的鎖列表:
* 需要 64 個字節(jié)來持有某個對象上的鎖,,在這個對象上,沒有持有其它鎖,。64bit的是112字節(jié)
* 需要 32 個字節(jié)來記錄某個對象上的鎖,,在這個對象上,已經(jīng)持有一個鎖,。32bit的是56字節(jié)
MAXLOCKS 定義了應(yīng)用程序持有的鎖列表的百分比,,當任何一個應(yīng)用程序所持有的鎖數(shù)量達到整個鎖列表大小的這個百分比時,對該應(yīng)用程序所持有的鎖進行鎖升級,。如果鎖列表用完了空間,,那么也會發(fā)生鎖升級。經(jīng)驗:MAXLOCKS 參數(shù)乘以 MAXAPPLS 參數(shù)不能小于 100,。
如果發(fā)生死鎖,,將數(shù)據(jù)庫診斷級別改為4,數(shù)據(jù)庫日志將記錄死鎖發(fā)生的原因(與誰發(fā)生了死鎖,,鎖類型,,是否行級鎖)
db2 update dbm cfg using diaglevel 3
0 為不記錄信息
1 為僅記錄錯誤
2 記錄服務(wù)和非服務(wù)錯誤
缺省是3,,記錄db2的錯誤和警告
4 是記錄全部信息,包括成功執(zhí)行的信息
監(jiān)控:
get snapshot for database on | grep -i ‘Lock’
Locks held currently = 12
Lock waits = 0
Time database waited on locks (ms) = 0
Lock list memory in use (Bytes) = 2080
Deadlocks detected = 1
Lock escalations = 0
Exclusive lock escalations = 0
Agents currently waiting on locks = 0
Lock Timeouts = 0
Internal rollbacks due to deadlock = 1
如果診斷級別改為4,,Lock Timeouts的詳細原因就可以記錄:
Request for lock “TAB: (2, 13)” in mode “.IX” timed out
Application caused the lock wait is “*LOCAL.DB2.007340152709″
Statement: 7570 6461 7465 2074 3120 7365 7420 6331 update t1 set c1
3d63 312b 3531 3231 30 =c1+51210
可以看到LOCAL.DB2.007340152709應(yīng)用占著t1表的鎖沒有釋放
16,、Number of Asynchronous Page Cleaners (NUM_IOCLEANERS)
異步清理緩沖池中臟頁的進程數(shù).
清理進程啟動的條件:
1)臟頁閥值CHNGPGS_THRESH:表示臟頁占緩沖池的百分數(shù)
2)達到SOFTMAX(soft checkpoint)值時,(如果softmax值是50,,logfilesize值是10M,,當寫入日志文件的數(shù)據(jù)量達到5M=10M×50%時,啟動清理進程)
3)當發(fā)生Dirty page steals情況時,,
配置:經(jīng)驗值(A rule of thumb)-小于等于CPU數(shù)目
update db cfg for using NUM_IOCLEANERS 16
監(jiān)控:
update monitor switches using bufferpool on
get snapshot for db on testdb|grep -i “writes”
Buffer pool data writes = 0
Asynchronous pool data page writes = 167660
Buffer pool index writes = 0
Asynchronous pool index page writes = 178944
PADW = (Asynchronous pool data page writes / Buffer pool data writes) * 100%
PAIX = (Asynchronous pool index page writes / Buffer pool index writes) * 100%
如果PADW ,、PAIX 接近100%,應(yīng)該減少NUM_IOCLEANERS
get snapshot for db on testdb|grep -i “cleaner trigger”
LSN Gap cleaner triggers = 142
Dirty page steal cleaner triggers = 2
Dirty page threshold cleaner triggers = 396
如果Dirty page steal cleaner triggers 值非常小,,其它兩個大,,說明配置恰當。
如果Dirty page steal cleaner triggers 值非常大,,LSN Gap cleaner triggers比較小,,說明softmax值比較高,需要調(diào)小,。
計算每次cleaner啟動后,,寫多少page?
APPAW = (167660 + 178944) / (142 + 2 + 396) = 641 Pages
相當于每次cleaner寫641×4k=2.5M數(shù)據(jù)到硬盤,,對于1G的buffer來講,,啟動次數(shù)太多,但對100M的buffer來講,,是合適的,。
17、Number of I/O Servers (NUM_IOSERVERS)
該參數(shù)值就是預(yù)取器的數(shù)量,。一般該值等于數(shù)據(jù)庫數(shù)據(jù)所在的磁盤數(shù)目,。
18、Number of Commits to Group (MINCOMMIT)
如果1秒內(nèi)有6個事務(wù),,該參數(shù)最后調(diào)到6,。
并且也要調(diào)logbufsize>=MINCOMMIT×平均每個事務(wù)消耗的空間
配置:
update db cfg for using MINCOMMIT 5
監(jiān)控:
get snapshot for database on
Last reset timestamp = 09-12-2002 14:51:43.786876
Snapshot timestamp = 09-12-2002 14:56:27.787088
Commit statements attempted = 1011
Rollback statements attempted = 10
Log space used by the database (Bytes) = 3990
Log pages written = 23
每秒執(zhí)行的事務(wù)數(shù)=(Commit statements attempted + Rollback statements attempted) /
(Last reset timestamp - Snapshot timestamp)
19、Catalog Cache Size (CATALOGCACHE_SZ)
配置:
update db cfg for using CATALOGCACHE_SZ 32
監(jiān)控:
db2 get snapshot for db on testdb|grep -i “catalog”
Catalog database partition number = 0
Catalog network node name =
Catalog cache lookups = 17
Catalog cache inserts = 7
Catalog cache verflows = 0
Catalog cache high water mark = 0
如果命中率(1 – (Catalog cache inserts / Catalog cache lookups)) * 100 < 95%,增加該參數(shù)值,。
如果Catalog cache overflows 不為0,, 也需要增加該參數(shù)值,一般同時會增加dbheap參數(shù)值,。
20,、Average Number of Active Applications (AVG_APPLS)
DB2優(yōu)化器根據(jù)這個參數(shù)來評估資源的使用策略,特別是緩沖池空間,。
配置:
update db cfg for using AVG_APPLS 16
監(jiān)控:
db2 get snapshot for db on testdb|grep -i “appls”
Appls. executing in db manager currently = 0
修改注冊變量:
DB2_SKIPINSERTED=on,DB2_SKIPDELETED=on,DB2_EVALUNCOMMITTED=on(V.8.2以上)
可以提高數(shù)據(jù)庫并發(fā)量,,但是查詢的結(jié)果不含正在插入或刪除的記錄,。