DB2维护手册第2页共64页目录DB2维护手册..........................................................................................1一、DB2日常维护日操作...................................................................31、检查管理服务器是否启动................................................................32、检查DB2实例是否已经启动............................................................33、查看表空间状态是否正常................................................................34、查看表的状态.................................................................................75、查看磁盘空间.................................................................................86、检查存储管理软件是否正常...........................................................187、检查数据库备份是否正常..............................................................188、检查归档日志是否正确归档了........................................................199、查看缓冲池的命中率.....................................................................1910、查看当前运行最频繁的SQL,其命中率是否正常..........................2911、查看当前连接的应用程序,有没有非法连接.................................2912、检查有没有死锁.........................................................................3013、对表和索引进行RUNSTATS...........................................................3014、检查表是否需要重组..................................................................3015、对需要重组的表进行重组...........................................................31二、DB2日常维护月操作.................................................................311、查看DB2日志..............................................................................312、检查备份和日志是否都保存好了....................................................32三、DB2日常维护季度操作..............................................................331、通过快照监控器,查看系统性能如何..............................................332、数据库补丁级别............................................................................33四、注意事项..................................................................................331、不要删除活动日志文件..................................................................332、注意交易日志存储空间..................................................................333、按照系统的实际工作量配置日志空间..............................................344、设置正确数据库代码页..................................................................345、检查许可证(LICENSE)安装情况....................................................346、创建数据库前调整好系统时间........................................................357、不要随便执行CHOWN(CHMOD)–R(UNIX/LINUX)...........................358、在归档日志模式下使用LOAD记得加NONRECOVERABLE参数.........35五、附:以脱机方式重组表...............................................................35六、附:索引重组............................................................................36七、附:收集和更新统计信息的准则..................................................37八、附:使用CLP捕获数据库运行状况快照.....................................38第3页共64页一、DB2日常维护日操作1、检查管理服务器是否启动用ps命令查看是否有dasusr1后台进程:#ps-ef|grepdasusr1请确保管理服务器已经启动;如果没有启动,则按以下步骤启动管理服务器:以管理服务器用户(UNIX默认是DASUSR1)登录发出db2adminstart命令如果是HA环境,则要保证在脚本中正确配置了启动命令2、检查DB2实例是否已经启动用ps命令查看是否有db2sysc后台进程#ps-ef|grepdb2sysc也可以以DB2实例所有者登录,通过发出db2start命令来确保启动了实例(如果实例已经启动,则会告知SQL1026N数据库管理器已激活;否则,将把实例启动起来)3、查看表空间状态是否正常以db2实例所有者登录#db2listtablespacesshowdetail//在单分区上查看表空间的状态,正常返回0x0000#db2_alllisttablespacesshowdetail//在所有分区上查看表空间的状态可以使用LISTTABLESPACES命令确定连接数据库中表空间的当前状态,可以使用SHOWDETAIL选项查看表空间的详细信息。比如,我们连上SAMPLE数据库,执行db2listtablespacesshowdetail,可以看到状态返回值是0x0000,此时,使用db2tbst可以查看状态编号对于的状态含义,具体语法如下:db2tbsttablespacestate可以查看编号所代表的状态例如:[db2inst1@localhost~]$db2listtablespacesshowdetail第4页共64页TablespacesforCurrentDatabaseTablespaceID=0Name=SYSCATSPACEType=DatabasemanagedspaceContents=Allpermanentdata.Regulartablespace.State=0x0000Detailedexplanation:NormalTotalpages=12288Useablepages=12284Usedpages=9804Freepages=2480Highwatermark(pages)=9804Pagesize(bytes)=8192Extentsize(pages)=4Prefetchsize(pages)=4Numberofcontainers=1TablespaceID=1Name=TEMPSPACE1Type=SystemmanagedspaceContents=SystemTemporarydataState=0x0000Detailedexplanation:NormalTotalpages=1Useablepages=1Usedpages=1Freepages=NotapplicableHighwatermark(pages)=NotapplicablePagesize(bytes)=8192Extentsize(pages)=32Prefetchsize(pages)=32Numberofcontainers=1TablespaceID=2Name=USERSPACE1Type=DatabasemanagedspaceContents=Allpermanentdata.Largetablespace.State=0x0000Detailedexplanation:第5页共64页NormalTotalpages=4096Useablepages=4064Usedpages=1824Freepages=2240Highwatermark(pages)=1824Pagesize(bytes)=8192Extentsize(pages)=32Prefetchsize(pages)=32Numberofcontainers=1TablespaceID=3Name=IBMDB2SAMPLERELType=DatabasemanagedspaceContents=Allpermanentdata.Largetablespace.State=0x0000Detailedexplanation:NormalTotalpages=4096Useablepages=4064Usedpages=608Freepages=3456Highwatermark(pages)=608Pagesize(bytes)=8192Extentsize(pages)=32Prefetchsize(pages)=32Numberofcontainers=1TablespaceID=4Name=IBMDB2SAMPLEXMLType=DatabasemanagedspaceContents=Allpermanentdata.Largetablespace.State=0x0000Detailedexplanation:NormalTotalpages=4096Useablepages=4064Usedpages=1440Freepages=2624Highwatermark(pages)=1440Pagesize(bytes)=8192Extentsize(pages)=32第6页共64页Prefetchsize(pages)=32Numberofcontain