如何诊断和解决db2问题

参考书:
牛新庄:
Oracle数据库开发讲座—— Oracle9i Jdeveloper与J2EE实务应用
DB2应用开发实战指导
循序渐进DB2――DBA系统管理、运维与应用案例 http://www.ibm.com/developerworks/cn/data/books/db2mang/
DB2数据库性能调整和优化 http://www.ibm.com/developerworks/cn/data/books/db2perf/
深入解析DB2--高级管理、内部体系结构与诊断案例  http://www.ibm.com/developerworks/cn/data/books/db2advan/

=============================================
如何诊断和解决db2问题:
=============================================
1.对于常见的报错信息,运行db2 ?
db2 [? [phrase | message | sqlstate | class-code]]]

1)db2 ? :
DB2 ? SQLnnnn 显示这个SQLCODE的解释信息(SQLCODE   四位数字) db2 ? sql0440   db2 ? SQL10007N  注:code必须为4位数,不够4位,前面补0
DB2 ? DB2nnnn 显示这个DB2错误的解释信息
2)db2 ?
DB2 ? nnnnn 显示这个SQLSTATE的解释信息(SQLSTATE  5位数字) db2 ? 42734


2.收集db2diag.log,notification log, event log,dump file,trap file, core file:
db2support c:/temp -d adapter -a -g -l -r -s

如何清理db2diag.log文件
db2diag.log,是用来记录DB2数据库运行中的信息的文件。可以通过此文件,查看记录的有关DB2数据库详细的错误信息。此文件也是不断增大的,需要定期进行清理。
可以通过查看实例的配置参数DIAGPATH来确定db2diag.log文件是放在哪个目录下:db2 get dbm cfg. 如果Diagnostic data directory path(DIAGPATH) = /home/db2inst1/sqllib/db2dump,则此文件是放在/home/db2inst1/sqllib/db2dump目录下。当文件系统/home的使用率达到80%-90%左右时,应及时删除db2diag.log文件。
请按以下正确步骤操作:确认应用(如BTP)、DB2已经停止。
将原db2diag.log文件备份到其它文件系统下。
删除db2diag.log文件。删除后,DB2会自动创建一个新的文件。

3.db2pd -everything >c:/temp/db2pd.log  功能超级强大,由于db2pd可以直接从DB2的内存中读取信息,所以它比起snapshot来说开销更小,速度也更快
比如: db2pd -version -osinfo 查看db2version和机器信息
      db2pd -db adapter -dynamic 查看内存中的sql statements   ---------非常有用
   db2 get snapshot for dynamic sql on adapter >c:/temp/stmt.txt ---------非常有用
   db2 SELECT * FROM TABLE( SNAPSHOT_DYN_SQL( 'SAMPLE', -1 )) as SNAPSHOT_DYN_SQL  ---------非常有用
  
   db2pd  -db adapter -static
   db2 SELECT * FROM TABLE( SNAPSHOT_STATEMENT( 'SAMPLE', -1 )) as SNAPSHOT_STATEMENT
   db2 select * from syscat.statements
   .....

4.打开trace内容:
1)db2trc on -l 50M 打开db2 trace 收集最后的50M信息
2)reproduce问题
3)db2trc dmp c:/temp/db2trc.dmp
4)db2trc off
5)db2trc fmt c:/temp/db2trc.dmp 1.txt 得到一个按照process/thread排序的文本文件
6)db2trc flw c:/temp/db2trc.dmp 2.txt 得到一个按照时间先后排序的文本文件

5.离线收集数据:
db2dart adapter
db2dart adapter /TSI   (db2 list tablespaces 可以得到tablespaceId)
db2dart adapter /TSI /TN "customer"
db2dart adapter /TSI /MI /OI

6.在线收集数据:读取内存中东东
db2inspect check database results c:/temp/1.out
db2inspect check tbspaceid 2 results keep c:/temp/1.out
db2inspf c:/temp/1.out c:/temp/2.txt

7.db2cos.bat
编辑这个脚本里面的内容使得db2pd -everthing

