{"id":4138,"date":"2026-09-28T00:56:52","date_gmt":"2026-09-27T16:56:52","guid":{"rendered":"https:\/\/yowlab.idv.tw\/wordpress\/?p=4138"},"modified":"2026-09-28T01:07:44","modified_gmt":"2026-09-27T17:07:44","slug":"sqlite-%e7%9b%b8%e9%97%9c%e7%ad%86%e8%a8%98","status":"publish","type":"post","link":"https:\/\/yowlab.idv.tw\/wordpress\/?p=4138","title":{"rendered":"SQLite \u76f8\u95dc\u7b46\u8a18"},"content":{"rendered":"<p>\u56e0\u70ba\u9700\u6c42\u78b0\u89f8\u5230 SQLite\uff0c\u624d\u77e5\u9053\u4ed6\u7684\u597d\u8207\u5f37\u3002\u8a66\u8457\u6574\u7406\u4e00\u4e0b\u3002<\/p>\n<style type=\"text\/css\">\n    li.present01 {line-height:1.5em; background-color:#F5E5C9; padding:5px; border-radius:10px; font-weight:bold; margin:5px;}\n    li.present02 {line-height:1.5em; background-color:#D1EC87; padding:5px; border-radius:10px; font-weight:bold; margin:5px;}\n    li.present03 {line-height:1.5em; background-color:#b3dffa; padding:5px; border-radius:10px; font-weight:bold; margin:5px;}\n    li.present04 {line-height:1.5em; padding:5px; border-radius:0px; font-weight:bold; margin:5px;}\n    ol.lower-alpha {list-style-type:lower-alpha;}\n    ol.lower-roman {list-style-type:lower-roman;}\n    ul.none {list-style-type:none;line-height:1.5em; padding:10px;}\n    ul.note {line-height:1.5em; padding:10px;}\n    .highlight01 {font-weight:bold; line-height:1.5em; background-color:#e7f49c; padding:0px 2px; border:1px; border-radius:10px;}\n    .highlight02 {font-weight:bold; line-height:1.5em; background-color:#F2F26B; padding:1px 1px; border:1px;}\n    .highlight03 {font-weight:bold; line-height:1.5em; background-color:#F9BF72; padding:3px 10px; border:2px; border-radius:10px;}\n    .box01 {margin: 5px; border:1px #19130B solid; border-radius:5px; padding:10px;}\n    .box02 {margin: 5px; font-weight:bold; line-height:1.5em; padding:10px; border:1px #19130B solid; border-radius:5px;}\n    h3 {border:2px #000 solid; border-width:0px 0px 1px 0px; padding-width:0px 0px 3px 0px;}\n    h4 {border:2px #000 solid; border-width:0px 0px 1px 0px; padding-width:3px 0px 3px 0px;margin: 3px 0px 10px 0px ;font-weight:bold; line-height:1.5em;  }\n    h5 {background-color:#eff0f1; padding:10px; font-weight:bold; line-height:2em; border:1px #000 solid; border-width:1px 0px 1px 0px; margin: 5px 0px 20px 0px;}<\/p>\n<p>    pre {margin: 5px; border:0px #19130B solid; border-radius:5px; padding:10px;line-height:2em;}\n<\/style>\n<ol>\n<li class=\"present01\">SQLite \u662f\u4e00\u500b\u8f15\u91cf\u7d1a\u4e14\u9075\u5b88 ACID \u7684\u95dc\u806f\u5f0f\u8cc7\u6599\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u4e3b\u8981\u7279\u9ede\u5982\u4e0b\uff1a<\/li>\n<ul>\n<li>\u5d4c\u5165\u5f0f\u67b6\u69cb\uff1a<\/li>\n<p>\t    \u5b83\u4e0d\u662f\u7368\u7acb\u904b\u884c\u7684\u4f3a\u670d\u5668\/\u5ba2\u6236\u7aef\u7a0b\u5e8f\uff0c\u800c\u662f\u76f4\u63a5\u5305\u88dd\u5728\u5c0f\u5de7\u7684 C \u7a0b\u5f0f\u5eab\u4e2d\uff0c\u5d4c\u5165\u5230\u61c9\u7528\u7a0b\u5f0f\u5167\u904b\u884c\u3002<\/p>\n<li>\u514d\u8a2d\u5b9a\u8207\u55ae\u4e00\u6a94\u6848\uff1a<\/li>\n<p>\t    \u6574\u500b\u8cc7\u6599\u5eab\u5132\u5b58\u5728\u55ae\u4e00\u78c1\u789f\u6a94\u6848\u4e2d\uff0c\u4e0d\u9700\u7e41\u7463\u7684\u5b89\u88dd\u3001\u914d\u7f6e\u6216\u7ba1\u7406\u4f3a\u670d\u5668\u7a0b\u5e8f\u3002<\/p>\n<li>\u6a19\u6e96 SQL \u652f\u63f4\uff1a<\/li>\n<p>\t    \u4f7f\u7528\u6a19\u6e96\u7d50\u69cb\u5f0f\u67e5\u8a62\u8a9e\u8a00\uff08SQL\uff09\u4ee5\u8868\u683c\u5f62\u5f0f\u5132\u5b58\u53ca\u67e5\u8a62\u8cc7\u6599\uff0c\u6709\u6548\u907f\u514d\u7d14\u6a94\u6848\uff08\u5982 CSV\uff09\u8cc7\u6599\u91cd\u8907\u8207\u4e0d\u540c\u6b65\u7684\u554f\u984c\u3002<\/p>\n<li>\u61c9\u7528\u5ee3\u6cdb\uff1a<\/li>\n<p>\t    \u5e38\u7528\u65bc\u700f\u89bd\u5668\u6b77\u7a0b\u7d00\u9304\u3001\u884c\u52d5\u88dd\u7f6e App\u3001\u5c0f\u578b\u7db2\u7ad9\u6216\u73fe\u4ee3 SaaS \u5c08\u6848\u7b49\u5834\u666f\u3002\n     <\/ul>\n<li class=\"present01\">ACID \u662f\u4ec0\u9ebc\uff1f<\/li>\n<p>     ACID \u662f\u6307\u8cc7\u6599\u5eab\u7ba1\u7406\u7cfb\u7d71\uff08DBMS\uff09\u5728\u5beb\u5165\u6216\u66f4\u65b0\u8cc7\u6599\u6642\uff0c\u70ba\u78ba\u4fdd\u4ea4\u6613\uff08Transaction\uff09\u6b63\u78ba\u53ef\u9760\u6240\u5fc5\u9808\u5177\u5099\u7684\u56db\u500b\u6838\u5fc3\u7279\u6027\uff1a<\/p>\n<ul>\n<li>\u539f\u5b50\u6027\uff08Atomicity\uff09\uff1a<\/li>\n<p>\t    \u4ea4\u6613\u4e2d\u7684\u6240\u6709\u64cd\u4f5c\u8996\u70ba\u55ae\u4e00\u6574\u9ad4\uff0c\u8981\u9ebc\u5168\u90e8\u6210\u529f\u5b8c\u6210\uff0c\u8981\u9ebc\u5168\u90e8\u5931\u6557\u56de\u6efe\uff0c\u4e0d\u5141\u8a31\u505c\u7559\u65bc\u4e2d\u9593\u72c0\u614b\u3002<\/p>\n<li>\u4e00\u81f4\u6027\uff08Consistency\uff09\uff1a<\/li>\n<p>\t    \u4ea4\u6613\u5b8c\u6210\u524d\u5f8c\uff0c\u8cc7\u6599\u5eab\u5fc5\u9808\u59cb\u7d42\u7b26\u5408\u9810\u8a2d\u7684\u5b8c\u6574\u6027\u9650\u5236\u8207\u898f\u5247\u3002<\/p>\n<li>\u9694\u96e2\u6027\uff08Isolation\uff09\uff1a<\/li>\n<p>\t    \u591a\u500b\u4e26\u884c\u4ea4\u6613\u540c\u6642\u57f7\u884c\u6642\u5f7c\u6b64\u4e92\u4e0d\u5e72\u64fe\uff0c\u907f\u514d\u8cc7\u6599\u8b80\u5beb\u885d\u7a81\u3002<\/p>\n<li>\u8010\u4e45\u6027\uff08Durability\uff09\uff1a<\/li>\n<p>\t    \u4ea4\u6613\u4e00\u65e6\u6210\u529f\u63d0\u4ea4\uff0c\u5176\u5c0d\u8cc7\u6599\u7684\u4fee\u6539\u5373\u6c38\u4e45\u4fdd\u5b58\uff0c\u5373\u4f7f\u7cfb\u7d71\u5d29\u6f70\u4e5f\u4e0d\u6703\u907a\u5931\u3002\n     <\/ul>\n<p>    ACID \u5e38\u898b\u65bc\u95dc\u806f\u5f0f\u8cc7\u6599\u5eab\uff0c\u90e8\u5206 NoSQL \u8cc7\u6599\u5eab\u4e5f\u80fd\u9075\u5faa\u6b64\u898f\u5247\u3002<\/p>\n<li class=\"present01\">SQLite \u57f7\u884c\u6642\uff0c\u6703\u6709\u4ee5\u4e0b\u4e09\u500b\u6a94\u6848\uff1axxxx.sqlite\uff0cxxxx.sqlite-shm\uff0cxxxx.sqlite-wal <\/li>\n<p>     \u9019\u4e09\u500b\u6a94\u6848\u4ee3\u8868 SQLite \u5728\u958b\u555f WAL\uff08Write-Ahead Logging\uff0c\u9810\u5beb\u5f0f\u65e5\u8a8c\uff09\u6a21\u5f0f\u4e0b\u904b\u4f5c\u6642\u7522\u751f\u7684\u7d50\u69cb\uff1a<\/p>\n<ul>\n<li>xxxx.sqlite\uff08\u4e3b\u8cc7\u6599\u5eab\u6a94\u6848\uff09\uff1a<\/li>\n<p>\t    \u5132\u5b58\u8cc7\u6599\u8868\u3001\u7db1\u8981\u8207\u7d22\u5f15\u7684\u4e3b\u8981\u78c1\u789f\u6a94\u6848\u3002<\/p>\n<li>xxxx.sqlite-wal\uff08\u9810\u5beb\u5f0f\u65e5\u8a8c\u6a94\uff09\uff1a<\/li>\n<p>\t    \u5beb\u5165\u65b0\u8b8a\u66f4\u6642\u6703\u512a\u5148\u8ffd\u52a0\u8a18\u9304\u65bc\u6b64\u6a94\uff0c\u8b93\u8b80\u53d6\u8207\u5beb\u5165\u53ef\u4e26\u884c\u904b\u4f5c\u800c\u4e0d\u4e92\u65a5\uff0c\u63d0\u5347\u591a\u5de5\u6548\u80fd\u8207\u65e5\u8a8c\u56de\u6efe\u80fd\u529b\u3002\u65e5\u8a8c\u8cc7\u6599\u6703\u5728\u57f7\u884c\u6aa2\u67e5\u9ede\uff08Checkpoint\uff09\u6642\u5408\u4f75\u56de\u4e3b\u6a94\u6848\u3002<\/p>\n<li>xxxx.sqlite-shm\uff08\u5171\u4eab\u8a18\u61b6\u9ad4\u7d22\u5f15\u6a94\uff09\uff1a<\/li>\n<p>\t    \u7576\u591a\u500b\u9023\u7dda\u5b58\u53d6\u8cc7\u6599\u5eab\u6642\u7522\u751f\uff0c\u4f5c\u70ba WAL \u6a94\u6848\u7684\u5feb\u901f\u7d22\u5f15\u8207\u5354\u8abf\u5171\u4eab\u8a18\u61b6\u9ad4\u4e4b\u7528\u3002\n     <\/ul>\n<li class=\"present01\">\u5982\u4f55\u5099\u4efd\u8cc7\u6599\u5eab<\/li>\n<p>     \u5728 SQLite \u958b\u555f WAL \u6a21\u5f0f\u7684\u60c5\u6cc1\u4e0b\uff0c\u82e5\u76f4\u63a5\u7528 cp \u8907\u88fd\u55ae\u4e00\u4e3b\u6a94\u6848\uff08xxxx.sqlite\uff09\uff0c\u6703\u907a\u5931 WAL \u6a94\u5167\u7684\u6700\u65b0\u8cc7\u6599\uff1b\u82e5\u76f4\u63a5 cp \u6b63\u5728\u8b80\u5beb\u4e2d\u7684\u4e09\u500b\u6a94\u6848\uff0c\u4e5f\u53ef\u80fd\u9047\u5230\u8cc7\u6599\u5beb\u5165\u5230\u4e00\u534a\u4e0d\u4e00\u81f4\u7684\u98a8\u96aa\u3002<\/p>\n<p>     \u6709\u4e09\u7a2e\u6a19\u6e96\u4e14\u5b89\u5168\u7684\u5099\u4efd\u65b9\u5f0f\uff0c\u53ef\u4f9d\u9700\u6c42\u9078\u64c7\uff1a<\/p>\n<ul>\n<li>\u65b9\u6cd5\u4e00\uff1a<\/li>\n<p>            <span class=\"highlight01\">\u4f7f\u7528 SQLite CLI \u7684 .backup \u6307\u4ee4\uff08\u6700\u63a8\u85a6\u3001\u6700\u5b89\u5168\uff09\u3002<\/span><\/p>\n<p>            SQLite \u547d\u4ee4\u5217\u5de5\u5177\u5167\u5efa\u7684 .backup \u6703\u5728\u5e95\u5c64\u8abf\u7528\u5c08\u9580\u7684\u5099\u4efd API\uff0c\u80fd\u5728\u4e0d\u505c\u6b62\u670d\u52d9\uff08\u7dda\u4e0a\u71b1\u5099\u4efd\uff09\u3001\u4fdd\u8b49\u4e8b\u52d9\u4e00\u81f4\u6027\u7684\u60c5\u6cc1\u4e0b\uff0c\u76f4\u63a5\u7522\u51fa\u4e00\u4efd\u5df2\u6574\u5408 WAL \u8cc7\u6599\u7684\u55ae\u4e00\u5b8c\u6574 .sqlite \u6a94\u6848\u3002<\/p>\n<p>            \u6b64\u6cd5\u512a\u9ede\uff1a\u4e0d\u9700\u505c\u6a5f\u3001\u4e0d\u9396\u6b7b\u8b80\u5beb\u3001\u5099\u4efd\u51fa\u4f86\u7684\u6a94\u6848\u76f4\u63a5\u662f\u4e7e\u6de8\u5b8c\u6574\u7684\u4e3b\u6a94\u6848\uff08\u4e0d\u6703\u6709 -wal \u548c -shm\uff09\u3002<\/p>\n<pre><code>\r\n# \u5099\u4efd\u5230\u6307\u5b9a\u8def\u5f91\uff0c\u7522\u751f\u4e7e\u6de8\u7684\u55ae\u4e00\u6a94\u6848\r\nsqlite3 \/path\/to\/xxxx.sqlite \".backup '\/path\/to\/backup\/xxxx_$(date +%Y%m%d_%H%M%S).sqlite'\"  \r\n            <\/code><\/pre>\n<li>\u65b9\u6cd5\u4e8c\uff1a<\/li>\n<p>            \u5728\u61c9\u7528\u7a0b\u5f0f\u5167\u57f7\u884c Checkpoint \u5f8c\u518d\u8907\u88fd\u3002<\/p>\n<p>            \u5982\u679c\u5e0c\u671b\u76f4\u63a5\u4f7f\u7528\u6a94\u6848\u7cfb\u7d71\u5de5\u5177\uff08\u5982 cp\u3001rsync \u6216\u5b9a\u671f\u5feb\u7167\uff09\uff0c\u5efa\u8b70\u5148\u5f37\u5236\u8b93 SQLite \u5c07 WAL \u6a94\u6848\u7684\u5167\u5bb9\u5beb\u56de\u4e3b\u6a94\u6848\uff1a<\/p>\n<ul>\n<li>\u624b\u52d5\u89f8\u767c Checkpoint\uff1a<\/li>\n<p>                 TRUNCATE \u6703\u628a WAL \u5167\u5bb9\u5b8c\u5168\u5408\u4f75\u56de homework.sqlite\uff0c\u4e26\u5c07 homework.sqlite-wal \u622a\u65b7\u6b78\u96f6\uff08\u5927\u5c0f\u8b8a\u70ba 0\uff09\u3002<\/p>\n<pre><code>\r\nsqlite3 \/path\/to\/homework.sqlite \"PRAGMA wal_checkpoint(TRUNCATE);\"  \r\n                <\/code><\/pre>\n<li>\u8907\u88fd\u4e09\u500b\u6a94\u6848\uff08\u5373\u4f7f WAL \u5df2\u7d93\u6b78\u96f6\uff0c\u9023\u540c\u8907\u88fd\u6700\u4fdd\u96aa\uff09\uff1a<\/li>\n<pre><code>\r\ncp \/path\/to\/homework.sqlite* \/path\/to\/backup\/  \r\n               <\/code><\/pre>\n<\/ul>\n<li>\u65b9\u6cd5\u4e09\uff1a<\/li>\n<p>            \u5728 Python (Flask \/ Web \u5f8c\u7aef) \u7a0b\u5f0f\u78bc\u4e2d\u57f7\u884c\u71b1\u5099\u4efd\u3002<\/p>\n<p>            \u5982\u679c\u60f3\u5728\u7cfb\u7d71\u7ba1\u7406\u4ecb\u9762\u52a0\u4e0a\u300c\u4e0b\u8f09\u5099\u4efd\u300d\u6309\u9215\uff0c\u6216\u900f\u904e\u5f8c\u7aef\u6392\u7a0b\u5b9a\u6642\u5099\u4efd\uff0c\u53ef\u4ee5\u4f7f\u7528 Python \u539f\u751f sqlite3 \u6a21\u7d44\u7684 backup() API\uff1a<\/p>\n<pre><code>\r\nimport sqlite3\r\nimport datetime\r\n\r\ndef backup_db(source_db_path, backup_dir):\r\n    timestamp = datetime.datetime.now().strftime(\"%Y%m%d_%H%M%S\")\r\n    target_db_path = f\"{backup_dir}\/xxxx_backup_{timestamp}.sqlite\"\r\n\r\n    # \u9023\u7dda\u81f3\u4f86\u6e90\u8cc7\u6599\u5eab\u8207\u5099\u4efd\u76ee\u6a19\r\n    src_conn = sqlite3.connect(source_db_path)\r\n    dst_conn = sqlite3.connect(target_db_path)\r\n\r\n    # \u57f7\u884c\u71b1\u5099\u4efd\uff08\u57f7\u884c\u6642\u4f9d\u7136\u652f\u63f4\u4e26\u884c\u8b80\u5beb\uff0c\u4e14\u4fdd\u8b49\u8cc7\u6599\u4e00\u81f4\u6027\uff09\r\n    with dst_conn:\r\n        src_conn.backup(dst_conn)\r\n\r\n    dst_conn.close()\r\n    src_conn.close()\r\n    print(f\"\u5099\u4efd\u5b8c\u6210\uff1a{target_db_path}\")\r\n\r\n# \u547c\u53eb\u7bc4\u4f8b\r\nbackup_db('\/path\/to\/xxxx.sqlite', '\/path\/to\/backup')\r\n\r\n               <\/code><\/pre>\n<li>\u81ea\u52d5\u5316\u6392\u7a0b<\/li>\n<p>            \u82e5\u8981\u6bcf\u5929\u81ea\u52d5\u5b9a\u6642\u5099\u4efd\uff08\u4f8b\u5982\u6bcf\u5929\u51cc\u6668 2:00\uff09\uff0c\u5c07\u4ee5\u4e0b\u5167\u5bb9\u5beb\u5165 \/etc\/crontab \u6a94\u6848\uff1a<\/p>\n<pre><code>\r\n0  2  *  *   *  (account)  sqlite3 \/path\/to\/xxxx.sqlite \".backup '\/backup\/dir\/xxxx_$(date +\\%Y\\%m\\%d).sqlite'\"\r\n\r\n               <\/code><\/pre>\n<\/ul>\n<li class=\"present01\">\u89c0\u5bdf\u8cc7\u6599\u6a94\u6848\uff0c\u767c\u73fe\u4e09\u500b\u6a94\u6848(xxxx.sqlite\uff0cxxxx.sqlite-shm\uff0cxxxx.sqlite-wal)\u6642\u9593\u6233\u5370\u5206\u5225\u4e0d\u540c\uff0c\u662f\u5426\u4ee3\u8868\u8cc7\u6599\u9084\u6c92\u771f\u6b63\u5beb\u5165\u8cc7\u6599\u5eab\uff1f<\/li>\n<p>    \u9019\u4e0d\u4ee3\u8868\u8cc7\u6599\u6c92\u6709\u5beb\u5165\u8cc7\u6599\u5eab\uff0c\u8cc7\u6599\u5df2\u7d93\u78ba\u5be6\u3001\u5b89\u5168\u5730\u88ab\u6301\u4e45\u5316\u4e86\u3002<\/p>\n<p>    \u5728 SQLite \u7684 WAL\uff08Write-Ahead Logging\uff09\u6a21\u5f0f\u4e0b\uff0c\u8cc7\u6599\u5beb\u5165\u7684\u751f\u547d\u9031\u671f\u8207\u50b3\u7d71\u6a21\u5f0f\u4e0d\u540c\uff1a<\/p>\n<ul>\n<li>\u8cc7\u6599\u5df2\u7d93\u5b89\u5168\u5beb\u5165\u78c1\u789f<\/li>\n<p>          \u7576\u61c9\u7528\u7a0b\u5f0f\u57f7\u884c COMMIT \u4e14\u4e8b\u52d9\u6210\u529f\u6642\uff0cSQLite \u6703\u5c07\u6700\u65b0\u8cc7\u6599\u8207\u8b8a\u66f4\u5b8c\u6574\u5beb\u5165 xxxx.sqlite-wal \u6a94\u6848\uff0c\u4e26\u547c\u53eb\u7cfb\u7d71\u7684 fsync() \u78ba\u4fdd\u843d\u76e4\u3002<\/p>\n<p>          \u53ea\u8981 WAL \u6a94\u6848\u66f4\u65b0\uff08\u4f8b\uff1a17:06\uff09\uff0c\u5c31\u4ee3\u8868\u8cc7\u6599\u5eab\u7684 ACID \u7279\u6027\uff08\u7279\u5225\u662f\u8010\u4e45\u6027 Durability\uff09\u5df2\u7372\u5f97\u4fdd\u8b49\u3002<\/p>\n<p>          \u4efb\u4f55\u9023\u7dda\u6b64\u6642\u767c\u8d77\u67e5\u8a62\uff0cSQLite \u5167\u90e8\u6703\u81ea\u52d5\u5408\u4f75\u4e3b\u6a94\u6848\u8207 WAL \u6a94\u6848\u7684\u5167\u5bb9\uff0c\u8b80\u53d6\u5230\u7684\u7d55\u5c0d\u662f(\u4f8b\uff1a17:06)\u7684\u6700\u65b0\u8cc7\u6599\u3002<\/p>\n<li>\u4e3b\u8cc7\u6599\u5eab\u6a94\u6848\u6642\u9593\u505c\u5728 (\u4f8b\uff1a11:03) \u7684\u539f\u56e0<\/li>\n<p>          \u4e3b\u8cc7\u6599\u5eab\u6a94\u6848\uff08xxxx.sqlite\uff09\u53ea\u6709\u5728\u89f8\u767c Checkpoint\uff08\u6aa2\u67e5\u9ede\uff09\u6a5f\u5236\u6642\uff0cSQLite \u624d\u6703\u5c07 WAL \u6a94\u4e2d\u7684\u8b8a\u66f4\u540c\u6b65\u56de\u4e3b\u6a94\u3002\u5728 Checkpoint \u767c\u751f\u4e4b\u524d\uff1a\u300c\u4e3b\u6a94\u6848\u7684\u6642\u9593\u6233\u5370\u8207\u5927\u5c0f\u6703\u4fdd\u6301\u4e0d\u8b8a\u300d\u4ee5\u53ca\u300c\u6240\u6709\u7684\u589e\u4fee\u90fd\u5728 WAL \u6a94\u6848\u4e2d\u7d2f\u52a0\u300d\u3002<\/p>\n<li>\u4f55\u6642\u6703\u540c\u6b65\u56de\u4e3b\u6a94\u6848\uff1f<\/li>\n<p>          SQLite \u9810\u8a2d\u6703\u5728\u4ee5\u4e0b\u6642\u6a5f\u81ea\u52d5\u57f7\u884c Checkpoint\uff1a<\/p>\n<ul>\n<li>WAL \u9801\u9762\u9054\u5230\u9580\u6abb\uff1a\u9810\u8a2d\u901a\u5e38\u70ba 1000 \u500b\u9801\u9762\uff08\u7d04 4MB \u5de6\u53f3\uff0c\u6b63\u597d\u63a5\u8fd1\u76ee\u524d\u7684\u6a94\u6848\u5927\u5c0f\uff09\u3002<\/li>\n<li>\u6700\u5f8c\u4e00\u500b\u9023\u7dda\u95dc\u9589\uff1a\u7576\u6240\u6709\u958b\u555f\u8a72\u8cc7\u6599\u5eab\u7684\u9023\u7dda\u5b8c\u5168\u95dc\u9589\u6642\uff0cSQLite \u6703\u5617\u8a66\u81ea\u52d5\u57f7\u884c Checkpoint \u4e26\u6e05\u7a7a\/\u91cd\u7f6e WAL\u3002<\/li>\n<li\u624b\u52d5\u89f8\u767c\uff1a\u5728 SQL \u9023\u7dda\u4e2d\u624b\u52d5\u57f7\u884c PRAGMA wal_checkpoint(TRUNCATE);\u3002<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>    <span class=\"highlight01\">\u5099\u4efd\u6ce8\u610f\u4e8b\u9805<\/span><br \/>\n    \u5982\u679c\u8981\u51b7\u5099\u4efd\u8cc7\u6599\u5eab\uff0c\u5207\u52ff\u53ea\u8907\u88fd xxxx.sqlite\uff0c\u5426\u5247\u6703\u907a\u5931(\u4f8b\uff1a 11:03 \u5230 17:06 )\u4e4b\u9593\u7684\u6240\u6709\u8cc7\u6599\u3002\u5099\u4efd\u6642\u5fc5\u9808\u5c07 .sqlite\u3001.sqlite-wal\u3001.sqlite-shm \u4e09\u500b\u6a94\u6848\u4e00\u8d77\u8907\u88fd\uff0c\u6216\u8005\u4f7f\u7528 SQLite \u5167\u5efa\u7684\u5099\u4efd API \/ .backup \u6307\u4ee4\u3002<\/p>\n<\/ul>\n<li class=\"present01\">\u5982\u4f55\u5fa9\u539f SQLite \u8cc7\u6599\u5eab<\/li>\n<p>    \u5fa9\u539f SQLite \u8cc7\u6599\u5eab\u6642\uff0c\u70ba\u4e86\u78ba\u4fdd\u8cc7\u6599\u5b8c\u6574\u4e26\u907f\u514d\u5beb\u5165\u885d\u7a81\uff0c\u8acb\u4f9d\u5e8f\u57f7\u884c\u4ee5\u4e0b\u6b65\u9a5f\uff1a<\/p>\n<ul>\n<li>\u505c\u6b62\u76f8\u95dc\u670d\u52d9\uff1a <\/li>\n<p>      \u5148\u95dc\u9589\u6240\u6709\u6b63\u5728\u5b58\u53d6\u8a72 SQLite \u7684\u61c9\u7528\u7a0b\u5f0f\u6216\u5bb9\u5668\uff0c\u907f\u514d\u6a94\u6848\u906d\u9396\u5b9a\u6216\u5728\u8b80\u5beb\u4e2d\u7522\u751f\u6bc0\u640d\u3002<\/p>\n<li>\u6e05\u7406\u73fe\u6709\u6a94\u6848\uff1a<\/li>\n<p>      \u5c07\u76ee\u6a19\u76ee\u9304\u73fe\u5b58\u7684\u4e3b\u6a94\uff08.sqlite\uff09\u4ee5\u53ca\u66ab\u5b58\u8a18\u9304\u6a94\uff08\u5982 -wal \u548c -shm\uff09\u79fb\u51fa\u6216\u79fb\u9664\uff0c\u5207\u52ff\u53ea\u8986\u84cb\u4e3b\u6a94\u800c\u6b98\u7559\u820a\u7684 WAL \u6a94\u6848\u3002<\/p>\n<li>\u653e\u5165\u5099\u4efd\u6a94\u6848\uff1a<\/li>\n<p>      \u5c07\u5099\u4efd\u7684 .sqlite \u6a94\u6848\u8907\u88fd\u81f3\u76ee\u6a19\u8cc7\u6599\u5eab\u76ee\u9304\u8def\u5f91\u4e2d\u3002<\/p>\n<li>\u8a2d\u5b9a\u6b0a\u9650\u8207\u9a57\u8b49\uff1a<\/li>\n<p>      \u78ba\u8a8d\u670d\u52d9\u57f7\u884c\u5e33\u6236\u5177\u5099\u8b80\u5beb\u6b0a\u9650\uff0c\u4e26\u900f\u904e CLI \u57f7\u884c PRAGMA integrity_check; \u78ba\u8a8d\u7d50\u69cb\u7121\u8aa4\u5f8c\u518d\u91cd\u555f\u670d\u52d9\u3002<\/p>\n<\/ul>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u56e0\u70ba\u9700\u6c42\u78b0\u89f8\u5230 SQLite\uff0c\u624d\u77e5\u9053\u4ed6\u7684\u597d\u8207\u5f37\u3002\u8a66\u8457\u6574\u7406\u4e00\u4e0b\u3002 SQLite \u662f\u4e00 <a class=\"more-link\" href=\"https:\/\/yowlab.idv.tw\/wordpress\/?p=4138\">Continue reading <span class=\"screen-reader-text\">  SQLite \u76f8\u95dc\u7b46\u8a18<\/span><span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-4138","post","type-post","status-publish","format-standard","hentry","category-3"],"_links":{"self":[{"href":"https:\/\/yowlab.idv.tw\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yowlab.idv.tw\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yowlab.idv.tw\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yowlab.idv.tw\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/yowlab.idv.tw\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4138"}],"version-history":[{"count":20,"href":"https:\/\/yowlab.idv.tw\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4138\/revisions"}],"predecessor-version":[{"id":4158,"href":"https:\/\/yowlab.idv.tw\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/4138\/revisions\/4158"}],"wp:attachment":[{"href":"https:\/\/yowlab.idv.tw\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yowlab.idv.tw\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yowlab.idv.tw\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}