數據庫的性能是我們重點考慮的因素,如何才能調整數據庫的性能,成為了大家熱議的話題,本文將為您介紹DB2數據庫的性能調整命令,供您參考,希望能對您有所幫助。
IBM DB2數據庫性能調整命令:
查看執行計劃:
db2expln:
db2expln -d dbname -c pkgOwner -p pkgNmae -o expln.out
dynexpln:
dynexpln -d eos -q "select * from eosmenu" -g -t
dynexpln -d eos -f query.sql -o out.txt
更新統計信息:
runstats:
db2 runstats on table songxn.eosmenu and indexs songxn.ix1,songxn.ix2 allow read Access
db2 runstats on table songxn.eosmenu with distribution and detailed index all
調整優化等級:
(0,1,2,3,5,7,9):
更改DFT_QUERYOPT(db cfg), 默認為5
SQL:set current query optimization = 3
索引:
建立索引:
create unique index ind1 on vicky.staff ( dept, lastname )
create unique index ind2 on vicky.emplyee ( empno ) include ( lastname, salary)
include中的字段不列入排序范圍
叢集索引:
記錄與索引的順序一致
cretae index ind3 on vicky.staff ( dept ) CLUSTER
SCAN MODE:
Index Scan,Full Index Scan(Index only Access),Relation Scan
查詢索引:
select indname from syscat.indexes where tabname='customer'
索引建議器:
db2advis -d dbname -i query.sql | -s "sql stmt" -o advis.out
在數據頁中預留空間:
alter table vicky.staff PCTFREE 30(預留30%)
load from staff.ixf of ixf modifIEd by pagefreespace=30 replace into vicky.staff
緩沖池與IO
默認為IBMDEFAULTBP
新建緩沖池:
db2 create bufferpool bpname size 1000 pagesize 4k
alter tablespace tbname bufferpool bpname
當髒頁超過CHNGPGS_THRESH(%,db cfg)時,緩沖池將被清空並寫回
延展緩沖池:
ESTORE_SEG_SZ& NUM_ESTORE_SEGS(db cfg)
db2 alter bufferpool ibmdefaultbp [ not ] extended storage
I/O SERVER:
NUM_iOSERVERS(db cfg):一般為磁盤數+2
數據重整:
REORGCHK:
db2 reorgchk update statistics on table all 該語句也用來對所有表做RUNSTATS
db2 reorgchk current statistics on table vicky.staff
table statistics:
CARD:記錄筆數
OV(ERFLOW):overflow的記錄數
NP(AGES):含有記錄的頁數
FP(AGES):表格占用的總頁數
TSIZE(Bytes):表格大小
index statistics:
LEAF:leaf page數
ELEAF:空葉數
NDEL:被刪除的RID數
LVLS:索引層級數
ISIZE:索引平均長度
KEYS:不同的索引值的個數
表格重整:
db2 reorg table vicky.staff index ind1 use tempspace2 indexscan
索引重整:
db2 reorg indexes all for table vicky.staff _options_
options:allow read|write|no Access, cleanup only pages|all(不重建索引結構,只回收空索引頁)
聯機表格重整(V8+):
db2 reorg table vicky.staff index vicky.ind2 inplace allow write Access
db2 reorg table vicky.staff index vicky.ind2 inplace pause|resume
db2 list history reorg all for dbname
MQT
MQT:
建立MQT:
CREATE TABLE vicky.mqt1 AS
( SELECT name, location, salary
FROM vicky.staff, vicky.org
WHERE staff.dept=org.deptnumb AND salary>20000
) DATA INITIALLY DEFERRED REFRESH DEFERRED|IMMEDIATE
ENABLE|DISABLE QUERY OPTIMIZATION
REFRESH TABLE vicky.mqt1
利用MQT:
RUNSTATS ON TABLE vicky.mqt1
UPDATE DB CFG FOR sample USING DFT_REFRESH_AGE ANY
並行處理
設置並行處理:
UPDATE DBM CFG USING INTRA_PARALLEL YES
UPDATE DB CFG FOR EOS USING DFT_DEGREE ANY
並行處理上限:
應用級:
SET RUNTIME DEGREE FOR ( 25 ) TO 4
SET RUNTIME DEGREE FOR ALL TO 6
實例級:
UPDATE DBM CFG USING MAX_QUERYDEGREE 6
MDC表:
CREATE TABLE vicky.sales
( YearAndMonth CHAR(4),
Region CHAR(20),
Product CHAR(2),
Sales BIGINT
) ORGANIZE BY DIMENSIONS ( YearAndMonth, Region )
CREATE TABLE vicky.table1
( col1 CHAR(10),
col2 CHAR(10),
col3 CHAR(10),
col4 INTEGER,
col5 DECIMAL(10,2),
) ORGANIZE BY DIMENSIONS ( col1, ( col2, col3 ),col4 )