如何查看当前日志空间的使用情况
的有关信息介绍如下:DB2 在DATABASE级别有几个参数,如下决定了事物日志的使用空间大小Log file size (4KB) (LOGFILSIZ) = 60000Number of primary log files (LOGPRIMARY) = 16Number of secondary log files (LOGSECOND) = 200Changed path to log files (NEWLOGPATH) =Path to log files = /db2inst1_log01/sample如此我们可以计算分配给日志的空间大约是(200+16)*60000*4/1024/1024大约50GB。如果日志是单独的文件系统分区,我们在操作系统上即可看到日志空间使用情况,对日志使用情况进行监控,可以看到如下信息:$ df -gFilesystem GB blocks Free %Used Iused %Iused Mounted on/dev/db2inst1_log01 60.00 54.50 10% 1458 1% /db2inst1_log01这个需要登录到系统,其实db2pd也是可以看到日志信息的db2pd -d sample -logsDatabase Partition 0 -- Database SAMPLE -- Active -- Up 34 days 17:30:12 -- Date 2013-11-26-10.42.49.558342Logs:Current Log Number 117123 Pages Written 33697 Cur Commit Disk Log Reads 0 Cur Commit Total Log Reads 0 Method 1 Archive Status SuccessMethod 1 Next Log to Archive 117123 Method 1 First Failure n/aMethod 2 Archive Status n/aMethod 2 Next Log to Archive n/aMethod 2 First Failure n/aLog Chain ID 2 Current LSN 0x00001A2DDE649E70Address StartLSN State Size Pages Filename0x0700000177B795D0 00001A2CBFD88010 0x00000000 60000 60000 S0117104.LOG0x0700000177B806D0 00001A2CCE7E8010 0x00000000 60000 60000 S0117105.LOG0x0700000177B8B450 00001A2CDD248010 0x00000000 60000 60000 S0117106.LOG0x0700000177B82EF0 00001A2CEBCA8010 0x00000000 60000 60000 S0117107.LOG0x0700000177B9ECD0 00001A2CFA708010 0x00000000 60000 60000 S0117108.LOG0x0700000177BA27D0 00001A2D09168010 0x00000000 60000 60000 S0117109.LOG0x0700000177B79E30 00001A2D17BC8010 0x00000000 60000 60000 S0117110.LOG0x0700000177BAAD50 00001A2D26628010 0x00000000 60000 60000 S0117111.LOG0x0700000177B9FFD0 00001A2D35088010 0x00000000 60000 60000 S0117112.LOG0x0700000177BB44D0 00001A2D43AE8010 0x00000000 60000 60000 S0117113.LOG0x0700000177BD45D0 00001A2D52548010 0x00000000 60000 60000 S0117114.LOG0x0700000177B7F0D0 00001A2D60FA8010 0x00000000 60000 60000 S0117115.LOG0x0700000177B9C850 00001A2D6FA08010 0x00000000 60000 60000 S0117116.LOG0x0700000177B84750 00001A2D7E468010 0x00000000 60000 60000 S0117117.LOG0x0700000177B877D0 00001A2D8CEC8010 0x00000000 60000 60000 S0117118.LOG0x0700000177B857D0 00001A2D9B928010 0x00000000 60000 60000 S0117119.LOG0x0700000177B7DC50 00001A2DAA388010 0x00000000 60000 60000 S0117120.LOG0x0700000177B83750 00001A2DB8DE8010 0x00000000 60000 60000 S0117121.LOG0x0700000177B907B0 00001A2DC7848010 0x00000000 60000 60000 S0117122.LOG0x0700000177B91010 00001A2DD62A8010 0x00000000 60000 60000 S0117123.LOG0x0700000177B9A150 00001A2DE4D08010 0x00000000 60000 60000 S0117124.LOG不过之只能看到当前使用日志和日志文件对应的LSN信息和归档情况,对于使用率还真不能看到。另外还可以在实例快照中看到,不过在此不示例了。但是上面我们需要登录到操作系统上,如何在远端通过SQL查询呢,其实DB2还是提供了蛮多的方法。a.通过管理视图查询:select DB_NAME, LOG_UTILIZATION_PERCENT, TOTAL_LOG_USED_KB,TOTAL_LOG_AVAILABLE_KB,TOTAL_LOG_USED_TOP_KB, DBPARTITIONNUM from SYSIBMADM.LOG_UTILIZATION;DB_NAME LOG_UTILIZATION_PERCENT TOTAL_LOG_USED_KB TOTAL_LOG_AVAILABLE_KB TOTAL_LOG_USED_TOP_KB DBPARTITIONNUM-------------------------------------------------------------------------------------------------------------------------------- ----------------------- -------------------- ---------------------- --------------------- --------------DSS 8.97 4631824 46955050 16655013 0非常清楚一目了然吧,对于监控事物日志使用情况,及早发现事务日志空间满问题很有帮助。b.还有一种方法,就是查看快照视图:select int(total_log_used/1024/1024) as "Log Used (Mb)",int(total_log_available/1024/1024) as "Log Space Free(Mb)", int((float(total_log_used)/float(total_log_used+total_log_available))*100) as "Pct Used",int(tot_log_used_top/1024/1024) as "Max Log Used (Mb)", int(sec_log_used_top/1024/1024) as "Max Sec. Used (Mb)",int(sec_logs_allocated) as "Secondaries" from sysibmadm.snapdb;Log Used (Mb) Log Space Free(Mb) Pct Used Max Log Used (Mb) Max Sec. Used (Mb) Secondaries------------- ------------------ ----------- ----------------- ------------------ -----------4544 45833 9 16264 12532 51 record(s) selected.其实还有一种通过表函数的方法,不过需要带入参数:select DB_NAME,TOTAL_LOG_AVAILABLE,TOTAL_LOG_USED,SEC_LOG_USED_TOP,SEC_LOGS_ALLOCATED from table(SNAP_GET_DB('SAMPLE',0))DB_NAME TOTAL_LOG_AVAILABLE TOTAL_LOG_USED SEC_LOG_USED_TOP SEC_LOGS_ALLOCATED-------------------------------------------------------------------------------------------------------------------------------- -------------------- -------------------- -------------------- --------------------SAMPLE 48045192251 4779767749 13141773417 51 record(s) selected