{"id":96892,"date":"2024-10-20T13:14:17","date_gmt":"2024-10-20T05:14:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/96892\/"},"modified":"2024-10-20T13:14:17","modified_gmt":"2024-10-20T05:14:17","slug":"postgresql-%e4%b8%ad%e7%9a%84%e4%b8%a6%e7%99%bc%e5%89%b5%e5%bb%ba%e7%b4%a2%e5%bc%95","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/96892\/","title":{"rendered":"PostgreSQL \u4e2d\u7684\u4e26\u767c\u5275\u5efa\u7d22\u5f15"},"content":{"rendered":"<h1 id=\"postgresql-%e4%b8%ad%e7%9a%84%e4%b8%a6%e7%99%bc%e5%89%b5%e5%bb%ba%e7%b4%a2%e5%bc%95-ZPcFUQYEjf\">PostgreSQL \u4e2d\u7684\u4e26\u767c\u5275\u5efa\u7d22\u5f15<\/h1>\n<p>\u5728\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0c\u7d22\u5f15\u662f\u4e00\u7a2e\u91cd\u8981\u7684\u6578\u64da\u7d50\u69cb\uff0c\u7528\u65bc\u52a0\u901f\u67e5\u8a62\u64cd\u4f5c\u3002PostgreSQL \u4f5c\u70ba\u4e00\u500b\u529f\u80fd\u5f37\u5927\u7684\u958b\u6e90\u6578\u64da\u5eab\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u7d22\u5f15\u985e\u578b\u548c\u5275\u5efa\u7d22\u5f15\u7684\u65b9\u5f0f\u3002\u5728\u9ad8\u4e26\u767c\u74b0\u5883\u4e0b\uff0c\u5982\u4f55\u6709\u6548\u5730\u5275\u5efa\u7d22\u5f15\u6210\u70ba\u4e86\u4e00\u500b\u91cd\u8981\u7684\u8ab2\u984c\u3002\u672c\u6587\u5c07\u63a2\u8a0e PostgreSQL \u4e2d\u7684\u4e26\u767c\u5275\u5efa\u7d22\u5f15\u7684\u539f\u7406\u3001\u65b9\u6cd5\u53ca\u5176\u512a\u52e2\u3002<\/p>\n<h2 id=\"%e4%b8%a6%e7%99%bc%e5%89%b5%e5%bb%ba%e7%b4%a2%e5%bc%95%e7%9a%84%e5%8e%9f%e7%90%86-ZPcFUQYEjf\">\u4e26\u767c\u5275\u5efa\u7d22\u5f15\u7684\u539f\u7406<\/h2>\n<p>\u5728 PostgreSQL \u4e2d\uff0c\u5275\u5efa\u7d22\u5f15\u7684\u904e\u7a0b\u901a\u5e38\u6703\u9396\u5b9a\u8868\uff0c\u9019\u6703\u5c0e\u81f4\u5176\u4ed6\u67e5\u8a62\u548c\u6578\u64da\u4fee\u6539\u64cd\u4f5c\u88ab\u963b\u585e\u3002\u70ba\u4e86\u89e3\u6c7a\u9019\u500b\u554f\u984c\uff0cPostgreSQL \u63d0\u4f9b\u4e86 <code>CONCURRENTLY<\/code> \u9078\u9805\uff0c\u5141\u8a31\u5728\u4e0d\u9396\u5b9a\u8868\u7684\u60c5\u6cc1\u4e0b\u5275\u5efa\u7d22\u5f15\u3002\u9019\u610f\u5473\u8457\u5728\u5275\u5efa\u7d22\u5f15\u7684\u904e\u7a0b\u4e2d\uff0c\u5176\u4ed6\u7528\u6236\u4ecd\u7136\u53ef\u4ee5\u5c0d\u8868\u9032\u884c\u67e5\u8a62\u548c\u66f4\u65b0\u64cd\u4f5c\u3002<\/p>\n<h2>\u4f7f\u7528 <code>CREATE INDEX CONCURRENTLY<\/code><\/h2>\n<p>\u8981\u4f7f\u7528\u4e26\u767c\u5275\u5efa\u7d22\u5f15\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b SQL \u8a9e\u53e5\uff1a<\/p>\n<pre><code>CREATE INDEX CONCURRENTLY index_name ON table_name (column_name);<\/code><\/pre>\n<p>\u9019\u689d\u8a9e\u53e5\u6703\u5728\u4e0d\u9396\u5b9a\u8868\u7684\u60c5\u6cc1\u4e0b\u5275\u5efa\u7d22\u5f15\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4f7f\u7528 <code>CONCURRENTLY<\/code> \u9078\u9805\u6703\u4f7f\u5275\u5efa\u7d22\u5f15\u7684\u904e\u7a0b\u8b8a\u5f97\u66f4\u6162\uff0c\u56e0\u70ba PostgreSQL \u9700\u8981\u5728\u5275\u5efa\u7d22\u5f15\u7684\u540c\u6642\u8655\u7406\u5176\u4ed6\u7684\u6578\u64da\u64cd\u4f5c\u3002<\/p>\n<h3 id=\"%e4%b8%a6%e7%99%bc%e5%89%b5%e5%bb%ba%e7%b4%a2%e5%bc%95%e7%9a%84%e6%ad%a5%e9%a9%9f-ZPcFUQYEjf\">\u4e26\u767c\u5275\u5efa\u7d22\u5f15\u7684\u6b65\u9a5f<\/h3>\n<ul>\n<li><strong>\u6b65\u9a5f 1\uff1a<\/strong>\u78ba\u4fdd\u6c92\u6709\u5176\u4ed6\u7684 <code>CREATE INDEX<\/code> \u64cd\u4f5c\u6b63\u5728\u9032\u884c\u3002<\/li>\n<li><strong>\u6b65\u9a5f 2\uff1a<\/strong>\u57f7\u884c <code>CREATE INDEX CONCURRENTLY<\/code> \u8a9e\u53e5\u3002<\/li>\n<li><strong>\u6b65\u9a5f 3\uff1a<\/strong>\u76e3\u63a7\u7d22\u5f15\u5275\u5efa\u7684\u9032\u5ea6\uff0c\u78ba\u4fdd\u6c92\u6709\u932f\u8aa4\u767c\u751f\u3002<\/li>\n<li><strong>\u6b65\u9a5f 4\uff1a<\/strong>\u5b8c\u6210\u5f8c\uff0c\u6aa2\u67e5\u7d22\u5f15\u662f\u5426\u6b63\u78ba\u5275\u5efa\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%84%aa%e5%8b%a2%e8%88%87%e8%80%83%e9%87%8f-ZPcFUQYEjf\">\u512a\u52e2\u8207\u8003\u91cf<\/h2>\n<p>\u4e26\u767c\u5275\u5efa\u7d22\u5f15\u7684\u4e3b\u8981\u512a\u52e2\u5728\u65bc\u5b83\u80fd\u5920\u6e1b\u5c11\u5c0d\u7cfb\u7d71\u7684\u5f71\u97ff\uff0c\u7279\u5225\u662f\u5728\u9ad8\u6d41\u91cf\u7684\u61c9\u7528\u4e2d\u3002\u7528\u6236\u53ef\u4ee5\u5728\u5275\u5efa\u7d22\u5f15\u7684\u540c\u6642\u7e7c\u7e8c\u9032\u884c\u67e5\u8a62\u548c\u6578\u64da\u4fee\u6539\uff0c\u9019\u5c0d\u65bc\u9700\u8981\u9ad8\u53ef\u7528\u6027\u7684\u7cfb\u7d71\u5c24\u70ba\u91cd\u8981\u3002<\/p>\n<p>\u7136\u800c\uff0c\u4e26\u767c\u5275\u5efa\u7d22\u5f15\u4e5f\u6709\u5176\u7f3a\u9ede\u3002\u7531\u65bc\u9700\u8981\u8655\u7406\u5176\u4ed6\u7684\u6578\u64da\u64cd\u4f5c\uff0c\u9019\u53ef\u80fd\u6703\u5c0e\u81f4\u7d22\u5f15\u5275\u5efa\u7684\u6642\u9593\u5ef6\u9577\u3002\u6b64\u5916\uff0c\u4e26\u767c\u5275\u5efa\u7d22\u5f15\u6703\u6d88\u8017\u66f4\u591a\u7684\u7cfb\u7d71\u8cc7\u6e90\uff0c\u56e0\u6b64\u5728\u8cc7\u6e90\u6709\u9650\u7684\u60c5\u6cc1\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u8b39\u614e\u8003\u616e\u3002<\/p>\n<h2 id=\"%e5%af%a6%e9%9a%9b%e6%a1%88%e4%be%8b-ZPcFUQYEjf\">\u5be6\u969b\u6848\u4f8b<\/h2>\n<p>\u5047\u8a2d\u6709\u4e00\u500b\u5927\u578b\u7684\u96fb\u5b50\u5546\u52d9\u5e73\u53f0\uff0c\u6578\u64da\u5eab\u4e2d\u6709\u5927\u91cf\u7684\u7528\u6236\u548c\u8a02\u55ae\u6578\u64da\u3002\u5728\u9ad8\u5cf0\u6642\u6bb5\uff0c\u7cfb\u7d71\u9700\u8981\u8655\u7406\u5927\u91cf\u7684\u67e5\u8a62\u548c\u6578\u64da\u66f4\u65b0\u3002\u5982\u679c\u5728\u9019\u500b\u6642\u5019\u5275\u5efa\u7d22\u5f15\uff0c\u4f7f\u7528\u50b3\u7d71\u7684\u65b9\u5f0f\u6703\u5c0e\u81f4\u7cfb\u7d71\u6027\u80fd\u4e0b\u964d\uff0c\u5f71\u97ff\u7528\u6236\u9ad4\u9a57\u3002\u9019\u6642\u5019\uff0c\u4f7f\u7528 <code>CREATE INDEX CONCURRENTLY<\/code> \u53ef\u4ee5\u6709\u6548\u5730\u89e3\u6c7a\u9019\u500b\u554f\u984c\uff0c\u8b93\u7cfb\u7d71\u5728\u5275\u5efa\u7d22\u5f15\u7684\u540c\u6642\u4fdd\u6301\u9ad8\u6548\u904b\u884c\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-ZPcFUQYEjf\">\u7d50\u8ad6<\/h2>\n<p>PostgreSQL \u4e2d\u7684\u4e26\u767c\u5275\u5efa\u7d22\u5f15\u662f\u4e00\u500b\u5f37\u5927\u7684\u529f\u80fd\uff0c\u80fd\u5920\u5728\u4e0d\u5f71\u97ff\u7cfb\u7d71\u6027\u80fd\u7684\u60c5\u6cc1\u4e0b\uff0c\u5feb\u901f\u5275\u5efa\u7d22\u5f15\u3002\u96d6\u7136\u5b83\u6709\u5176\u6311\u6230\uff0c\u4f46\u5728\u9ad8\u4e26\u767c\u74b0\u5883\u4e2d\uff0c\u9019\u7a2e\u65b9\u6cd5\u7121\u7591\u662f\u503c\u5f97\u8003\u616e\u7684\u9078\u64c7\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u53ef\u7528\u6027\u548c\u6027\u80fd\u7684\u61c9\u7528\uff0c\u4e26\u767c\u5275\u5efa\u7d22\u5f15\u63d0\u4f9b\u4e86\u4e00\u7a2e\u6709\u6548\u7684\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u548c\u6578\u64da\u5eab\u7ba1\u7406\u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3 PostgreSQL \u4e2d\u7684\u4e26\u767c\u5275\u5efa\u7d22\u5f15\u6280\u8853\uff0c\u63d0\u5347\u6578\u64da\u5eab\u6027\u80fd\uff0c\u6e1b\u5c11\u9396\u5b9a\u5f71\u97ff\uff0c\u5be6\u73fe\u9ad8\u6548\u6578\u64da\u67e5\u8a62\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-96892","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96892","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=96892"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96892\/revisions"}],"predecessor-version":[{"id":96893,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96892\/revisions\/96893"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=96892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=96892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=96892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}