avinliu 发表于 2011-12-22 08:54

索引监控(实际应用)

<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="FONT-SIZE: 9pt; FONT-FAMILY: Verdana"></SPAN>&nbsp;</P><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri">索引监控</SPAN> <SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Cambria; mso-hansi-font-family: Cambria">目的</SPAN>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; tab-stops: 50.25pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">应用程序在开发时,可能会建立众多索引,但是这些索引的使用情况,是否有些索引一直都没有用到过,这需要我们对这些索引进行监控,以便确定他们的使用情况,并为是否可以清除它们给出依据。</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt"></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; tab-stops: 50.25pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">认为</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">oracle</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">数据库使用的索引不会超过设计时创建索引总数的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">25%,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">或者不以它们被期望的使用方式使用</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">.</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">在实际应用中</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">调优速度较慢的查询时</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">经常发现执行的</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">sql</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">调用了垃圾索引</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">而不是我们设计时建立的索引</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">.</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">所以我们有必要通过监控数据库索引的使用</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">释放那些未被使用的索引</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">从而节省维护索引的开销</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">,</SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">优化性能</SPAN><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">.</SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US><A href="http://blog.csdn.net/47522341/archive/2008/09/22/2962144.aspx" target=_blank><FONT face="Times New Roman">http://blog.csdn.net/47522341/archive/2008/09/22/2962144.aspx</FONT></A></SPAN></P>
<P><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Cambria; mso-hansi-font-family: Cambria">具体步骤</SPAN> </P>
<P><FONT size=4><STRONG><SPAN lang=EN-US style="mso-bidi-font-family: 宋体"><SPAN style="mso-list: Ignore"><FONT face=Calibri>一、</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri">开启索引监控</SPAN> </STRONG></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt"><FONT size=2>SELECT 'alter index ' || OWNER || '.' || INDEX_NAME || ' monitoring usage;'</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FROM DBA_INDEXES</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>WHERE INDEX_TYPE = 'NORMAL'</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt"><FONT size=2><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>AND owner IN ('USER1','USER2');</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri></FONT></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">开启数据库索引监控</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">查找用户</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt"><FONT color=#f00000>select * from dba_users where username not in ('SYS','SYSTEM','OUTLN','AURORA\$JIS\$UTILITY\$');</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt"><FONT color=#f00000></FONT></SPAN>&nbsp;</P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo1; mso-char-indent-count: 0"><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Wingdings; mso-fareast-font-family: Wingdings"><SPAN style="mso-list: Ignore">l<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">数据库1涉及下列用户,共</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>1354</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">个索引</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0"><SPAN lang=EN-US><FONT face=Calibri>'BD','CECFJS','CECFMEMO','CRM','DRAGON','FAIRPORT','DBSNMP','CUSTOMDATA',</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0"><SPAN lang=EN-US><FONT face=Calibri>'GJHPHONE','IMPMEMO','INVOICEPUBLIC','MEMOTOSQL','MGMT_VIEW',</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0"><SPAN lang=EN-US><FONT face=Calibri>'NEWZJ','PAY_MANAGE','SUMCONTRACT','TEST'</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: -21pt; mso-list: l1 level1 lfo1; mso-char-indent-count: 0"><SPAN lang=EN-US style="FONT-FAMILY: Wingdings; mso-bidi-font-family: Wingdings; mso-fareast-font-family: Wingdings"><SPAN style="mso-list: Ignore">l<SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri">数据库2涉及下列用户,共</SPAN><SPAN lang=EN-US><FONT face=Calibri>196</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri">个索引</SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0"><SPAN lang=EN-US><FONT face=Calibri>'BD','CHECKTICKT','DBSNMP','MGMT_VIEW','TEST' ,'WL'</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0"><SPAN lang=EN-US><FONT face=Calibri></FONT></SPAN>&nbsp;</P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0"><SPAN lang=EN-US><FONT face=Calibri>查询出用户表,并编成<SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">开启数据库索引监控脚本</SPAN></P></FONT></SPAN>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0"><SPAN lang=EN-US>alter index DBSNMP.MGMT_DB_FILE_GTT_PK monitoring usage;</SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0"><SPAN lang=EN-US>....</SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 21pt; TEXT-INDENT: 0cm; mso-char-indent-count: 0"><SPAN lang=EN-US>....<BR>alter index DBSNMP.MGMT_DB_SIZE_GTT_PK monitoring usage;</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face=Calibri></FONT></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri">说明:按照服务器的性能,监控不会影响应用,不过如果相关应用缓慢,将立即关闭监控。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri">监控将一直持续到高峰结束。</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"></SPAN>&nbsp;</P><FONT size=4><STRONG><SPAN lang=EN-US style="mso-bidi-font-family: 宋体"><SPAN style="mso-list: Ignore"><FONT face=Cambria>二、</FONT><SPAN style="FONT: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN></SPAN></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Cambria; mso-hansi-font-family: Cambria">生成监控视图</SPAN></STRONG></FONT>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">监视</SPAN></U></B><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">到</SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">索引</SPAN></U></B><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">的使用信息被存储在</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt"> V$OBJECT_USAGE </SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">视图中。</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt"></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">视图中的一些列的具体含义:</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt"><BR>INDEX_NAME: sys.obj$.name</SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">中</SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">索引</SPAN></U></B><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">的名字。</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt"><BR>TABLE_NAME: sys.obj$obj$name</SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">中表的名字。</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt"><BR>MONITORING: YES (</SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">索引</SPAN></U></B><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">正在被</SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">监视</SPAN></U></B><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">), NO (</SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">索引</SPAN></U></B><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">没有被</SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">监视</SPAN></U></B><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">)<BR>USED: YES</SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">(</SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">索引</SPAN></U></B><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">被使用了)</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt"> NO (</SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">索引</SPAN></U></B><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">没有被使用</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">)<BR>START_MONITORING: </SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">监视</SPAN></U></B><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">开始的时间。</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt"><BR>END_MONITORING: </SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">监视</SPAN></U></B><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">结束的时间。</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt"><BR></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">所有被使用过的</SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">索引</SPAN></U></B><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">,哪怕被用过一次也会显示在这个视图中。但一个用户只能</SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">监视</SPAN></U></B><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">他自己模式中</SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">索引</SPAN></U></B><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">的使用情况。</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">ORACLE</SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">没有提供</SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">监视</SPAN></U></B><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">所有模式中的</SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">索引</SPAN></U></B><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">的功能。要想</SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">监视</SPAN></U></B><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">所有模式中的</SPAN><B><U><SPAN style="COLOR: red; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">索引</SPAN></U></B><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">的使用情况,请用</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">SYS</SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">登录。执行下列脚本。</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt"></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">CREATE OR REPLACE VIEW SYS.V$ALL_OBJECT_USAGE</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">(</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">OWNER,</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">INDEX_NAME,</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">TABLE_NAME,</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">MONITORING,</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">USED,</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">START_MONITORING,</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">END_MONITORING</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">)</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">AS</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">select u.name, io.name, t.name,</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">decode(bitand(i.flags, 65536), 0, 'NO', 'YES'),</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">decode(bitand(ou.flags, 1), 0, 'NO', 'YES'),</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">ou.start_monitoring,</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left" align=left><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">ou.end_monitoring</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">from sys.obj$ io, sys.obj$ t, sys.ind$ i, sys.object_usage ou, sys.user$ u</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">where i.obj# = ou.obj#</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">and io.obj# = ou.obj#</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">and t.obj# = i.bo#</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">and io.owner# = u.user#</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">/</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">COMMENT ON TABLE SYS.V$ALL_OBJECT_USAGE IS</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">'Record of all index usage - developed by liu'</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">/</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-family: Courier; mso-font-kerning: 0pt">GRANT SELECT ON SYS.V$ALL_OBJECT_USAGE TO "PUBLIC"<BR>/<BR>CREATE PUBLIC SYNONYM V$ALL_OBJECT_USAGE<BR>FOR SYS.V$ALL_OBJECT_USAGE<BR>/</SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face=Calibri></FONT></SPAN>&nbsp;</P><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"><FONT size=4><STRONG>三、停止监控</STRONG></FONT></SPAN>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri">执行以下查询</SPAN><SPAN lang=EN-US><FONT face=Calibri>,</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri">确认监控结束</SPAN><SPAN lang=EN-US><FONT face=Calibri>,</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri">一定切记终止索引监控</SPAN><SPAN lang=EN-US><FONT face=Calibri>,</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri">因为监控也会使用一定的资源</SPAN><SPAN lang=EN-US><FONT face=Calibri>.</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri">返回记录条数为</SPAN><SPAN lang=EN-US><FONT face=Calibri>0</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri">表示监控已终止</SPAN><SPAN lang=EN-US><FONT face=Calibri>.</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US><FONT face=Calibri></FONT></SPAN>&nbsp;</P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US><FONT face=Calibri>SELECT INDEX_NAME, MONITORING, USED, START_MONITORING, END_MONITORING</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US><FONT face=Calibri><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FROM V$OBJECT_USAGE</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US><FONT face=Calibri><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>WHERE end_monitoring IS NULL;</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><FONT face=Calibri></FONT></SPAN>&nbsp;</P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: 0cm; tab-stops: 50.25pt; mso-char-indent-count: 0"><SPAN lang=EN-US style="FONT-SIZE: 9pt; COLOR: black; FONT-FAMILY: Verdana"></SPAN>&nbsp;</P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: 0cm; tab-stops: 50.25pt; mso-char-indent-count: 0"><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">已生成停止监控的脚本。</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt"></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: 0cm; tab-stops: 50.25pt; mso-char-indent-count: 0"><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">关闭索引监控</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">(</SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">从开启监控中得出停止监控的脚本</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">)</SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: 0cm; tab-stops: 50.25pt; mso-char-indent-count: 0"><I><SPAN lang=EN-US style="COLOR: #ff0102; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">&nbsp;</SPAN></I><I><SPAN style="COLOR: #ff0102; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">注:使用</SPAN></I><I><SPAN lang=EN-US style="COLOR: #ff0102; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt">alter index &lt;INDEX_NAME&gt; nomonitoring usage</SPAN></I><I><SPAN style="COLOR: #ff0102; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt">取消监控。</SPAN></I></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: 0cm; tab-stops: 50.25pt; mso-char-indent-count: 0"><I><SPAN style="COLOR: #ff0102; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt"></SPAN></I><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt"></SPAN>&nbsp;</P><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri"><FONT size=4><STRONG>四、生成监控报表</STRONG></FONT></SPAN>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">找出那些没有使用过的索引</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>.</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>SELECT INDEX_NAME,table_name, MONITORING, USED, START_MONITORING, END_MONITORING</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FROM V$OBJECT_USAGE</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>WHERE USED = 'NO';</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri></FONT></SPAN>&nbsp;</P><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">找出那些使用过的索引</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>.</FONT></SPAN></P></FONT></SPAN>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="BACKGROUND: white; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Courier; mso-font-kerning: 0pt; mso-highlight: white">&nbsp;&nbsp;&nbsp;select</SPAN><SPAN lang=EN-US style="BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Courier; mso-font-kerning: 0pt; mso-highlight: white"> * </SPAN><SPAN lang=EN-US style="BACKGROUND: white; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Courier; mso-font-kerning: 0pt; mso-highlight: white">from</SPAN><SPAN lang=EN-US style="BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Courier; mso-font-kerning: 0pt; mso-highlight: white"> </SPAN><SPAN lang=EN-US style="BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-highlight: white">V$ALL_OBJECT_USAGE</SPAN><SPAN lang=EN-US style="BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Courier; mso-font-kerning: 0pt; mso-highlight: white"> </SPAN><SPAN lang=EN-US style="BACKGROUND: white; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Courier; mso-font-kerning: 0pt; mso-highlight: white">where</SPAN><SPAN lang=EN-US style="BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Courier; mso-font-kerning: 0pt; mso-highlight: white"> used</SPAN><SPAN lang=EN-US style="BACKGROUND: white; COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Courier; mso-font-kerning: 0pt; mso-highlight: white">=</SPAN><SPAN lang=EN-US style="BACKGROUND: white; COLOR: red; FONT-FAMILY: Courier; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Courier; mso-font-kerning: 0pt; mso-highlight: white">'YES'</SPAN><SPAN lang=EN-US style="COLOR: red; FONT-FAMILY: Courier; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Courier; mso-font-kerning: 0pt"></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri></FONT></SPAN>&nbsp;</P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">找出之后要判断哪些是我们建立时希望他使用的</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>,</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">根据找出的表名称</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>table_name</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">我们可以到</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>dba_source</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">中找出那些使用到这个表的查询语句</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>.</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">针对这些语句执行优化操作</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>.</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri></FONT></SPAN>&nbsp;</P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>SELECT ds.owner||'.'||ds.NAME OName,ds.type,ds.line,ds.text</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FROM DBA_SOURCE DS</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>WHERE INSTR(UPPER(DS.TEXT), UPPER('&amp;</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">请输入要检索的对象名称</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>')) &gt; 0<SPAN style="mso-spacerun: yes">&nbsp; </SPAN>;</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US style="COLOR: blue; FONT-FAMILY: Courier; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: Courier; mso-font-kerning: 0pt"></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 12pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">这个应该是</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">index monitor</SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">后的结果</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">,</SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">还需要查</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">v$sql_plan</SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">中是否有人使用过该索引</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">,</SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">如果要删除</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">,</SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">也要在晚上</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">,</SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">否则一旦出现问题</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">,</SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">就会引起宕机</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">...</SPAN></P><FONT size=4><STRONG><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Cambria; mso-hansi-font-family: Cambria">五</SPAN><SPAN style="LINE-HEIGHT: 173%; FONT-FAMILY: 宋体; mso-ascii-font-family: Cambria; mso-hansi-font-family: Cambria; mso-bidi-font-size: 9.0pt">、改进措施</SPAN></STRONG></FONT><SPAN lang=EN-US style="LINE-HEIGHT: 173%; mso-bidi-font-size: 9.0pt"></SPAN>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>1, </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">对一些检索比较频繁的表</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>,</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">找出系统中引用该表的查询语句</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>,</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">查看其执行计划</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>,</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">检索是否使用正确索引</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>;</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>2,</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">如果已经使用正确索引</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>,</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">则考虑通过重建索引等手段查看是否能提高查询速度</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>;</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>3,</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">如果索引确实无法增加数据检索的速度</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>,</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">则清除之</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>3, </FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">经过合适的时间</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>(</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">比如一个星期</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>)</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">之后我们可以继续下面的步骤</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>,</FONT></SPAN><SPAN style="FONT-FAMILY: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-size: 10.5pt">首先我们可以查看一下索引的使用比率</SPAN><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>.</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri>SELECT ROUND(100 * SUM(DECODE(USED, 'YES', 1, 0)) / COUNT(INDEX_NAME), 2)</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>FROM V$OBJECT_USAGE;</FONT></SPAN></P>
<P class=ListParagraph style="MARGIN: 0cm 0cm 0pt 18pt; tab-stops: 50.25pt"><SPAN lang=EN-US style="mso-bidi-font-size: 10.5pt"><FONT face=Calibri></FONT></SPAN>&nbsp;</P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 12pt; TEXT-ALIGN: left; mso-pagination: widow-orphan" align=left><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">select * from v$object_usage;<BR></SPAN><SPAN style="COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt">只是当前用户下有效,只能看到当前用户下的监视索引。</SPAN><SPAN lang=EN-US style="COLOR: black; FONT-FAMILY: Verdana; mso-bidi-font-size: 10.5pt; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt"></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN lang=EN-US><A href="http://www.itpub.net/viewthread.php?tid=597992&amp;highlight=%BC%E0%CA%D3%2B%CB%F7%D2%FD" target=_blank><FONT face=Calibri color=#800080>http://www.itpub.net/viewthread.php?tid=597992&amp;highlight=%BC%E0%CA%D3%2B%CB%F7%D2%FD</FONT></A></SPAN></P>
页: [1]
查看完整版本: 索引监控(实际应用)