{"id":189322,"date":"2024-11-12T06:43:22","date_gmt":"2024-11-11T22:43:22","guid":{"rendered":"https:\/\/server.hk\/cnblog\/189322\/"},"modified":"2024-11-12T06:43:24","modified_gmt":"2024-11-11T22:43:24","slug":"%e9%80%9a%e9%81%8e%e9%a0%90%e7%86%b1%e4%be%86%e5%84%aa%e5%8c%96postgresql%e7%9a%84%e6%9f%a5%e8%a9%a2","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/189322\/","title":{"rendered":"\u901a\u904e\u9810\u71b1\u4f86\u512a\u5316PostgreSQL\u7684\u67e5\u8a62"},"content":{"rendered":"<h1 id=\"%e9%80%9a%e9%81%8e%e9%a0%90%e7%86%b1%e4%be%86%e5%84%aa%e5%8c%96postgresql%e7%9a%84%e6%9f%a5%e8%a9%a2-DTUblgONnE\">\u901a\u904e\u9810\u71b1\u4f86\u512a\u5316PostgreSQL\u7684\u67e5\u8a62<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u64da\u9a45\u52d5\u7684\u4e16\u754c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u6027\u80fd\u5c0d\u65bc\u61c9\u7528\u7a0b\u5e8f\u7684\u6574\u9ad4\u6548\u7387\u81f3\u95dc\u91cd\u8981\u3002PostgreSQL\u4f5c\u70ba\u4e00\u500b\u5f37\u5927\u7684\u958b\u6e90\u95dc\u4fc2\u578b\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u512a\u5316\u67e5\u8a62\u6027\u80fd\u7684\u6280\u8853\u3002\u5176\u4e2d\uff0c\u67e5\u8a62\u9810\u71b1\uff08Query Warmup\uff09\u662f\u4e00\u7a2e\u6709\u6548\u7684\u7b56\u7565\uff0c\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u67e5\u8a62\u7684\u97ff\u61c9\u901f\u5ea6\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u67e5\u8a62\u9810\u71b1\u7684\u6982\u5ff5\u3001\u5be6\u73fe\u65b9\u6cd5\u53ca\u5176\u5728PostgreSQL\u4e2d\u7684\u61c9\u7528\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e6%9f%a5%e8%a9%a2%e9%a0%90%e7%86%b1%ef%bc%9f-DTUblgONnE\">\u4ec0\u9ebc\u662f\u67e5\u8a62\u9810\u71b1\uff1f<\/h2>\n<p>\u67e5\u8a62\u9810\u71b1\u662f\u6307\u5728\u5be6\u969b\u67e5\u8a62\u57f7\u884c\u4e4b\u524d\uff0c\u901a\u904e\u57f7\u884c\u4e00\u4e9b\u6e96\u5099\u6027\u64cd\u4f5c\u4f86\u63d0\u9ad8\u67e5\u8a62\u7684\u6027\u80fd\u3002\u9019\u4e9b\u64cd\u4f5c\u901a\u5e38\u5305\u62ec\u52a0\u8f09\u6578\u64da\u5230\u7de9\u5b58\u4e2d\u3001\u5efa\u7acb\u7d22\u5f15\u4ee5\u53ca\u57f7\u884c\u8a08\u5283\u7684\u751f\u6210\u3002\u901a\u904e\u9019\u4e9b\u9810\u71b1\u6b65\u9a5f\uff0c\u53ef\u4ee5\u6e1b\u5c11\u67e5\u8a62\u57f7\u884c\u6642\u7684\u5ef6\u9072\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u5927\u578b\u6578\u64da\u96c6\u6642\u3002<\/p>\n<h2 id=\"%e6%9f%a5%e8%a9%a2%e9%a0%90%e7%86%b1%e7%9a%84%e5%a5%bd%e8%99%95-DTUblgONnE\">\u67e5\u8a62\u9810\u71b1\u7684\u597d\u8655<\/h2>\n<ul>\n<li><strong>\u63d0\u9ad8\u97ff\u61c9\u901f\u5ea6\uff1a<\/strong>\u901a\u904e\u5c07\u6578\u64da\u52a0\u8f09\u5230\u5167\u5b58\u4e2d\uff0c\u67e5\u8a62\u7684\u97ff\u61c9\u6642\u9593\u53ef\u4ee5\u986f\u8457\u964d\u4f4e\u3002<\/li>\n<li><strong>\u6e1b\u5c11I\/O\u64cd\u4f5c\uff1a<\/strong>\u9810\u71b1\u53ef\u4ee5\u6e1b\u5c11\u78c1\u789fI\/O\u64cd\u4f5c\uff0c\u5f9e\u800c\u63d0\u9ad8\u6574\u9ad4\u6027\u80fd\u3002<\/li>\n<li><strong>\u512a\u5316\u8cc7\u6e90\u4f7f\u7528\uff1a<\/strong>\u901a\u904e\u63d0\u524d\u52a0\u8f09\u6578\u64da\uff0c\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u5229\u7528\u7cfb\u7d71\u8cc7\u6e90\uff0c\u6e1b\u5c11\u9ad8\u5cf0\u6642\u6bb5\u7684\u8ca0\u8f09\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8postgresql%e4%b8%ad%e5%af%a6%e7%8f%be%e6%9f%a5%e8%a9%a2%e9%a0%90%e7%86%b1-DTUblgONnE\">\u5982\u4f55\u5728PostgreSQL\u4e2d\u5be6\u73fe\u67e5\u8a62\u9810\u71b1<\/h2>\n<p>\u5728PostgreSQL\u4e2d\u5be6\u73fe\u67e5\u8a62\u9810\u71b1\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u5e7e\u7a2e\u65b9\u6cd5\uff1a<\/p>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8explain%e5%91%bd%e4%bb%a4-DTUblgONnE\">1. \u4f7f\u7528EXPLAIN\u547d\u4ee4<\/h3>\n<p>\u5728\u57f7\u884c\u67e5\u8a62\u4e4b\u524d\uff0c\u53ef\u4ee5\u4f7f\u7528EXPLAIN\u547d\u4ee4\u4f86\u751f\u6210\u67e5\u8a62\u8a08\u5283\u3002\u9019\u4e0d\u50c5\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u7406\u89e3\u67e5\u8a62\u7684\u57f7\u884c\u65b9\u5f0f\uff0c\u9084\u53ef\u4ee5\u89f8\u767c\u4e00\u4e9b\u9810\u71b1\u64cd\u4f5c\u3002<\/p>\n<pre><code>EXPLAIN SELECT * FROM your_table WHERE your_condition;<\/code><\/pre>\n<h3 id=\"2-%e5%9f%b7%e8%a1%8c%e9%a0%90%e7%86%b1%e6%9f%a5%e8%a9%a2-DTUblgONnE\">2. \u57f7\u884c\u9810\u71b1\u67e5\u8a62<\/h3>\n<p>\u5728\u5be6\u969b\u67e5\u8a62\u4e4b\u524d\uff0c\u53ef\u4ee5\u57f7\u884c\u4e00\u4e9b\u76f8\u540c\u6216\u76f8\u4f3c\u7684\u67e5\u8a62\u4f86\u9810\u71b1\u6578\u64da\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u77e5\u9053\u67d0\u500b\u67e5\u8a62\u6703\u7d93\u5e38\u88ab\u57f7\u884c\uff0c\u53ef\u4ee5\u5728\u61c9\u7528\u555f\u52d5\u6642\u57f7\u884c\u4e00\u6b21\u8a72\u67e5\u8a62\u3002<\/p>\n<pre><code>SELECT * FROM your_table WHERE your_condition LIMIT 100;<\/code><\/pre>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8pg_prewarm%e6%93%b4%e5%b1%95-DTUblgONnE\">3. \u4f7f\u7528pg_prewarm\u64f4\u5c55<\/h3>\n<p>PostgreSQL\u63d0\u4f9b\u4e86\u4e00\u500b\u540d\u70bapg_prewarm\u7684\u64f4\u5c55\uff0c\u53ef\u4ee5\u5e6b\u52a9\u7528\u6236\u5c07\u8868\u6216\u7d22\u5f15\u7684\u9801\u9762\u52a0\u8f09\u5230\u5171\u4eab\u7de9\u5b58\u4e2d\u3002\u9019\u6a23\u53ef\u4ee5\u5728\u67e5\u8a62\u57f7\u884c\u4e4b\u524d\uff0c\u63d0\u524d\u5c07\u6578\u64da\u52a0\u8f09\u5230\u5167\u5b58\u4e2d\u3002<\/p>\n<pre><code>CREATE EXTENSION pg_prewarm;<\/code><\/pre>\n<p>\u7136\u5f8c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u9810\u71b1\u7279\u5b9a\u7684\u8868\uff1a<\/p>\n<pre><code>SELECT pg_prewarm('your_table');<\/code><\/pre>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-DTUblgONnE\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u96d6\u7136\u67e5\u8a62\u9810\u71b1\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u6027\u80fd\uff0c\u4f46\u4e5f\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li>\u9810\u71b1\u64cd\u4f5c\u53ef\u80fd\u6703\u6d88\u8017\u984d\u5916\u7684\u8cc7\u6e90\uff0c\u56e0\u6b64\u9700\u8981\u6839\u64da\u5be6\u969b\u60c5\u6cc1\u9032\u884c\u8abf\u6574\u3002<\/li>\n<li>\u4e0d\u7576\u7684\u9810\u71b1\u53ef\u80fd\u6703\u5c0e\u81f4\u7de9\u5b58\u6c61\u67d3\uff0c\u5f71\u97ff\u5176\u4ed6\u67e5\u8a62\u7684\u6027\u80fd\u3002<\/li>\n<li>\u61c9\u5b9a\u671f\u76e3\u63a7\u67e5\u8a62\u6027\u80fd\uff0c\u4ee5\u78ba\u4fdd\u9810\u71b1\u7b56\u7565\u7684\u6709\u6548\u6027\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-DTUblgONnE\">\u7e3d\u7d50<\/h2>\n<p>\u67e5\u8a62\u9810\u71b1\u662f\u4e00\u7a2e\u6709\u6548\u7684\u512a\u5316PostgreSQL\u67e5\u8a62\u6027\u80fd\u7684\u7b56\u7565\u3002\u901a\u904e\u5408\u7406\u5730\u4f7f\u7528EXPLAIN\u547d\u4ee4\u3001\u57f7\u884c\u9810\u71b1\u67e5\u8a62\u4ee5\u53ca\u5229\u7528pg_prewarm\u64f4\u5c55\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u67e5\u8a62\u7684\u97ff\u61c9\u901f\u5ea6\u548c\u7cfb\u7d71\u8cc7\u6e90\u7684\u5229\u7528\u6548\u7387\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6027\u80fd\u6578\u64da\u8655\u7406\u7684\u61c9\u7528\uff0c\u9019\u4e9b\u6280\u8853\u7121\u7591\u662f\u503c\u5f97\u8003\u616e\u7684\u9078\u64c7\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684\u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684\u6578\u64da\u5eab\u9700\u6c42\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u6216<a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\u4f86\u63d0\u5347\u60a8\u7684\u61c9\u7528\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u904e\u9810\u71b1\u6280\u8853\u512a\u5316PostgreSQL\u67e5\u8a62\uff0c\u63d0\u5347\u6027\u80fd\uff0c\u6e1b\u5c11\u5ef6\u9072\uff0c\u78ba\u4fdd\u6578\u64da\u5eab\u9ad8\u6548\u904b\u884c\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-189322","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/189322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=189322"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/189322\/revisions"}],"predecessor-version":[{"id":189323,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/189322\/revisions\/189323"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=189322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=189322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=189322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}