{"id":223,"date":"2026-09-06T00:42:28","date_gmt":"2026-09-05T16:42:28","guid":{"rendered":"https:\/\/www.ziliaochi.cn\/index.php\/2026\/09\/06\/zero-downtime-db-migration\/"},"modified":"2026-09-06T00:42:28","modified_gmt":"2026-09-05T16:42:28","slug":"zero-downtime-db-migration","status":"publish","type":"post","link":"https:\/\/www.ziliaochi.cn\/index.php\/2026\/09\/06\/zero-downtime-db-migration\/","title":{"rendered":"\u96f6\u505c\u673a\u6570\u636e\u5e93\u8fc1\u79fb\uff1aexpand-contract \u6a21\u5f0f\u4e0e\u90a3\u4e9b\u4f1a\u9501\u8868\u7684\u64cd\u4f5c"},"content":{"rendered":"<div style=\"font-family:-apple-system,BlinkMacSystemFont,\"Segoe UI\",\"PingFang SC\",\"Hiragino Sans GB\",\"Microsoft YaHei\",sans-serif;font-size:16.5px;line-height:1.9;color:#35435c;letter-spacing:.2px\">\n<div style=\"background:linear-gradient(135deg,#f5f9ff,#eef5ff);border:1px solid #dce8f8;border-left:4px solid #3d8ff5;border-radius:12px;padding:16px 20px;margin:0 0 24px;font-size:14.5px;color:#3d5570;line-height:2\"><span style=\"display:inline-block;background:#3d8ff5;color:#fff;font-size:12.5px;font-weight:700;padding:3px 10px;border-radius:6px;margin-right:12px;letter-spacing:1px;vertical-align:1px\">\u5173\u952e\u8bcd<\/span>\u96f6\u505c\u673a\u8fc1\u79fb\u3001\u6570\u636e\u5e93\u8fc1\u79fb\u3001expand-contract\u3001\u5728\u7ebf DDL\u3001\u9501\u8868<\/div>\n<div style=\"background:#fafbfd;border:1px solid #e8edf5;border-radius:12px;padding:18px 22px;margin:0 0 30px\">\n<div style=\"font-size:13.5px;font-weight:700;color:#8a99ae;letter-spacing:2px;margin-bottom:12px\">\u76ee\u5f55<\/div>\n<ol style=\"margin:0;padding-left:20px\">\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-1\" style=\"color:#42546e;text-decoration:none;border:none\">\u4e00\u3001\u6838\u5fc3\u6a21\u5f0f\uff1aexpand \u2192 migrate \u2192 contract<\/a><\/li>\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-2\" style=\"color:#42546e;text-decoration:none;border:none\">\u4e8c\u3001\u9010\u7c7b\u53d8\u66f4\u7684\u5b89\u5168\u6b65\u9aa4<\/a><\/li>\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-3\" style=\"color:#42546e;text-decoration:none;border:none\">\u4e09\u3001\u56db\u4e2a\u9ad8\u9891\u4e8b\u6545\u70b9<\/a><\/li>\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-4\" style=\"color:#42546e;text-decoration:none;border:none\">\u56db\u3001\u6267\u884c\u6e05\u5355<\/a><\/li>\n<li style=\"margin:8px 0;font-size:15px;line-height:1.6\"><a href=\"#sec-5\" style=\"color:#42546e;text-decoration:none;border:none\">\u4e94\u3001\u5c0f\u7ed3<\/a><\/li>\n<\/ol>\n<\/div>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\"><span style=\"font-size:17px;color:#1e2f47\">\u6570\u636e\u5e93\u8fc1\u79fb\u662f\u53d1\u5e03\u6d41\u7a0b\u91cc<strong style=\"color:#0f1c2e;font-weight:600\">\u6700\u4e0d\u53ef\u64a4\u9500<\/strong>\u7684\u4e00\u73af\u3002\u4ee3\u7801\u53d1\u9519\u4e86\u53ef\u4ee5\u56de\u6eda\uff0c\u6570\u636e\u8868\u6539\u9519\u4e86\u2014\u2014\u5c24\u5176\u662f\u5220\u5217\u3001\u6539\u7c7b\u578b\u8fd9\u7c7b\u64cd\u4f5c\u2014\u2014\u56de\u6eda\u610f\u5473\u7740\u505c\u673a\u548c\u6570\u636e\u62a2\u6551\u3002<\/p>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u672c\u6587\u8bb2\u6e05\u96f6\u505c\u673a\u8fc1\u79fb\u7684\u6838\u5fc3\u6a21\u5f0f\uff08expand-contract\uff09\u3001\u5404\u7c7b\u53d8\u66f4\u7684\u5b89\u5168\u6b65\u9aa4\uff0c\u4ee5\u53ca\u90a3\u4e9b&#8221;\u770b\u8d77\u6765\u65e0\u5bb3\u4f46\u5b9e\u9645\u4f1a\u9501\u8868&#8221;\u7684\u64cd\u4f5c\u3002<\/p>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #3d8ff5;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-1\">\u4e00\u3001\u6838\u5fc3\u6a21\u5f0f\uff1aexpand \u2192 migrate \u2192 contract<\/h2>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u6240\u6709\u5b89\u5168\u7684\u6570\u636e\u5e93\u8fc1\u79fb\uff0c\u5e95\u5c42\u90fd\u662f\u540c\u4e00\u4e2a\u6a21\u5f0f\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u5148\u628a\u7ed3\u6784\u6269\u5c55\u6210\u65b0\u65e7\u517c\u5bb9\uff0c\u518d\u8fc1\u79fb\u6570\u636e\uff0c\u6700\u540e\u624d\u6536\u7f29\u6389\u65e7\u7ed3\u6784\u3002<\/strong><\/p>\n<figure style=\"margin:30px 0;text-align:center\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"900\" src=\"https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/zero-downtime-db-migration-fig.png\" alt=\"expand \u2192 migrate \u2192 contract\" class=\"wp-image-222\" style=\"max-width:100%;height:auto;border-radius:12px;border:1px solid #e6ecf4;box-shadow:0 8px 24px rgba(15,30,60,.07)\" srcset=\"https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/zero-downtime-db-migration-fig.png 1200w, https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/zero-downtime-db-migration-fig-300x225.png 300w, https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/zero-downtime-db-migration-fig-1024x768.png 1024w, https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/zero-downtime-db-migration-fig-768x576.png 768w, https:\/\/www.ziliaochi.cn\/wp-content\/uploads\/2026\/09\/zero-downtime-db-migration-fig-800x600.png 800w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><figcaption style=\"margin-top:12px;font-size:13.5px;color:#7b8aa0;text-align:center;line-height:1.75\">\u96f6\u505c\u673a\u8fc1\u79fb\u56db\u6b65\uff1a\u6269\u5c55 \u2192 \u56de\u586b \u2192 \u5207\u8bfb \u2192 \u6536\u7f29<\/figcaption><\/figure>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u5173\u952e\u5728\u4e8e<strong style=\"color:#0f1c2e;font-weight:600\">\u6bcf\u4e2a\u9636\u6bb5\u90fd\u53ef\u4ee5\u72ec\u7acb\u90e8\u7f72\u548c\u56de\u6eda<\/strong>\uff0c\u4e14\u4e2d\u95f4\u6001\u4e0b\u65b0\u65e7\u7248\u672c\u4ee3\u7801\u80fd\u540c\u65f6\u6b63\u5e38\u5de5\u4f5c\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u5b83\u5fc5\u987b\u62c6\u6210\u591a\u6b21\u53d1\u5e03\uff0c\u800c\u4e0d\u662f\u4e00\u6b21\u641e\u5b9a\u3002<\/p>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #3d8ff5;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-2\">\u4e8c\u3001\u9010\u7c7b\u53d8\u66f4\u7684\u5b89\u5168\u6b65\u9aa4<\/h2>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #3d8ff540\">1. \u52a0\u5b57\u6bb5\uff1a\u9ed8\u8ba4\u5b89\u5168\uff0c\u4f46\u6709\u4e24\u4e2a\u4f8b\u5916<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u52a0\u4e00\u4e2a<strong style=\"color:#0f1c2e;font-weight:600\">\u53ef\u4e3a\u7a7a\u3001\u6709\u9ed8\u8ba4\u503c<\/strong>\u7684\u5217\uff0c\u5728\u4e3b\u6d41\u6570\u636e\u5e93\u4e0a\u901a\u5e38\u5f88\u5feb\u3002\u4f46\u4e0b\u9762\u4e24\u79cd\u60c5\u51b5\u4f1a\u51fa\u4e8b\uff1a<\/p>\n<ul style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u52a0\u4e86 NOT NULL \u4e14\u6ca1\u6709\u9ed8\u8ba4\u503c<\/strong>\uff1a\u5df2\u6709\u6570\u636e\u65e0\u6cd5\u6ee1\u8db3\u7ea6\u675f\uff0c\u76f4\u63a5\u5931\u8d25\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\"><strong style=\"color:#0f1c2e;font-weight:600\">\u8001\u7248\u672c\u6570\u636e\u5e93\u4e0a\u7ed9\u5927\u8868\u52a0\u5e26\u9ed8\u8ba4\u503c\u7684\u5217<\/strong>\uff1a\u67d0\u4e9b\u7248\u672c\u4f1a\u89e6\u53d1\u6574\u8868\u91cd\u5199\uff0c\u8868\u8d8a\u5927\u9501\u5f97\u8d8a\u4e45\u3002<\/li>\n<\/ul>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u5b89\u5168\u505a\u6cd5\u5206\u4e24\u6b65\u8d70\uff1a<\/p>\n<pre style=\"background:#0f1a2b;color:#dbe6f5;border-radius:12px;padding:18px 20px;overflow-x:auto;font-size:13.6px;line-height:1.78;margin:22px 0;border:1px solid #1e2c42;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace\"><code style=\"background:none;border:none;color:inherit;padding:0;font-size:inherit;font-family:inherit\">-- \u7b2c\u4e00\u6b65\uff1a\u5148\u52a0\u53ef\u4e3a\u7a7a\u7684\u5217\uff08\u5feb\u901f\uff0c\u4e0d\u9501\u8868\uff09\nALTER TABLE orders ADD COLUMN channel VARCHAR(32) NULL;\n\n-- \u7b2c\u4e8c\u6b65\uff1a\u56de\u586b\u5386\u53f2\u6570\u636e\uff0c\u5206\u6279\u8fdb\u884c\uff0c\u63a7\u5236\u5355\u6b21\u5f71\u54cd\u884c\u6570\nUPDATE orders SET channel = 'web' WHERE channel IS NULL LIMIT 5000;\n\n-- \u7b2c\u4e09\u6b65\uff1a\u786e\u8ba4\u65e0 NULL \u540e\uff0c\u518d\u52a0\u7ea6\u675f\uff08\u6309\u9700\uff0c\u6ce8\u610f\u4ecd\u53ef\u80fd\u89e6\u53d1\u6821\u9a8c\u626b\u63cf\uff09\n<\/code><\/pre>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u6ce8\u610f\u7b2c\u4e8c\u6b65\u7684<strong style=\"color:#0f1c2e;font-weight:600\">\u5206\u6279\u56de\u586b<\/strong>\uff1a\u4e00\u6b21\u6027\u66f4\u65b0\u51e0\u5343\u4e07\u884c\u4f1a\u6491\u7206\u4e8b\u52a1\u65e5\u5fd7\u3001\u62d6\u57ae\u4e3b\u4ece\u540c\u6b65\u3002\u5206\u6279 + \u6bcf\u6279\u4e4b\u95f4\u7559\u51fa\u95f4\u9694\uff0c\u662f\u6807\u51c6\u505a\u6cd5\u3002<\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #3d8ff540\">2. \u6539\u5b57\u6bb5\uff1a\u51e0\u4e4e\u90fd\u8981\u8d70&#8221;\u52a0\u65b0\u5217&#8221;\u8def\u7ebf<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u4e0d\u8981\u60f3\u7740\u76f4\u63a5 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">MODIFY<\/code> \u6216 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">ALTER COLUMN TYPE<\/code>\u3002\u6b63\u786e\u8def\u5f84\u662f\uff1a<\/p>\n<ol style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u52a0\u4e00\u4e2a\u65b0\u5217\uff08\u65b0\u7c7b\u578b\uff09\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u4ee3\u7801\u6539\u6210<strong style=\"color:#0f1c2e;font-weight:600\">\u53cc\u5199<\/strong>\u2014\u2014\u540c\u65f6\u5199\u65e7\u5217\u548c\u65b0\u5217\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u540e\u53f0\u4efb\u52a1\u56de\u586b\u5386\u53f2\u6570\u636e\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u6821\u9a8c\u65b0\u65e7\u5217\u6570\u636e\u4e00\u81f4\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u4ee3\u7801<strong style=\"color:#0f1c2e;font-weight:600\">\u5207\u5230\u53ea\u8bfb\u65b0\u5217<\/strong>\uff0c\u89c2\u5bdf\u4e00\u6bb5\u65f6\u95f4\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u4ee3\u7801<strong style=\"color:#0f1c2e;font-weight:600\">\u505c\u6b62\u5199\u65e7\u5217<\/strong>\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u6700\u540e\u624d\u5220\u9664\u65e7\u5217\u3002<\/li>\n<\/ol>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u4e03\u6b65\u542c\u8d77\u6765\u7e41\u7410\uff0c\u4f46\u6bcf\u4e00\u6b65\u90fd\u53ef\u56de\u9000\u2014\u2014\u8fd9\u6b63\u662f\u5b83\u503c\u5f97\u7684\u539f\u56e0\u3002\u5408\u5e76\u6210\u4e00\u6b65\u7684\u7ed3\u679c\u662f\uff1a\u51fa\u95ee\u9898\u53ea\u80fd\u505c\u673a\u3002<\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #3d8ff540\">3. \u5220\u5b57\u6bb5\uff1a\u5148\u505c\u5199\uff0c\u518d\u5220<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u5220\u9664\u5217\u7684\u81f4\u547d\u98ce\u9669\u5728\u4e8e<strong style=\"color:#0f1c2e;font-weight:600\">\u65e7\u7248\u672c\u4ee3\u7801\u8fd8\u5728\u8bfb\u5b83<\/strong>\u3002\u53d1\u5e03\u671f\u95f4\u65b0\u65e7\u7248\u672c\u5fc5\u7136\u5171\u5b58\uff08\u6eda\u52a8\u53d1\u5e03\u3001\u7070\u5ea6\u3001\u591a\u5b9e\u4f8b\uff09\uff0c\u56e0\u6b64\u987a\u5e8f\u5fc5\u987b\u662f\uff1a<\/p>\n<ol style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u4ee3\u7801\u5b8c\u5168\u79fb\u9664\u5bf9\u8be5\u5217\u7684<strong style=\"color:#0f1c2e;font-weight:600\">\u6240\u6709\u8bfb\u5199\u5f15\u7528<\/strong>\uff0c\u5e76\u53d1\u5e03\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u786e\u8ba4\u6240\u6709\u5b9e\u4f8b\u90fd\u8dd1\u5728\u65b0\u7248\u672c\u4e0a\uff0c\u4e14\u76d1\u63a7\u4e2d\u8be5\u5217\u65e0\u4efb\u4f55\u67e5\u8be2\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u7b49\u5f85\u4e00\u4e2a\u8db3\u591f\u957f\u7684\u89c2\u5bdf\u671f\uff08\u8986\u76d6\u6700\u957f\u53ef\u80fd\u7684\u65e7\u5b9e\u4f8b\u5b58\u6d3b\u65f6\u95f4\uff09\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u624d\u6267\u884c <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">DROP COLUMN<\/code>\u3002<\/li>\n<\/ol>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u4e00\u4e2a\u5b9e\u7528\u6280\u5de7\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u5220\u9664\u524d\u5148\u628a\u5217\u6539\u540d\u800c\u4e0d\u662f\u76f4\u63a5\u5220\u6389<\/strong>\uff08\u5982 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">old_col<\/code> \u2192 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">old_col_deprecated_202609<\/code>\uff09\u3002\u4e07\u4e00\u6709\u9057\u6f0f\u7684\u5f15\u7528\uff0c\u6539\u540d\u4f1a\u7acb\u523b\u62a5\u9519\u66b4\u9732\u51fa\u6765\uff0c\u800c\u5220\u9664\u5219\u4f1a\u5bfc\u81f4\u6570\u636e\u6c38\u4e45\u4e22\u5931\u3002<\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #3d8ff540\">4. \u52a0\u7d22\u5f15\uff1a\u5fc5\u987b\u7528\u5728\u7ebf\u65b9\u5f0f<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u5728\u5927\u8868\u4e0a\u76f4\u63a5 <code style=\"background:#eef4fb;color:#0b6bcb;padding:2px 7px;border-radius:5px;font-size:14px;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace;border:1px solid #dce8f6;white-space:nowrap\">CREATE INDEX<\/code> \u4f1a<strong style=\"color:#0f1c2e;font-weight:600\">\u963b\u585e\u5199\u5165<\/strong>\uff0c\u65f6\u95f4\u4e0e\u8868\u5927\u5c0f\u6210\u6b63\u6bd4\u3002\u8fd9\u662f\u751f\u4ea7\u4e8b\u6545\u7684\u9ad8\u9891\u6765\u6e90\u3002<\/p>\n<pre style=\"background:#0f1a2b;color:#dbe6f5;border-radius:12px;padding:18px 20px;overflow-x:auto;font-size:13.6px;line-height:1.78;margin:22px 0;border:1px solid #1e2c42;font-family:\"JetBrains Mono\",Consolas,Monaco,\"Courier New\",monospace\"><code style=\"background:none;border:none;color:inherit;padding:0;font-size:inherit;font-family:inherit\">-- PostgreSQL\uff1a\u5e76\u53d1\u5efa\u7d22\u5f15\uff08\u4e0d\u963b\u585e\u5199\u5165\uff0c\u4f46\u8017\u65f6\u66f4\u957f\u4e14\u53ef\u80fd\u5931\u8d25\u6b8b\u7559\uff09\nCREATE INDEX CONCURRENTLY idx_orders_channel ON orders(channel);\n\n-- MySQL\uff1aInnoDB \u7684\u591a\u6570\u573a\u666f\u4e0b\u5728\u7ebf DDL \u5df2\u8f83\u6210\u719f\uff0c\u4f46\u4ecd\u9700\u786e\u8ba4\u7248\u672c\u4e0e\u7b97\u6cd5\nALTER TABLE orders ADD INDEX idx_channel(channel), ALGORITHM=INPLACE, LOCK=NONE;\n<\/code><\/pre>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u4e24\u4e2a\u6ce8\u610f\u70b9\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u5e76\u53d1\u5efa\u7d22\u5f15\u5931\u8d25\u4f1a\u7559\u4e0b\u65e0\u6548\u7d22\u5f15\uff0c\u9700\u8981\u6e05\u7406\u540e\u91cd\u8bd5<\/strong>\uff1b\u53e6\u5916\u5b83\u8017\u65f6\u66f4\u957f\uff0c\u522b\u5728\u8d85\u65f6\u65f6\u95f4\u77ed\u7684\u8fc1\u79fb\u811a\u672c\u91cc\u8dd1\u3002<\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #3d8ff540\">5. \u6539\u8868\u540d \/ \u62c6\u5206\u8868\uff1a\u7528\u89c6\u56fe\u505a\u8fc7\u6e21\u5c42<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u6700\u7a33\u59a5\u7684\u505a\u6cd5\u662f<strong style=\"color:#0f1c2e;font-weight:600\">\u5efa\u65b0\u8868 \u2192 \u53cc\u5199 \u2192 \u56de\u586b \u2192 \u5207\u8bfb \u2192 \u7528\u89c6\u56fe\u517c\u5bb9\u65e7\u8868\u540d \u2192 \u6700\u540e\u4e0b\u7ebf<\/strong>\u3002\u89c6\u56fe\u7684\u4f5c\u7528\u662f\u7ed9\u8fd8\u6ca1\u6765\u5f97\u53ca\u6539\u9020\u7684\u65e7\u67e5\u8be2\u7559\u4e00\u4e2a\u517c\u5bb9\u5c42\uff0c\u628a\u4e00\u6b21\u6027\u5207\u6362\u53d8\u6210\u53ef\u5206\u6279\u63a8\u8fdb\u3002<\/p>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #3d8ff5;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-3\">\u4e09\u3001\u56db\u4e2a\u9ad8\u9891\u4e8b\u6545\u70b9<\/h2>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #3d8ff540\">1. \u957f\u4e8b\u52a1\u963b\u585e DDL<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u4e00\u4e2a\u8dd1\u4e86\u5341\u5206\u949f\u672a\u63d0\u4ea4\u7684\u67e5\u8be2\uff0c\u5c31\u80fd\u8ba9 DDL \u7b49\u5341\u5206\u949f\uff0c\u8fdb\u800c<strong style=\"color:#0f1c2e;font-weight:600\">\u963b\u585e\u540e\u7eed\u6240\u6709\u5bf9\u8be5\u8868\u7684\u8bf7\u6c42<\/strong>\u3002\u6267\u884c\u8fc1\u79fb\u524d\u5fc5\u987b<strong style=\"color:#0f1c2e;font-weight:600\">\u68c0\u67e5\u5e76\u6e05\u7406\u957f\u4e8b\u52a1<\/strong>\uff0c\u540c\u65f6\u7ed9 DDL \u8bbe\u7f6e\u5408\u7406\u7684\u9501\u7b49\u5f85\u8d85\u65f6\uff0c\u907f\u514d\u5b83\u81ea\u5df1\u53d8\u6210\u963b\u585e\u6e90\u5934\u3002<\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #3d8ff540\">2. \u4e3b\u4ece\u5ef6\u8fdf\u88ab\u5ffd\u7565<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u5728\u4e3b\u5e93\u4e0a\u5206\u6279\u56de\u586b\uff0c\u4f1a\u9020\u6210\u5927\u91cf binlog\/WAL\uff0c<strong style=\"color:#0f1c2e;font-weight:600\">\u4ece\u5e93\u8ffd\u4e0d\u4e0a<\/strong>\u3002\u800c\u5f88\u591a\u8bfb\u6d41\u91cf\u5728\u4ece\u5e93\u4e0a\uff0c\u7528\u6237\u4f1a\u770b\u5230&#8221;\u6570\u636e\u4e00\u4f1a\u513f\u6709\u4e00\u4f1a\u513f\u6ca1\u6709&#8221;\u3002\u56de\u586b\u5fc5\u987b<strong style=\"color:#0f1c2e;font-weight:600\">\u9650\u901f\u5e76\u76d1\u63a7\u4e3b\u4ece\u5ef6\u8fdf<\/strong>\uff0c\u8d85\u9608\u503c\u5c31\u6682\u505c\u3002<\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #3d8ff540\">3. \u8fc1\u79fb\u811a\u672c\u548c\u4ee3\u7801\u53d1\u5e03\u987a\u5e8f\u641e\u53cd<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u7ecf\u5178\u9519\u8bef\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u5148\u53d1\u4ee3\u7801\uff08\u8bfb\u5199\u65b0\u5217\uff09\uff0c\u518d\u8dd1\u8fc1\u79fb\uff08\u52a0\u65b0\u5217\uff09<\/strong>\u2014\u2014\u4e2d\u95f4\u90a3\u6bb5\u65f6\u95f4\u5168\u90e8\u62a5\u9519\u3002\u6b63\u786e\u987a\u5e8f\u6c38\u8fdc\u662f<strong style=\"color:#0f1c2e;font-weight:600\">\u7ed3\u6784\u53d8\u66f4\u5148\u884c\uff0c\u4ee3\u7801\u53d8\u66f4\u968f\u540e<\/strong>\uff0c\u4e14\u7ed3\u6784\u53d8\u66f4\u5fc5\u987b\u662f\u5411\u540e\u517c\u5bb9\u7684\u3002<\/p>\n<h3 style=\"font-size:18.5px;line-height:1.55;font-weight:700;color:#18283e;margin:30px 0 12px;padding-left:12px;border-left:3px solid #3d8ff540\">4. \u6ca1\u6709\u56de\u6eda\u65b9\u6848<\/h3>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u6bcf\u6b21\u8fc1\u79fb\u90fd\u8981\u63d0\u524d\u60f3\u6e05\u695a\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u8fd9\u4e00\u6b65\u5931\u8d25\u4e86\u600e\u4e48\u529e\uff1f<\/strong>\u52a0\u5217\u53ef\u4ee5\u5220\u5217\uff0c\u56de\u586b\u53ef\u4ee5\u6e05\u6570\u636e\uff0c\u4f46\u5220\u5217\u3001\u6539\u7c7b\u578b\u5c31\u5f88\u96be\u56de\u9000\u3002<strong style=\"color:#0f1c2e;font-weight:600\">\u56de\u6eda\u96be\u5ea6\u9ad8\u7684\u64cd\u4f5c\uff0c\u4e00\u5b9a\u8981\u5148\u5907\u4efd\uff0c\u4e14\u653e\u5728\u6574\u4e2a\u6d41\u7a0b\u7684\u6700\u540e\u4e00\u6b65\u3002<\/strong><\/p>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #3d8ff5;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-4\">\u56db\u3001\u6267\u884c\u6e05\u5355<\/h2>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u5efa\u8bae\u628a\u4e0b\u9762\u8fd9\u4e9b\u56fa\u5316\u6210\u53d1\u5e03\u6a21\u677f\uff1a<\/p>\n<ol style=\"padding-left:26px;margin:16px 0\">\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u786e\u8ba4\u672c\u6b21\u53d8\u66f4\u5c5e\u4e8e\u54ea\u4e00\u7c7b\uff0c\u5957\u7528\u5bf9\u5e94\u6b65\u9aa4\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u68c0\u67e5\u76ee\u6807\u8868\u5927\u5c0f\u3001\u5f53\u524d\u957f\u4e8b\u52a1\u3001\u4e3b\u4ece\u5ef6\u8fdf\u57fa\u7ebf\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">DDL \u8bbe\u7f6e\u9501\u7b49\u5f85\u8d85\u65f6\uff0c\u907f\u514d\u963b\u585e\u6269\u6563\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u6570\u636e\u56de\u586b\u5206\u6279 + \u9650\u901f\uff0c\u5168\u7a0b\u76d1\u63a7\u4e3b\u4ece\u5ef6\u8fdf\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u6309&#8221;\u7ed3\u6784 \u2192 \u4ee3\u7801 \u2192 \u6570\u636e \u2192 \u6e05\u7406&#8221;\u7684\u987a\u5e8f\u63a8\u8fdb\uff0c\u4e0d\u5408\u5e76\u6b65\u9aa4\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u6bcf\u6b65\u4e4b\u95f4\u7559\u51fa\u89c2\u5bdf\u671f\uff0c\u786e\u8ba4\u65e0\u5f02\u5e38\u518d\u8fdb\u4e0b\u4e00\u6b65\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u9ad8\u5371\u64cd\u4f5c\uff08\u5220\u5217\u3001\u6539\u7c7b\u578b\uff09\u524d\u7f6e\u5907\u4efd\uff0c\u653e\u5728\u6700\u540e\u6267\u884c\uff1b<\/li>\n<li style=\"font-size:16.2px;line-height:1.92;color:#35435c;margin:10px 0;letter-spacing:.2px\">\u5168\u90e8\u5b8c\u6210\u540e\uff0c\u6e05\u7406\u5e9f\u5f03\u5217\u3001\u4e34\u65f6\u7d22\u5f15\u548c\u517c\u5bb9\u89c6\u56fe\u3002<\/li>\n<\/ol>\n<h2 style=\"font-size:23px;line-height:1.45;font-weight:700;color:#0f1c2e;margin:46px 0 18px;padding:0 0 12px 14px;border-left:5px solid #3d8ff5;border-bottom:1px solid #eef2f7;letter-spacing:.3px\" id=\"sec-5\">\u4e94\u3001\u5c0f\u7ed3<\/h2>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u96f6\u505c\u673a\u8fc1\u79fb\u7684\u6838\u5fc3\u4e0d\u662f\u67d0\u4e2a\u5de5\u5177\u6216\u547d\u4ee4\uff0c\u800c\u662f<strong style=\"color:#0f1c2e;font-weight:600\">\u628a\u4e0d\u53ef\u9006\u64cd\u4f5c\u62c6\u6210\u4e00\u4e32\u53ef\u9006\u7684\u5c0f\u6b65\u9aa4<\/strong>\u3002\u8fd9\u4e2a\u601d\u8def\u7684\u4ee3\u4ef7\u662f\u53d1\u5e03\u5468\u671f\u53d8\u957f\u2014\u2014\u4e00\u6b21\u5b57\u6bb5\u7c7b\u578b\u53d8\u66f4\u53ef\u80fd\u8981\u8de8\u4e24\u4e09\u4e2a\u53d1\u5e03\u7a97\u53e3\u3002<\/p>\n<p style=\"font-size:16.2px;line-height:1.95;color:#35435c;margin:16px 0;letter-spacing:.2px\">\u4f46\u76f8\u6bd4&#8221;\u4e00\u6b21\u4e0a\u7ebf\u5bfc\u81f4\u534a\u5c0f\u65f6\u5168\u7ad9\u4e0d\u53ef\u7528&#8221;\uff0c\u8fd9\u70b9\u65f6\u95f4\u6210\u672c\u51e0\u4e4e\u603b\u662f\u503c\u5f97\u7684\u3002\u8bb0\u4f4f\u4e00\u53e5\u8bdd\uff1a<strong style=\"color:#0f1c2e;font-weight:600\">\u80fd\u52a0\u7684\u5148\u52a0\uff0c\u80fd\u665a\u5220\u7684\u665a\u5220\uff0c\u4e2d\u95f4\u6001\u8981\u80fd\u540c\u65f6\u670d\u52a1\u65b0\u65e7\u4ee3\u7801\u3002<\/strong><\/p>\n<div style=\"margin:42px 0 0;padding:22px 0 0;border-top:1px solid #eaeef4\">\n<div style=\"font-size:13px;color:#93a1b5;letter-spacing:1px;margin-bottom:12px\">\u6807\u7b7e<\/div>\n<p><span style=\"display:inline-block;background:#f3f6fa;border:1px solid #e4eaf2;color:#5b6c85;font-size:13px;padding:5px 12px;border-radius:999px;margin:0 8px 8px 0\">#\u6570\u636e\u5e93<\/span><span style=\"display:inline-block;background:#f3f6fa;border:1px solid #e4eaf2;color:#5b6c85;font-size:13px;padding:5px 12px;border-radius:999px;margin:0 8px 8px 0\">#\u8fc1\u79fb<\/span><span style=\"display:inline-block;background:#f3f6fa;border:1px solid #e4eaf2;color:#5b6c85;font-size:13px;padding:5px 12px;border-radius:999px;margin:0 8px 8px 0\">#DDL<\/span><span style=\"display:inline-block;background:#f3f6fa;border:1px solid #e4eaf2;color:#5b6c85;font-size:13px;padding:5px 12px;border-radius:999px;margin:0 8px 8px 0\">#\u5de5\u7a0b\u5b9e\u8df5<\/span><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u6570\u636e\u5e93\u8fc1\u79fb\u662f\u53d1\u5e03\u6d41\u7a0b\u91cc\u6700\u4e0d\u53ef\u64a4\u9500\u7684\u4e00\u73af\u3002\u672c\u6587\u8bb2\u6e05\u96f6\u505c\u673a\u8fc1\u79fb\u7684\u6838\u5fc3\u6a21\u5f0f expand-contract\u3001\u5404\u7c7b\u53d8\u66f4\u7684\u5b89\u5168\u6b65\u9aa4\uff0c\u4ee5\u53ca\u90a3\u4e9b\u770b\u8d77\u6765\u65e0\u5bb3\u4f46\u5b9e\u9645\u4f1a\u9501\u8868\u7684\u64cd\u4f5c\uff0c\u5e76\u7ed9\u51fa\u4e00\u4efd\u53ef\u6267\u884c\u7684\u68c0\u67e5\u6e05\u5355\u3002<\/p>\n","protected":false},"author":1,"featured_media":221,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,1],"tags":[104,105,73,103],"class_list":["post-223","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-engineering-practice","category-technical","tag-ddl","tag-105","tag-73","tag-103"],"_links":{"self":[{"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/posts\/223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/comments?post=223"}],"version-history":[{"count":0,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/posts\/223\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/media\/221"}],"wp:attachment":[{"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/media?parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/categories?post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ziliaochi.cn\/index.php\/wp-json\/wp\/v2\/tags?post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}