8.db2pdcfg  指定发生什么事件的时候做什么事情。
db2pdcfg -db2cos on 当database manager trap的时候,自动call db2cos.bat
db2pdcfg -catch -911,2 当死锁发生的时候dump所有有用信息
db2pdcfg -catch -911,2 db2cos 当死锁发生的时候,call db2cos
db2pdcfg -catch -289 当tablespace full的时候,dump所有有用信息
db2pdcfg -fodc dumpshmem=on 在最近的一次数据库crash的情况下你怀疑内存corruption, 将shared memory全部dump出来。

9.db2fodc 指定当发生什么事情的时候,dump内容
1)db2pdcfg -fodc dumpshmem=on 在最近的一次数据库crash的情况下你怀疑内存corruption, 将shared memory全部dump出来。  or
  db2fodc -hang -alldb
  db2fodc -db adapter -hang full
2)运行db2support收集fodc数据: db2support c:/temp -d adapter -a -g -l -r -s

10.event monitor, activity monitor, snapshot:
1)如何使用snapshot:
C:/>db2 ? get snapshot
GET SNAPSHOT FOR {DATABASE MANAGER | ALL [DCS] DATABASES |
ALL [DCS] APPLICATIONS | ALL BUFFERPOOLS | [DCS] APPLICATION
{APPLID appl-id | AGENTID appl-handle} | FCM FOR ALL DBPARTITIONNUMS |
LOCKS FOR APPLICATION {APPLID appl-id | AGENTID appl-handle} |
{ALL | [DCS] DATABASE | [DCS] APPLICATIONS | TABLES |
TABLESPACES | LOCKS | BUFFERPOOLS | DYNAMIC SQL [write to file]}
ON database-alias} [AT DBPARTITIONNUM db-partition-number | GLOBAL]

NOTE: From the operating system prompt, prefix commands with 'db2'.
      Special characters MAY require an escape sequence (/), for example:
      db2 /? change database
      db2 ? change database xxx comment with /"text/"

db2 get snapshot for application agentid 2432;

11.用SQL语句实现DB2主要指标的监控 (参考Administrative SQL Routines and Views.pdf)
--Database manager:To capture a snapshot of database manager information:
SELECT * FROM TABLE( SNAPSHOT_DBM(-1)) as SNAPSHOT_DBM

--To capture a snapshot of database manager information specifically regarding the fast communication manager (FCM):
SELECT * FROM TABLE( SNAPSHOT_FCM(-1)) as SNAPSHOT_FCM

--To capture a snapshot of database manager information for a partition specifically regarding the fast communication manager(FCM):
SELECT * FROM TABLE( SNAPSHOT_FCMPARTITION(-1)) as SNAPSHOT_FCMPARTITION

--To capture the database manager's monitor switch settings:
SELECT * FROM TABLE( SNAPSHOT_SWITCHES(-1)) as SNAPSHOT_SWITCHES

--Database: To capture a snapshot of database information:
SELECT * FROM TABLE( SNAPSHOT_DATABASE( 'SAMPLE', -1 )) as SNAPSHOT_DATABASE

--Application:To capture a snapshot of application information:
SELECT * FROM TABLE( SNAPSHOT_APPL( 'SAMPLE', -1 )) as SNAPSHOT_APPL

--To capture a snapshot of application identification information:Chapter 3. Using the Snapshot Monitor 23
SELECT * FROM TABLE( SNAPSHOT_APPL_INFO( 'SAMPLE', -1 )) as SNAPSHOT_APPL_INFO

--To capture a snapshot of lock wait information:
SELECT * FROM TABLE( SNAPSHOT_LOCKWAIT('SAMPLE', -1 )) as SNAPSHOT_LOCKWAIT

--To capture a snapshot of statement information:
SELECT * FROM TABLE( SNAPSHOT_STATEMENT( 'SAMPLE', -1 )) as SNAPSHOT_STATEMENT

--Dynamic SQL cache: To capture a snapshot of dynamic SQL statement cache information:Snapshot monitor 24 System Monitor Guide and Reference
SELECT * FROM TABLE( SNAPSHOT_DYN_SQL( 'SAMPLE', -1 )) as SNAPSHOT_DYN_SQL

