DB2數(shù)據(jù)庫常用命令數(shù)據(jù)庫學習
你可以用 get snapshot for locks on XXX 看是那個表鎖了,再從相關的操作去查原因吧
db2pd -d 庫名 -locks
和
db2pd -d 庫名 -wlocks
window環(huán)境下在db2cmd下,使用db2 get snapshot for locks on dbname
-查看數(shù)據(jù)庫管理器級別快照信息
??? db2 get snapshot for dbm
-查看數(shù)據(jù)庫級別快照信息
??? db2 get snapshot for database on dbname???????
-查看應用級別快照信息
??? db2 get snapshot for application agentid appl-handler
?? 注:appl-handler可以從list applicaitions的輸出中得到
-查看表級別快照信息
??? db2 get snapshot for tables on dbname??
??? 注:需要把tables快照開關設為ON才會有作用
-查看鎖快照信息
??? db2 get snapshot for locks on dbname
? 或
??? db2 get snapshot for locks on for application agentid appl-handler
-查看動態(tài)sql語句快照信息
??? db2 get snapshot for dynamic sql on dbname
db2 get monitor switches
db2 update monitor switches using lock on statement on
create? event monitor mymonitor for deadlocks,statements?? write to file? 'D:\temp'
set event monitor mymonitor state 1
db2evmon? - path 'D:\temp'
?
DB2頻繁出現(xiàn)死鎖,常用解決命令
db2 get snapshot for locks on sample
db2 get db cfg for sample
db2 update db cfg using dlchktime 10000
4. 查看快照信息
-查看數(shù)據(jù)庫管理器級別快照信息
DB2 get snapshot for dbm
-查看數(shù)據(jù)庫級別快照信息
DB2 get snapshot for database on dbname
-查看應用級別快照信息
DB2 get snapshot for application agentid appl-handler
注:appl-handler可以從list applicaitions的輸出中得到
-查看表級別快照信息
DB2 get snapshot for tables on dbname
注:需要把tables快照開關設為ON才會有作用
-查看鎖快照信息
DB2 get snapshot for locks on dbname
或
DB2 get snapshot for locks? for application agentid appl-handler
-查看動態(tài)sql語句快照信息
DB2 get snapshot for dynamic sql on dbname
5.使用事件查看器
可以使用時間查看器收集鎖事件,SQL語句事件,從而根據(jù)事件分析鎖原因。
事件類型
使用事件監(jiān)控器,首先要選定所關注的事件類型,DB2中有很多事件類型,可以用于鎖分析的通常會用到以下三種:
DEADLOCKS
DEADLOCKS WITH DETAILS
STATEMENTS
步驟:
-創(chuàng)建事件監(jiān)控器
create event monitor evmname for eventtype write to file ‘directory’
例:create event monitor mymonitor for deadlocks, statements
write to file ‘c:\temp’
-把事件監(jiān)控器打開
接上例:
set event monitor mymonitor state 1
注:1為打開,0為關閉
事件監(jiān)控器開始工作,當所有應用斷掉連接后,將事件記錄下來
-查看事件細節(jié)
一、加載數(shù)據(jù):
1、 以默認分隔符加載,默認為“,”號
??? db2 "import from btpoper.txt of del insert into btpoper"
2、 以指定分隔符“|”加載
??? db2 "import from btpoper.txt of del modified by coldel| insert into btpoper"
二、卸載數(shù)據(jù):
1、 卸載一個表中全部數(shù)據(jù)
??? db2 "export to btpoper.txt of del select * from btpoper"
??? db2 "export to btpoper.txt of del modified by coldel| select * from btpoper"
2、 帶條件卸載一個表中數(shù)據(jù)
??? db2 "export to btpoper.txt of del select * from btpoper where brhid='907020000'"
??? db2 "export to cmmcode.txt of del select * from cmmcode where codtp='01'"
??? db2 "export to cmmcode.txt of del modified by coldel| select * from cmmcode where codtp='01'"
三、查詢數(shù)據(jù)結構及數(shù)據(jù):
??? db2 "select * from btpoper"
??? db2 "select * from btpoper where brhid='907020000' and oprid='0001'"
??? db2 "select oprid,oprnm,brhid,passwd from btpoper"
四、刪除表中數(shù)據(jù):
??? db2 "delete from btpoper"
??? db2 "delete from btpoper where brhid='907020000' or brhid='907010000'"
五、修改表中數(shù)據(jù):
??? db2 "update svmmst set prtlines=0 where brhid='907010000' and jobtp='02'"
??? db2 "update svmmst set prtlines=0 where jobtp='02' or jobtp='03'"
六、聯(lián)接數(shù)據(jù)庫
??? db2 connect to btpdbs
七、清除數(shù)據(jù)庫聯(lián)接
??? db2 connect reset??? 斷開數(shù)據(jù)庫連接
??? db2 terminate??????? 斷開數(shù)據(jù)庫連接
??? db2 force applications all??? 斷開所有數(shù)據(jù)庫連接
八、備份數(shù)據(jù)庫
1、 db2 backup db btpdbs
2、 db2move btpdbs export
??? db2look -d btpdbs -e -x [-a] -o crttbl.sql
九、恢復數(shù)據(jù)庫
1、 db2 restore db btpdbs without rolling forward
2、 db2 -tvf crtdb.sql
??????? crtdb.sql文件內容:create db btpdbs on /db2catalog
??? db2 -stvf crttbl.sql
??? db2move btpdbs import
十、DB2幫助命令:
??? db2 ?
??? db2 ? restroe
??? db2 ? sqlcode (例:db2 ? sql0803) 注:code必須為4位數(shù),不夠4位,前面補0
十一、bind命令:將應用程序與數(shù)據(jù)庫作一捆綁,每次恢復數(shù)據(jù)庫后,建議都要做一次bind
?? (1) db2 bind br8200.bnd
?? (2) /btp/bin/bndall /btp/bnd
?????? /btp/bin/bndall /btp/tran/bnd
十二、查看數(shù)據(jù)庫參數(shù):
????? db2 get dbm cfg
????? db2 get db cfg for btpdbs
十三、修改數(shù)據(jù)庫參數(shù):
????? db2 update db cfg for btpdbs using LOGBUFSZ 20
????? db2 update db cfg for btpdbs using LOGFILSIZ 5120
????? 改完后,應執(zhí)行以下命令使其生效:
????? db2 stop
????? db2 start
補充:
?? db2 set schema btp??? 修改當前模式為"btp"
?? db2 list tablespaces show detail???? 查看當前數(shù)據(jù)庫表空間分配狀況
?? db2 list tablespace containers for 2? show detail 查看tablespace id=2使用容器所在目錄
?? db2 list application
?? db2 list db directory?????????????? 列出所有數(shù)據(jù)庫
?? db2 list active databases?????????? 列出所有活動的數(shù)據(jù)庫
?? db2 list tables for all???????????? 列出當前數(shù)據(jù)庫下所有的表
?? db2 list tables for schema btp????? 列出當前數(shù)據(jù)庫中schema為btp的表
?? db2 list tablespaces show detail??? 顯示數(shù)據(jù)庫空間使用情況
?? db2 list packages for all
?? db2 "import from tab76.ixf of ixf commitcount 5000 insert into achact"
?? db2 "create table achact_t like achact"
??
?? db2 "rename table achact_t to achact"
??
?? db2 "insert into achact_t select * from achact where txndt>=(select lstpgdt from
????? acmact where actno=achact.actno)"
??
?? db2 get snapshot for dynaimic sql on jining
刪除一個實例:
?? # cd /usr/lpp/db2_07_01/instance
?? # ./db2idrop InstName
列出所有DB2實例:
?? # cd /usr/lpp/db2_07_01/bin
?? # ./db2ilist
為數(shù)據(jù)庫建立編目
? $ db2 catalog db btpdbs on /db2catalog
取消已編目的數(shù)據(jù)庫btpdbs
? $ db2 uncatalog db btpdbs
????????????
查看版本
?? # db2level
顯示當前數(shù)據(jù)庫管理實例
?? $ db2 get instance
設置實例系統(tǒng)啟動時是否自動啟動。
?? $ db2iauto -on???? 自動啟動
?? $ db2iauto -off??? 不自動啟動
數(shù)據(jù)庫優(yōu)化命令:
?? reorg、runstats
?? 當數(shù)據(jù)庫經過一段時間使用,數(shù)據(jù)空間會變得越來越龐大。一些delete掉
?? 的數(shù)據(jù)仍存放在數(shù)據(jù)庫中,占用數(shù)據(jù)空間,影響系統(tǒng)性能。因此需要定期
?? 運行reorg、runstats命令,清除已delete的數(shù)據(jù),優(yōu)化數(shù)據(jù)結構。
?? db2 reorg table 表名
?? db2 runstats on table 表名 with distribution and indexes all
?? 因為要優(yōu)化的表比較多,所以在/btp/bin目錄下提供了一個sh程序runsall,
?? 可在當天業(yè)務結束后,運行runsall,對數(shù)據(jù)庫進行優(yōu)化?
更多文章、技術交流、商務合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
