{"id":15785,"date":"2023-12-04T22:46:44","date_gmt":"2023-12-04T14:46:44","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=15785"},"modified":"2023-12-04T22:53:20","modified_gmt":"2023-12-04T14:53:20","slug":"oracle-zhong-ru-he-ding-wei-zhong-yao-xiao-hao-zi","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/04\/oracle-zhong-ru-he-ding-wei-zhong-yao-xiao-hao-zi\/","title":{"rendered":"Oracle \u4e2d\u5982\u4f55\u5b9a\u4f4d\u91cd\u8981\uff08\u6d88\u8017\u8d44\u6e90\u591a\uff09\u7684 SQL?"},"content":{"rendered":"<p>\u5728 Oracle \u6570\u636e\u5e93\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e0d\u540c\u7684\u65b9\u6cd5\u6765\u5b9a\u4f4d\u6d88\u8017\u8d44\u6e90\u8f83\u591a\u7684 SQL \u8bed\u53e5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u65b9\u6cd5\uff1a<\/p>\n<h3><a id=\"1%E4%BD%BF%E7%94%A8%E5%8A%A8%E6%80%81%E6%80%A7%E8%83%BD%E8%A7%86%E5%9B%BE%EF%BC%88-dynamic-performance-views%EF%BC%89%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>1. <strong>\u4f7f\u7528\u52a8\u6001\u6027\u80fd\u89c6\u56fe\uff08Dynamic Performance Views\uff09\uff1a<\/strong><\/h3>\n<ul>\n<li>\u67e5\u8be2\u52a8\u6001\u6027\u80fd\u89c6\u56fe\u53ef\u4ee5\u83b7\u53d6\u6570\u636e\u5e93\u4e2d\u6b63\u5728\u6267\u884c\u7684 SQL \u8bed\u53e5\u4ee5\u53ca\u5b83\u4eec\u7684\u6267\u884c\u8ba1\u5212\u3001\u6d88\u8017\u8d44\u6e90\u7b49\u4fe1\u606f\u3002\u5176\u4e2d\uff0c<code>V$SQL<\/code> \u548c <code>V$SQLSTATS<\/code> \u89c6\u56fe\u662f\u6bd4\u8f83\u5e38\u7528\u7684\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-sql\">SELECT SQL_TEXT, EXECUTIONS, ELAPSED_TIME, CPU_TIME, FETCHES\nFROM V$SQL\nORDER BY ELAPSED_TIME DESC;\n<\/code><\/pre>\n<pre><code class=\"language-sql\">SELECT SQL_TEXT, EXECUTIONS, ELAPSED_TIME, CPU_TIME, FETCHES\nFROM V$SQLSTATS\nORDER BY ELAPSED_TIME DESC;\n<\/code><\/pre>\n<h3><a id=\"2%E4%BD%BF%E7%94%A8%E8%87%AA%E9%80%82%E5%BA%94-sql%E8%B7%9F%E8%B8%AA%EF%BC%88-adaptive-sql-tuning%EF%BC%89%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>2. <strong>\u4f7f\u7528\u81ea\u9002\u5e94 SQL \u8ddf\u8e2a\uff08Adaptive SQL Tuning\uff09\uff1a<\/strong><\/h3>\n<ul>\n<li>Oracle \u63d0\u4f9b\u4e86\u81ea\u9002\u5e94 SQL \u8ddf\u8e2a\u529f\u80fd\uff0c\u53ef\u4ee5\u81ea\u52a8\u8bc6\u522b\u548c\u8ddf\u8e2a\u9ad8\u6d88\u8017 SQL \u8bed\u53e5\u3002\u901a\u8fc7\u542f\u7528\u81ea\u9002\u5e94 SQL \u8ddf\u8e2a\uff0c\u6570\u636e\u5e93\u5f15\u64ce\u4f1a\u81ea\u52a8\u6536\u96c6\u548c\u62a5\u544a\u5173\u952e SQL \u8bed\u53e5\u7684\u6267\u884c\u8ba1\u5212\u548c\u6027\u80fd\u6570\u636e\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-sql\">ALTER SYSTEM SET OPTIMIZER_ADAPTIVE_REPORTING_ONLY=FALSE;\n<\/code><\/pre>\n<h3><a id=\"3%E4%BD%BF%E7%94%A8-sql%E4%BC%98%E5%8C%96%E5%B7%A5%E5%85%B7%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>3. <strong>\u4f7f\u7528 SQL \u4f18\u5316\u5de5\u5177\uff1a<\/strong><\/h3>\n<ul>\n<li>Oracle \u63d0\u4f9b\u4e86 SQL \u4f18\u5316\u5de5\u5177\uff0c\u4f8b\u5982 SQL Developer\u3001SQL Tuning Advisor \u7b49\uff0c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5206\u6790\u548c\u4f18\u5316 SQL \u8bed\u53e5\u3002\u8fd9\u4e9b\u5de5\u5177\u53ef\u4ee5\u7ed9\u51fa\u5efa\u8bae\uff0c\u5e76\u63d0\u4f9b\u6267\u884c\u8ba1\u5212\u3001\u7edf\u8ba1\u4fe1\u606f\u7b49\u3002<\/li>\n<\/ul>\n<h3><a id=\"4%E6%9F%A5%E7%9C%8B%E6%95%B0%E6%8D%AE%E5%BA%93%E7%9B%91%E8%A7%86%E5%92%8C%E8%B7%9F%E8%B8%AA%E6%96%87%E4%BB%B6%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>4. <strong>\u67e5\u770b\u6570\u636e\u5e93\u76d1\u89c6\u548c\u8ddf\u8e2a\u6587\u4ef6\uff1a<\/strong><\/h3>\n<ul>\n<li>Oracle \u6570\u636e\u5e93\u751f\u6210\u76d1\u89c6\u548c\u8ddf\u8e2a\u6587\u4ef6\uff0c\u5305\u62ec <code>trace<\/code> \u6587\u4ef6\u548c <code>alert<\/code> \u65e5\u5fd7\u3002\u8fd9\u4e9b\u6587\u4ef6\u4e2d\u8bb0\u5f55\u4e86\u6570\u636e\u5e93\u6d3b\u52a8\u3001\u6027\u80fd\u4fe1\u606f\u7b49\u3002\u53ef\u4ee5\u901a\u8fc7\u67e5\u770b\u8fd9\u4e9b\u6587\u4ef6\u6765\u5b9a\u4f4d\u6f5c\u5728\u7684\u6027\u80fd\u95ee\u9898\u3002<\/li>\n<\/ul>\n<h3><a id=\"5%E4%BD%BF%E7%94%A8-awr%E6%8A%A5%E5%91%8A%EF%BC%88-automatic-workload-repository%EF%BC%89%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>5. <strong>\u4f7f\u7528 AWR \u62a5\u544a\uff08Automatic Workload Repository\uff09\uff1a<\/strong><\/h3>\n<ul>\n<li>AWR \u662f Oracle \u63d0\u4f9b\u7684\u6027\u80fd\u76d1\u6d4b\u548c\u8c03\u6574\u5de5\u5177\u4e4b\u4e00\u3002\u53ef\u4ee5\u901a\u8fc7\u751f\u6210 AWR \u62a5\u544a\u6765\u5206\u6790\u6570\u636e\u5e93\u7684\u6027\u80fd\u72b6\u51b5\uff0c\u5305\u62ec\u9ad8\u6d88\u8017\u7684 SQL \u8bed\u53e5\u3001\u7b49\u5f85\u4e8b\u4ef6\u7b49\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-sql\">-- \u751f\u6210 AWR \u62a5\u544a\nSELECT * FROM TABLE(DBMS_WORKLOAD_REPOSITORY.AWR_REPORT_HTML(SYSTIMESTAMP - INTERVAL '30' MINUTE, SYSTIMESTAMP));\n<\/code><\/pre>\n<p>\u901a\u8fc7\u7ed3\u5408\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u53ef\u4ee5\u66f4\u5168\u9762\u5730\u4e86\u89e3\u6570\u636e\u5e93\u4e2d\u7684\u9ad8\u6d88\u8017 SQL \u8bed\u53e5\uff0c\u5e76\u91c7\u53d6\u76f8\u5e94\u7684\u4f18\u5316\u63aa\u65bd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Oracle \u6570\u636e\u5e93\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e0d\u540c\u7684\u65b9\u6cd5\u6765\u5b9a\u4f4d\u6d88\u8017\u8d44\u6e90\u8f83\u591a\u7684 SQL \u8bed\u53e5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u65b9\u6cd5\uff1a 1. [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[120],"tags":[],"class_list":["post-15785","post","type-post","status-publish","format-standard","hentry","category-oracel"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/15785","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=15785"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/15785\/revisions"}],"predecessor-version":[{"id":15786,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/15785\/revisions\/15786"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=15785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=15785"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=15785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}