--To capture a snapshot of agent information:
SELECT * FROM TABLE( SNAPSHOT_AGENT( 'SAMPLE', -1 )) as SNAPSHOT_AGENT

--To capture a snapshot of subsection information:
SELECT * FROM TABLE( SNAPSHOT_SUBSECT( 'SAMPLE', -1 )) as SNAPSHOT_SUBSECT

--Buffer pool: To capture a snapshot of buffer pool information:
SELECT * FROM TABLE( SNAPSHOT_BP( 'SAMPLE', -1 )) as SNAPSHOT_BP

--Table space:To capture a snapshot of table space information:
SELECT * FROM TABLE( SNAPSHOT_TBS( 'SAMPLE', -1 )) as SNAPSHOT_TBS

--To capture a snapshot of table space configuration information:
SELECT * FROM TABLE( SNAPSHOT_TBS_CFG( 'SAMPLE', -1 )) as SNAPSHOT_TBS_CFG

--To capture a snapshot of table space quiescer information:
SELECT * FROM TABLE( SNAPSHOT_QUIESCER( 'SAMPLE', -1 )) as SNAPSHOT_QUIESCER

--To capture a snapshot of table space container configuration information:
SELECT * FROM TABLE( SNAPSHOT_CONTAINER( 'SAMPLE', -1 )) as SNAPSHOT_CONTAINER

--To capture a snapshot of the ranges for a table space map:
SELECT * FROM TABLE( SNAPSHOT_RANGES( 'SAMPLE', -1 )) as SNAPSHOT_RANGES

--Table: To capture a snapshot of table information:
SELECT * FROM TABLE( SNAPSHOT_TABLE( 'SAMPLE', -1 )) as SNAPSHOT_TABLE

--Lock: To capture a snapshot of lock information:
SELECT * FROM TABLE( SNAPSHOT_LOCK( 'SAMPLE', -1 )) as SNAPSHOT_LOCK


