在使用DB2进行大量的update,insert,import的操作时候,事务日志可能会用光,即日志文件不够,还有一种情况是应用程序占用了很大的事务并且没有提交,造成后续应用不能重用日志,导致日志满。
针对上面两个问题,给出的解决方案如下:
1.日志文件不够
总共日志大小为:( LOGPRIMARY + LOGSECOND )* LOGFILSIZ * 4KB ,其中4KB为数据页,不同数据库设置的数据页可能不一样。
对一个表进行全表update时候,占用的最大事务空间约为表大小的2倍。这主要是事务日志记录了两种方式,do和redo。例如一张task表大小为160M,全表update时候所用到的最大日志空间约为320M。
如果觉得日志空间不够,可以用 db2 update db cfg for <dbname> using <p> <v>。例如要更改主日志大小:
db2 update db cfg for <dbname> using logprimary 30.
2.应用程序占用很大事务日志并且没有提交,造成后续操作不能重用日志。
针对这样相似的问题,我们通常先找到应用程序的ID,然后将应用程序停掉。
2.1用快照方式获取应用程序使用日志情况。
例如:
(1).打开监控开关:db2 update monitor switches using statement on uow on
(2).获取数据库快照:db2 get snapshot for database on <dbname>。找到快照中日志空间使用部分:
Log space available to the database (Bytes)= 20394939
Log space used by the database (Bytes) = 5061
Maximum secondary log space used (Bytes) = 0
Maximum total log space used (Bytes) = 12255
Secondary logs allocated currently = 0
Log pages read = 0
Log read time (sec.ns) = 0.000000004
Log pages written = 6
Log write time (sec.ns) = 0.000000004
Number write log IOs = 6
Number read log IOs = 0
Number partial page log IOs = 5
Number log buffer full = 0
Log data found in buffer = 0
Appl id holding the oldest transaction = 136
Log to be redone for recovery (Bytes) = 4923
Log accounted for by dirty pages (Bytes) = 4923
File number of first active log = 0
File number of last active log = 2
File number of current active log = 0
File number of log being archived = Not applicable
从快照信息中我们可以看到最后使用日志的应用程序的ID,如上图红色部分所示,即最后的应用程序的ID为136.
(3).获取应用程序的使用日志的详细信息。
db2 list applications
uth Id Application Appl. Application Id
DB # of
Name Handle
Name Agents
-------- -------------- ----------
-------------------------------------------------------------- --------
-----
E91Q3A db2bp 136 *LOCAL.e91q3a.120409075256
db2 " get snapshot for application applid *LOCAL.e91q3a.120409075256"
Application Snapshot
UOW log space used (Bytes) = 270
Previous UOW completion timestamp = 04/09/2012 15:52:57.581923
Elapsed time of last completed uow (sec.ms)= 0.465833
UOW start timestamp = 04/09/2012 15:53:25.545220
UOW stop timestamp =
UOW completion status =
(4)停止没有提交的应用程序。
db2 "force application(136)"
就这四步搞定,呵呵!
2.1使用db2pd来分析事务
(1).db2pd -db sampe -transactions/applications
(2).db2pd -db sample -dynamic查看是哪个SQL占据了大量的日志。
浙公网安备 33010602011771号