﻿{"id":472,"date":"2015-04-17T12:33:54","date_gmt":"2015-04-17T04:33:54","guid":{"rendered":"http:\/\/www.llku.com\/?p=472"},"modified":"2015-04-17T12:33:54","modified_gmt":"2015-04-17T04:33:54","slug":"%e6%9f%a5%e5%87%ba%e4%bd%8e%e6%95%88%e7%9a%84sql","status":"publish","type":"post","link":"https:\/\/www.llku.com\/?p=472","title":{"rendered":"\u67e5\u51fa\u4f4e\u6548\u7684SQL"},"content":{"rendered":"<p>\n\t&#8211;\u67e5\u627e\u4f4e\u6548sql\n<\/p>\n<p>\n\tSELECT EXECUTIONS,<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DISK_READS,<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BUFFER_GETS,<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ROUND((BUFFER_GETS &#8211; DISK_READS) \/ BUFFER_GETS, 2) Hit_radio,<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ROUND(DISK_READS \/ EXECUTIONS, 2) Reads_per_run,<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SQL_TEXT<br \/>\n\t&nbsp; FROM V$SQLAREA<br \/>\n\t&nbsp;WHERE EXECUTIONS &gt; 0<br \/>\n\t&nbsp;&nbsp; AND BUFFER_GETS &gt; 0<br \/>\n\t&nbsp;&nbsp; AND (BUFFER_GETS &#8211; DISK_READS) \/ BUFFER_GETS &lt; 0.8<br \/>\n\t&nbsp;ORDER BY 4 DESC;\n<\/p>\n<p>\n\t&#8211;\u67e5\u627ebad sql\u7684\u65b9\u6cd5\uff1a\n<\/p>\n<p>\n\tselect *<br \/>\n\t&nbsp; from (select buffer_gets, sql_text<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; from v$sqlarea<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where buffer_gets &gt; 500000<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; order by buffer_gets desc)<br \/>\n\t&nbsp;where rownum &lt;= 30;\n<\/p>\n<p>\n\t&#8212;\u6267\u884c\u6b21\u6570\u591a\u7684SQL\uff1a\n<\/p>\n<p>\n\tselect sql_text, executions<br \/>\n\t&nbsp; from (select sql_text, executions from v$sqlarea order by executions desc)\n<\/p>\n<p>\n\t&nbsp;where rownum &lt; 81;\n<\/p>\n<p>\n\t&#8211;\u8bfb\u786c\u76d8\u591a\u7684SQL\uff1a\n<\/p>\n<p>\n\tselect sql_text, disk_reads<br \/>\n\t&nbsp; from (select sql_text, disk_reads from v$sqlarea order by disk_reads desc)\n<\/p>\n<p>\n\t&nbsp;where rownum &lt; 21;\n<\/p>\n<p>\n\t&#8211;\u6392\u5e8f\u591a\u7684SQL\uff1a\n<\/p>\n<p>\n\tselect sql_text, sorts<br \/>\n\t&nbsp; from (select sql_text, sorts from v$sqlarea order by sorts desc)\n<\/p>\n<p>\n\t&nbsp;where rownum &lt; 21;\n<\/p>\n<p>\n\t&#8211;\u5206\u6790\u7684\u6b21\u6570\u592a\u591a\uff0c\u6267\u884c\u7684\u6b21\u6570\u592a\u5c11\uff0c\u8981\u7528\u7ed1\u53d8\u91cf\u7684\u65b9\u6cd5\u6765\u5199sql\uff1a\n<\/p>\n<p>\n\tset pagesize 600;\n<\/p>\n<p>\n\tset linesize 120;\n<\/p>\n<p>\n\tselect substr(sql_text, 1, 80) &quot;sql&quot;, count(*), sum(executions) &quot;totexecs&quot;\n<\/p>\n<p>\n\t&nbsp; from v$sqlarea\n<\/p>\n<p>\n\t&nbsp;where executions &lt; 5\n<\/p>\n<p>\n\t&nbsp;group by substr(sql_text, 1, 80)\n<\/p>\n<p>\n\thaving count(*) &gt; 30\n<\/p>\n<p>\n\t&nbsp;order by 2;\n<\/p>\n<p>\n\t&#8211;\u6e38\u6807\u7684\u89c2\u5bdf\uff1a\n<\/p>\n<p>\n\tset pages 300;\n<\/p>\n<p>\n\tselect sum(a.value), b.name\n<\/p>\n<p>\n\t&nbsp; from v$sesstat a, v$statname b\n<\/p>\n<p>\n\t&nbsp;where a.statistic# = b.statistiC#<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>\n\t&nbsp;&nbsp; and b.name = &#39;opened cursors current&#39;\n<\/p>\n<p>\n\t&nbsp;group by b.name;\n<\/p>\n<p>\n\tselect count(0) from v$open_cursor;\n<\/p>\n<p>\n\tselect user_name, sql_text, count(0)<br \/>\n\t&nbsp; from v$open_cursor\n<\/p>\n<p>\n\t&nbsp;group by user_name, sql_text<br \/>\n\thaving count(0) &gt; 30;\n<\/p>\n<p>\n\t&#8211;\u67e5\u770b\u5f53\u524d\u7528\u6237&amp;username\u6267\u884c\u7684SQL\uff1a\n<\/p>\n<p>\n\tselect sql_text<br \/>\n\t&nbsp; from v$sqltext_with_newlines<br \/>\n\t&nbsp;where (hash_value, address) in<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (select sql_hash_value, sql_address<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; from v$session<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where username = &#39;&amp;username&#39;)<br \/>\n\t&nbsp;order by address, piece;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8211;\u67e5\u627e\u4f4e\u6548sql SELECT EXECUTIONS, &nbsp;&nbsp;&nbsp;&#038;nb &hellip; <a href=\"https:\/\/www.llku.com\/?p=472\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u67e5\u51fa\u4f4e\u6548\u7684SQL<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[84,83],"_links":{"self":[{"href":"https:\/\/www.llku.com\/index.php?rest_route=\/wp\/v2\/posts\/472"}],"collection":[{"href":"https:\/\/www.llku.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.llku.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.llku.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.llku.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=472"}],"version-history":[{"count":1,"href":"https:\/\/www.llku.com\/index.php?rest_route=\/wp\/v2\/posts\/472\/revisions"}],"predecessor-version":[{"id":473,"href":"https:\/\/www.llku.com\/index.php?rest_route=\/wp\/v2\/posts\/472\/revisions\/473"}],"wp:attachment":[{"href":"https:\/\/www.llku.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.llku.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.llku.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}