<.
db2_all.bat
db2_kill.bat
db2am.bat
db2ca.bat
db2cc.bat
db2cctrc.bat
db2ce.bat
db2cos.bat
db2cos_datacorruption.bat
db2cos_hang.bat
db2cos_perf.bat
db2cos_trap.bat
db2cw.bat
db2cwadmin.bat
db2env.bat
db2envar.bat
db2eva.bat
db2hc.bat
db2ic.bat
db2indbt.bat
db2journal.bat
db2lc.bat
db2memvis.bat
db2rc.bat
db2setcp.bat
db2tc.bat
db2unins.bat
db2vsregister.bat
db2vsrgx.bat
db2vsurgx.bat
db2wrapperconfig.bat
dxxadmin.cmd
asnacmd.exe
asnadmt.exe
asnanalyze.exe
asnapply.exe
asncap.exe
asnccmd.exe
asnclp.exe
ASNDONE.exe
ASNLOAD.exe
asnmail.exe
asnmcmd.exe
asnmig4c.exe
asnmig8.exe
asnmigpw.exe
asnmon.exe
asnpwd.exe
asnqacmd.exe
asnqanalyze.exe
asnqapp.exe
asnqcap.exe
asnqccmd.exe
asnqmfmt.exe
asnscrt.exe
asnsdrop.exe
asnserv.exe
asnslist.exe
asntdiff.exe
asntrc.exe
asntrcbp.exe
asntrep.exe
cc390ve.exe
dasmigr.exe
dasupdt.exe
db2.exe
db2_aram.exe
db2admin.exe
db2adutl.exe
db2advis.exe
db2audit.exe
db2batch.exe
db2bddbg.exe
db2bddbgsvc.exe
db2bfd.exe
db2bp.exe
db2cap.exe
db2cat.exe
db2cfexp.exe
db2cfimp.exe
db2ckbkp.exe
db2ckrst.exe
db2clpex.exe
db2clpsetcp.exe
db2cmd.exe
db2cmdadmin.exe
db2cmnclp.exe
db2cmnseh.exe
db2dart.exe
db2dascln.exe
db2daslevel.exe
db2dasrrm.exe
db2dasstm.exe
db2dclgn.exe
db2demigdbd.exe
db2diag.exe
db2disable_soap_udf.exe
db2drdat.exe
db2drvmp.exe
db2empfa.exe
db2enable_soap_udf.exe
db2envgen.exe
db2evmon.exe
db2evtbl.exe
db2exfmt.exe
db2exmig.exe
db2expln.exe
db2extsec.exe
db2flsn.exe
db2fmp.exe
db2fodc.exe
db2fopt.exe
db2fs.exe
db2gcf.exe
db2genp.exe
db2getinstalllog.exe
db2gov.exe
db2govd.exe
db2govds.exe
db2govlg.exe
db2gpmap.exe
db2icdocs.exe
db2iclus.exe
db2icons.exe
db2icrt.exe
db2idrop.exe
db2igp.exe
db2ilist.exe
db2imaudcfg.exe
db2imdbd.exe
db2imigr.exe
db2imnod.exe
db2inidb.exe
db2inspf.exe
db2iupdt.exe
db2javit.exe
db2javitCmd.exe
db2jcc.exe
db2jdbcbind.exe
db2ldcfg.exe
db2ldreg.exe
db2level.exe
db2licd.exe
db2licm.exe
db2listvolumes.exe
db2logsForRfwd.exe
db2look.exe
db2lspwd.exe
db2lswtch.exe
db2lueff.exe
db2mgmtsvc.exe
db2move.exe
db2mqCheck.exe
db2mqlsn.exe
db2mscs.exe
db2mtrk.exe
db2nchg.exe
db2ncrt.exe
db2ndmgr.exe
db2ndrop.exe
db2ndscv.exe
db2nkill.exe
db2nlist.exe
db2nmpcfg.exe
db2nmpsetup.exe
db2nstck.exe
db2pd.exe
db2pdcfg.exe
db2pdraw.exe
db2perfc.exe
db2perfi.exe
db2perfr.exe
db2pgixt.exe
db2profc.exe
db2profp.exe
db2rappl.exe
db2ras.exe
db2rbind.exe
db2rcmd.exe
db2rcmdc.exe
db2recri.exe
db2regfile.exe
db2reggv.exe
db2regsc.exe
db2relocatedb.exe
db2remot.exe
db2rfpen.exe
db2rspgn.exe
db2sampl.exe
db2schex.exe
db2se.exe
db2sec.exe
db2secv82.exe
db2set.exe
db2setres.exe
db2sqljbind.exe
db2sqljcustomize.exe
db2sqljprint.exe
db2star2.exe
db2start.exe
db2stat.exe
db2stop.exe
db2stop2.exe
db2support.exe
db2swtch.exe
db2swtchg.exe
db2sysc.exe
db2syscs.exe
db2systray.exe
db2tapemgr.exe
db2tbst.exe
db2tdbmgr.exe
db2trc.exe
db2trcd.exe
db2trcsc.exe
db2uiddl.exe
db2untag.exe
db2usvce.exe
db2vshelpreg.exe
db2vsreg.exe
db2wolfi.exe
db2xdbmig.exe
db2xdbsg.exe
db2xprt.exe
ddcspkgn.exe
ddcstrc.exe
disable_MQFunctions.exe
disable_MQXML.exe
dxxadm.exe
dxxgenx.exe
dxxgenxb.exe
dxxgenxc.exe
dxxisrt.exe
dxxlevel.exe
dxxMigv.exe
dxxretr.exe
dxxretr2.exe
dxxretrc.exe
dxxshrd.exe
dxxtrc.exe
dynexpln.exe
enable_MQFunctions.exe
enable_MQXML.exe
gseidx.exe
insertx.exe
killdb2.exe
ktdscvr.exe
pctn.exe
pctt.exe
profconv.exe
profdb.exe
profp.exe
rah.exe
retrieve.exe
retrieve2.exe
retrievec.exe
sdscvr.exe
shred.exe
sqlj.exe
strtstep.exe
tbscont.exe
testconn11.exe
testconn20.exe
tests2x.exe
tests2xb.exe
tests2xc.exe

 

你可能感兴趣的:(db2,table,database,manager,application,sql,数据库)