{"id":32624,"date":"2026-08-12T10:00:00","date_gmt":"2026-08-12T02:00:00","guid":{"rendered":"https:\/\/cn.hostease.com\/blog\/?p=32624"},"modified":"2026-08-16T20:16:06","modified_gmt":"2026-08-16T12:16:06","slug":"postgresql-pg-dump-wal","status":"publish","type":"post","link":"https:\/\/cn.hostease.com\/blog\/tutorials\/postgresql-pg-dump-wal\/","title":{"rendered":"PostgreSQL \u5907\u4efd\u6062\u590d\u6f14\u7ec3\uff1a\u7528 pg_dump \u4e0e WAL \u9a8c\u8bc1\u6062\u590d\u70b9"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/cn.hostease.com\/blog\/wp-content\/uploads\/2026\/08\/postgresql-pg-dump-wal-cover.webp\" alt=\"PostgreSQL \u5907\u4efd\u6062\u590d\u6f14\u7ec3\u5c01\u9762\" loading=\"lazy\" \/><\/p>\n<p>PostgreSQL \u5907\u4efd\u6062\u590d\u6f14\u7ec3\u7684\u4ef7\u503c\uff0c\u4e0d\u53ea\u662f\u201c\u6709\u4e00\u4efd\u5907\u4efd\u6587\u4ef6\u201d\uff0c\u800c\u662f\u5e2e\u52a9\u4f60\u786e\u8ba4\u5728\u8bef\u5220\u8868\u3001\u7a0b\u5e8f\u5199\u9519\u6570\u636e\u3001\u670d\u52a1\u5668\u78c1\u76d8\u6545\u969c\u65f6\uff0c\u80fd\u4e0d\u80fd\u6309\u9884\u671f\u6062\u590d\u5230\u4e00\u4e2a\u660e\u786e\u65f6\u95f4\u70b9\u3002\u672c\u6587\u6559\u4f60\u7528 pg_dump\uff08\u4e00\u79cd PostgreSQL \u903b\u8f91\u5907\u4efd\u5de5\u5177\uff09\u548c WAL\uff08Write-Ahead Logging\uff0c\u9884\u5199\u65e5\u5fd7\uff09\u5efa\u7acb\u53ef\u9a8c\u8bc1\u7684\u6062\u590d\u6d41\u7a0b\uff0c\u5e76\u7528\u5177\u4f53\u547d\u4ee4\u68c0\u67e5\u6062\u590d\u70b9\u662f\u5426\u771f\u7684\u53ef\u7528\u3002<\/p>\n<p>\u5f88\u591a\u56e2\u961f\u4f1a\u5b9a\u65f6\u751f\u6210 dump \u6587\u4ef6\uff0c\u5374\u5f88\u5c11\u505a\u6062\u590d\u6f14\u7ec3\u3002\u7b49\u5230\u4e8b\u6545\u53d1\u751f\u65f6\uff0c\u624d\u53d1\u73b0\u5907\u4efd\u6587\u4ef6\u7f3a\u5c11\u89d2\u8272\u6743\u9650\u3001WAL\uff08Write-Ahead Logging\uff0c\u9884\u5199\u65e5\u5fd7\uff09\u6ca1\u6709\u8fde\u7eed\u5f52\u6863\uff0c\u6216\u8005\u6062\u590d\u540e\u7684\u4e1a\u52a1\u6570\u636e\u5bf9\u4e0d\u4e0a\u3002\u5bf9\u4e8e\u8fd0\u884c\u5728 <a href=\"https:\/\/cn.hostease.com\/blog\/guides\/vps-incident-response-guide\/\">VPS\uff08\u865a\u62df\u4e13\u7528\u670d\u52a1\u5668\uff09\u5165\u4fb5\u5e94\u6025\u5904\u7406<\/a>\u4e4b\u540e\u9700\u8981\u6838\u5bf9\u6570\u636e\u5e93\u5b8c\u6574\u6027\u7684\u7ad9\u70b9\uff0c\u6062\u590d\u6f14\u7ec3\u5c24\u5176\u5173\u952e\uff1a\u5b83\u80fd\u628a\u201c\u6211\u89c9\u5f97\u53ef\u4ee5\u6062\u590d\u201d\u53d8\u6210\u201c\u6211\u5df2\u7ecf\u6062\u590d\u5e76\u6821\u9a8c\u8fc7\u201d\u3002<\/p>\n<h2>\u5148\u660e\u786e\uff1a\u4e24\u7c7b\u5907\u4efd\u5206\u522b\u89e3\u51b3\u4ec0\u4e48\u95ee\u9898<\/h2>\n<p>pg_dump\uff08\u4e00\u79cd PostgreSQL \u903b\u8f91\u5907\u4efd\u5de5\u5177\uff09\u9002\u5408\u5bfc\u51fa\u5355\u5e93\u3001\u8de8\u73af\u5883\u8fc1\u79fb\u548c\u5f00\u53d1\u73af\u5883\u590d\u523b\uff0c\u9ed8\u8ba4\u6062\u590d\u5230\u5bfc\u51fa\u65f6\u523b\u3002WAL\uff08Write-Ahead Logging\uff0c\u9884\u5199\u65e5\u5fd7\uff09\u914d\u5408\u57fa\u7840\u5907\u4efd\uff0c\u53ef\u4ee5\u628a\u6570\u636e\u5e93\u63a8\u8fdb\u5230\u6307\u5b9a\u65f6\u95f4\u70b9\u3002\u524d\u8005\u89e3\u51b3\u201c\u6709\u6ca1\u6709\u4e00\u4efd\u53ef\u8fc1\u79fb\u5907\u4efd\u201d\uff0c\u540e\u8005\u89e3\u51b3\u201c\u80fd\u5426\u56de\u5230\u4e8b\u6545\u524d\u51e0\u79d2\u201d\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cn.hostease.com\/blog\/wp-content\/uploads\/2026\/08\/postgresql-pg-dump-wal-restore-path.webp\" alt=\"pg_dump \u4e0e WAL \u9002\u7528\u8fb9\u754c\" loading=\"lazy\" \/><\/p>\n<h2>\u6f14\u7ec3\u73af\u5883\uff1a\u628a\u53d8\u91cf\u56fa\u5b9a\u4e0b\u6765\uff0c\u907f\u514d\u7ed3\u679c\u4e0d\u53ef\u590d\u73b0<\/h2>\n<p>\u6062\u590d\u6f14\u7ec3\u5e94\u5148\u4ece\u4e00\u5957\u9694\u79bb\u73af\u5883\u5f00\u59cb\uff0c\u4e0d\u8981\u76f4\u63a5\u5728\u751f\u4ea7\u5e93\u4e0a\u6d4b\u8bd5\uff1b\u5982\u679c\u670d\u52a1\u5668\u8d44\u6e90\u504f\u7d27\uff0c\u53ef\u5148\u53c2\u8003 <a href=\"https:\/\/cn.hostease.com\/blog\/guides\/ttfb-hosting-optimization\/\">\u7f51\u7ad9\u6027\u80fd\u4e0e TTFB \u4f18\u5316\u6307\u5357<\/a> \u91cc\u7684\u5bb9\u91cf\u6392\u67e5\u65b9\u5f0f\uff0c\u786e\u8ba4 CPU\uff08\u4e2d\u592e\u5904\u7406\u5668\uff09\u3001\u5185\u5b58\u548c\u78c1\u76d8 I\/O\uff08\u8f93\u5165\u8f93\u51fa\uff09\u662f\u5426\u8db3\u591f\u652f\u6491\u6062\u590d\u6d4b\u8bd5\u3002\u5efa\u8bae\u51c6\u5907\u4e00\u53f0\u4e0e\u751f\u4ea7\u63a5\u8fd1\u7684\u6d4b\u8bd5\u670d\u52a1\u5668\uff0cPostgreSQL \u4e3b\u7248\u672c\u4fdd\u6301\u4e00\u81f4\uff0c\u78c1\u76d8\u7a7a\u95f4\u81f3\u5c11\u9884\u7559\u201c\u6570\u636e\u5e93\u5927\u5c0f \u00d7 2\u201d\u7684\u5bb9\u91cf\u3002\u4f8b\u5982\u751f\u4ea7\u6570\u636e\u76ee\u5f55\u4e3a 40 GB\uff0c\u6d4b\u8bd5\u673a\u6700\u597d\u9884\u7559 80 GB \u4ee5\u4e0a\uff0c\u7528\u6765\u540c\u65f6\u653e\u7f6e\u57fa\u7840\u5907\u4efd\u3001WAL\uff08Write-Ahead Logging\uff0c\u9884\u5199\u65e5\u5fd7\uff09\u5f52\u6863\u548c\u6062\u590d\u540e\u7684\u6570\u636e\u76ee\u5f55\u3002<\/p>\n<p>\u6f14\u7ec3\u524d\u5148\u8bb0\u5f55\u4e09\u4e2a\u57fa\u7840\u4fe1\u606f\uff1aPostgreSQL \u7248\u672c\u3001\u6570\u636e\u5e93\u540d\u3001\u5907\u4efd\u4fdd\u5b58\u8def\u5f84\u3002\u4e0b\u9762\u547d\u4ee4\u53ef\u4ee5\u5feb\u901f\u53d6\u5f97\u7248\u672c\u4e0e\u5e93\u5927\u5c0f\uff0c\u540e\u7eed\u5199\u5165\u6f14\u7ec3\u8bb0\u5f55\uff0c\u65b9\u4fbf\u4e0b\u4e00\u6b21\u5bf9\u6bd4\u3002<\/p>\n<pre><code class=\"language-bash\">psql -U postgres -c \"SELECT version();\"\npsql -U postgres -c \"SELECT datname, pg_size_pretty(pg_database_size(datname)) FROM pg_database WHERE datistemplate = false;\"\nmkdir -p \/backup\/pg\/dump \/backup\/pg\/wal \/restore\/pgdata<\/code><\/pre>\n<h2>\u7528 pg_dump \u505a\u4e00\u4efd\u53ef\u6062\u590d\u7684\u903b\u8f91\u5907\u4efd<\/h2>\n<p>\u903b\u8f91\u5907\u4efd\u5efa\u8bae\u4f18\u5148\u4f7f\u7528 custom \u683c\u5f0f\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u914d\u5408 pg_restore\uff08\u4e00\u79cd PostgreSQL \u903b\u8f91\u6062\u590d\u5de5\u5177\uff09\u5e76\u884c\u6062\u590d\uff0c\u4e5f\u80fd\u6309\u5bf9\u8c61\u67e5\u770b\u548c\u9009\u62e9\u6062\u590d\u3002\u4e0b\u9762\u547d\u4ee4\u628a appdb \u6570\u636e\u5e93\u5bfc\u51fa\u5230\u5e26\u65e5\u671f\u7684\u6587\u4ef6\uff0c\u5e76\u628a\u9519\u8bef\u76f4\u63a5\u5199\u5165\u65e5\u5fd7\u3002<\/p>\n<pre><code class=\"language-bash\">export PGDATABASE=appdb\nexport PGUSER=postgres\npg_dump -Fc -f \/backup\/pg\/dump\/appdb_20260812.dump \"$PGDATABASE\" 2&gt;\/backup\/pg\/dump\/appdb_20260812.log\nls -lh \/backup\/pg\/dump\/appdb_20260812.dump\npg_restore -l \/backup\/pg\/dump\/appdb_20260812.dump &gt; \/backup\/pg\/dump\/appdb_20260812.list<\/code><\/pre>\n<ul>\n<li>\u5982\u679c\u6570\u636e\u5e93\u6709\u5927\u5bf9\u8c61\uff0c\u6267\u884c <code>SELECT count(*) FROM pg_largeobject_metadata;<\/code>\uff0c\u786e\u8ba4\u5907\u4efd\u7b56\u7565\u8986\u76d6\u5b83\u4eec\u3002<\/li>\n<li>\u5982\u679c\u5e94\u7528\u4f9d\u8d56\u6269\u5c55\uff0c\u6267\u884c <code>SELECT extname FROM pg_extension;<\/code>\uff0c\u6062\u590d\u73af\u5883\u8981\u63d0\u524d\u5b89\u88c5\u540c\u540d\u6269\u5c55\u3002<\/li>\n<li>\u5982\u679c\u4f7f\u7528\u72ec\u7acb\u89d2\u8272\uff0c\u6267\u884c <code>pg_dumpall --roles-only &gt; \/backup\/pg\/dump\/roles.sql<\/code>\uff0c\u907f\u514d\u6062\u590d\u65f6\u7f3a\u5c11 owner\u3002<\/li>\n<\/ul>\n<h2>\u5f00\u542f WAL \u5f52\u6863\u5e76\u9a8c\u8bc1\u8fde\u7eed\u6027<\/h2>\n<p>WAL\uff08Write-Ahead Logging\uff0c\u9884\u5199\u65e5\u5fd7\uff09\u5f52\u6863\u7684\u5173\u952e\u4e0d\u662f\u201c\u76ee\u5f55\u91cc\u6709\u6587\u4ef6\u201d\uff0c\u800c\u662f\u6587\u4ef6\u80fd\u8fde\u7eed\u8986\u76d6\u6545\u969c\u7a97\u53e3\u3002\u5148\u68c0\u67e5\u6570\u636e\u5e93\u53c2\u6570\uff0c\u518d\u628a\u5f52\u6863\u547d\u4ee4\u5199\u5f97\u8db3\u591f\u4fdd\u5b88\uff0c\u907f\u514d\u8986\u76d6\u540c\u540d\u6587\u4ef6\u3002<\/p>\n<pre><code class=\"language-sql\">SHOW wal_level;\nSHOW archive_mode;\nSHOW archive_command;\nSHOW data_directory;<\/code><\/pre>\n<p>\u5982\u679c\u5c1a\u672a\u5f00\u542f\u5f52\u6863\uff0c\u53ef\u5728 PostgreSQL \u914d\u7f6e\u6587\u4ef6\u4e2d\u8bbe\u7f6e\u4ee5\u4e0b\u53c2\u6570\uff0c\u7136\u540e\u91cd\u542f\u6570\u636e\u5e93\u3002\u793a\u4f8b\u8def\u5f84\u9700\u8981\u6309\u4f60\u7684\u7cfb\u7edf\u5b9e\u9645\u4f4d\u7f6e\u8c03\u6574\uff0c\u4f8b\u5982\u90e8\u5206 Linux \u53d1\u884c\u7248\u4f1a\u628a\u914d\u7f6e\u653e\u5728 <code>\/etc\/postgresql\/16\/main\/postgresql.conf<\/code>\u3002<\/p>\n<pre><code class=\"language-conf\">wal_level = replica\narchive_mode = on\narchive_command = 'test ! -f \/backup\/pg\/wal\/%f &amp;&amp; cp %p \/backup\/pg\/wal\/%f'\narchive_timeout = 300<\/code><\/pre>\n<p><code>archive_timeout = 300<\/code> \u8868\u793a\u6700\u957f 5 \u5206\u949f\u5207\u4e00\u6b21 WAL\uff08Write-Ahead Logging\uff0c\u9884\u5199\u65e5\u5fd7\uff09\u6bb5\uff0c\u9002\u5408\u6f14\u7ec3\u65f6\u7f29\u77ed\u7b49\u5f85\u65f6\u95f4\u3002\u751f\u4ea7\u73af\u5883\u8981\u7ed3\u5408\u5199\u5165\u91cf\u548c\u5b58\u50a8\u6210\u672c\u8c03\u6574\uff0c\u4e0d\u5efa\u8bae\u4e0d\u8bc4\u4f30\u5c31\u7167\u642c\u3002\u91cd\u542f\u540e\u6267\u884c\u4e00\u6b21\u624b\u52a8\u5207\u6362\uff0c\u786e\u8ba4\u5f52\u6863\u76ee\u5f55\u51fa\u73b0\u65b0\u6587\u4ef6\u3002<\/p>\n<pre><code class=\"language-bash\">psql -U postgres -c \"SELECT pg_switch_wal();\"\nsleep 10\nls -lh \/backup\/pg\/wal | tail<\/code><\/pre>\n<h2>\u505a\u57fa\u7840\u5907\u4efd\uff0c\u5efa\u7acb\u53ef\u56de\u653e\u7684\u8d77\u70b9<\/h2>\n<p>\u65f6\u95f4\u70b9\u6062\u590d\u9700\u8981\u4e00\u4e2a\u57fa\u7840\u5907\u4efd\u4f5c\u4e3a\u8d77\u70b9\uff0c\u518d\u7528 WAL\uff08Write-Ahead Logging\uff0c\u9884\u5199\u65e5\u5fd7\uff09\u5411\u524d\u56de\u653e\u3002PostgreSQL \u81ea\u5e26\u7684 pg_basebackup\uff08\u4e00\u79cd\u7269\u7406\u57fa\u7840\u5907\u4efd\u5de5\u5177\uff09\u53ef\u4ee5\u76f4\u63a5\u751f\u6210\u53ef\u6062\u590d\u7684\u6570\u636e\u76ee\u5f55\u526f\u672c\u3002\u6f14\u7ec3\u65f6\u5efa\u8bae\u52a0 <code>-X stream<\/code>\uff0c\u8ba9\u5907\u4efd\u8fc7\u7a0b\u4e2d\u4ea7\u751f\u7684 WAL\uff08Write-Ahead Logging\uff0c\u9884\u5199\u65e5\u5fd7\uff09\u4e5f\u88ab\u5e26\u4e0a\uff0c\u51cf\u5c11\u8d77\u59cb\u7f3a\u53e3\u3002<\/p>\n<pre><code class=\"language-bash\">pg_basebackup -U replication_user   -D \/backup\/pg\/base_20260812   -Fp -Xs -P   -l \"base backup 2026-08-12 drill\"<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/cn.hostease.com\/blog\/wp-content\/uploads\/2026\/08\/postgresql-pg-dump-wal-archive-check.webp\" alt=\"WAL \u5f52\u6863\u8fde\u7eed\u6027\u68c0\u67e5\" loading=\"lazy\" \/><\/p>\n<h2>\u6062\u590d\u5230\u6d4b\u8bd5\u5e93\uff0c\u5e76\u9a8c\u8bc1 pg_dump \u6587\u4ef6<\/h2>\n<p>\u5148\u9a8c\u8bc1\u903b\u8f91\u5907\u4efd\u6062\u590d\uff0c\u8fd9\u80fd\u66b4\u9732\u5bf9\u8c61\u6743\u9650\u3001\u6269\u5c55\u3001\u7f16\u7801\u548c\u7d22\u5f15\u91cd\u5efa\u95ee\u9898\u3002\u521b\u5efa\u4e00\u4e2a\u65b0\u5e93\uff0c\u4e0d\u8981\u8986\u76d6\u539f\u5e93\uff1b\u6062\u590d\u5b8c\u6210\u540e\u8dd1\u4e1a\u52a1\u5173\u952e\u67e5\u8be2\uff0c\u786e\u8ba4\u8868\u6570\u91cf\u548c\u6838\u5fc3\u6570\u636e\u4e00\u81f4\u3002<\/p>\n<pre><code class=\"language-bash\">createdb -U postgres appdb_restore_test\npg_restore -U postgres -d appdb_restore_test   --jobs=4   \/backup\/pg\/dump\/appdb_20260812.dump   2&gt;\/backup\/pg\/dump\/restore_appdb_20260812.log\npsql -U postgres -d appdb_restore_test -c \"\\dt\"\npsql -U postgres -d appdb_restore_test -c \"SELECT count(*) FROM orders;\"<\/code><\/pre>\n<p>\u5982\u679c\u6062\u590d\u65e5\u5fd7\u4e2d\u51fa\u73b0 extension does not exist\uff0c\u5148\u5728\u6d4b\u8bd5\u5e93\u5b89\u88c5\u6269\u5c55\uff0c\u518d\u91cd\u65b0\u6062\u590d\uff1b\u5982\u679c\u51fa\u73b0 role does not exist\uff0c\u5148\u5bfc\u5165 <code>roles.sql<\/code> \u6216\u521b\u5efa\u540c\u540d\u89d2\u8272\u3002\u4e0d\u8981\u4e3a\u4e86\u8ba9\u6062\u590d\u201c\u770b\u8d77\u6765\u6210\u529f\u201d\u800c\u5ffd\u7565 owner \u548c\u6743\u9650\u9519\u8bef\uff0c\u56e0\u4e3a\u5e94\u7528\u8fde\u63a5\u6570\u636e\u5e93\u65f6\u53ef\u80fd\u6b63\u597d\u4f9d\u8d56\u8fd9\u4e9b\u6743\u9650\u3002<\/p>\n<h2>\u6a21\u62df\u8bef\u64cd\u4f5c\uff0c\u7528 WAL \u6062\u590d\u5230\u6307\u5b9a\u65f6\u95f4\u70b9<\/h2>\n<p>\u63a5\u4e0b\u6765\u6f14\u7ec3\u65f6\u95f4\u70b9\u6062\u590d\u3002\u5148\u5728\u6d4b\u8bd5\u73af\u5883\u8bb0\u5f55\u4e00\u4e2a\u6062\u590d\u76ee\u6807\u65f6\u95f4\uff0c\u518d\u5236\u9020\u4e00\u6761\u53ef\u8bc6\u522b\u7684\u6570\u636e\u53d8\u5316\u3002\u4f8b\u5982\u63d2\u5165\u4e00\u6761\u6f14\u7ec3\u8bb0\u5f55\uff0c\u968f\u540e\u5220\u9664\u5b83\u3002\u76ee\u6807\u662f\u628a\u6570\u636e\u5e93\u6062\u590d\u5230\u5220\u9664\u4e4b\u524d\u3001\u63d2\u5165\u4e4b\u540e\u7684\u65f6\u95f4\u70b9\u3002<\/p>\n<pre><code class=\"language-sql\">SELECT now();\nINSERT INTO drill_events(event_name, created_at) VALUES ('restore_drill_marker', now());\nSELECT now();\nDELETE FROM drill_events WHERE event_name = 'restore_drill_marker';\nSELECT now();<\/code><\/pre>\n<p>\u5047\u8bbe\u63d2\u5165\u540e\u7684\u65f6\u95f4\u4e3a <code>2026-08-12 10:04:55+08<\/code>\uff0c\u6062\u590d\u65f6\u5c31\u628a <code>recovery_target_time<\/code> \u8bbe\u7f6e\u5230\u8fd9\u4e2a\u65f6\u95f4\u9644\u8fd1\u3002\u5148\u505c\u6b62\u6d4b\u8bd5\u5b9e\u4f8b\uff0c\u6e05\u7a7a\u76ee\u6807\u6062\u590d\u76ee\u5f55\uff0c\u518d\u590d\u5236\u57fa\u7840\u5907\u4efd\u3002<\/p>\n<pre><code class=\"language-bash\">rm -rf \/restore\/pgdata\/*\ncp -a \/backup\/pg\/base_20260812\/* \/restore\/pgdata\/\nchown -R postgres:postgres \/restore\/pgdata\nchmod 700 \/restore\/pgdata<\/code><\/pre>\n<p>\u5728 PostgreSQL 12 \u53ca\u4ee5\u4e0a\u7248\u672c\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7 <code>postgresql.auto.conf<\/code> \u6216\u914d\u7f6e\u6587\u4ef6\u8bbe\u7f6e\u6062\u590d\u53c2\u6570\uff0c\u5e76\u521b\u5efa <code>recovery.signal<\/code>\u3002\u4e0b\u9762\u793a\u4f8b\u628a WAL\uff08Write-Ahead Logging\uff0c\u9884\u5199\u65e5\u5fd7\uff09\u4ece\u5f52\u6863\u76ee\u5f55\u53d6\u56de\uff0c\u5e76\u5728\u76ee\u6807\u65f6\u95f4\u6682\u505c\uff0c\u65b9\u4fbf\u4eba\u5de5\u68c0\u67e5\u3002<\/p>\n<pre><code class=\"language-conf\">restore_command = 'cp \/backup\/pg\/wal\/%f %p'\nrecovery_target_time = '2026-08-12 10:04:55+08'\nrecovery_target_action = 'pause'<\/code><\/pre>\n<pre><code class=\"language-bash\">touch \/restore\/pgdata\/recovery.signal\nsudo -u postgres pg_ctl -D \/restore\/pgdata start\npsql -U postgres -c \"SELECT pg_is_wal_replay_paused();\"<\/code><\/pre>\n<p>\u6062\u590d\u6682\u505c\u540e\uff0c\u67e5\u8be2\u6f14\u7ec3\u6807\u8bb0\u662f\u5426\u5b58\u5728\u3002\u5982\u679c\u6807\u8bb0\u5b58\u5728\uff0c\u8bf4\u660e\u5df2\u7ecf\u6062\u590d\u5230\u5220\u9664\u4e4b\u524d\uff1b\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u8981\u6838\u5bf9\u76ee\u6807\u65f6\u95f4\u662f\u5426\u9009\u9519\u3001WAL\uff08Write-Ahead Logging\uff0c\u9884\u5199\u65e5\u5fd7\uff09\u662f\u5426\u7f3a\u6bb5\u3001\u65f6\u533a\u662f\u5426\u4e00\u81f4\u3002\u8fd9\u4e2a\u9a8c\u8bc1\u70b9\u5fc5\u987b\u5199\u8fdb\u6f14\u7ec3\u8bb0\u5f55\uff0c\u5426\u5219\u65e0\u6cd5\u8bc1\u660e\u6062\u590d\u70b9\u771f\u7684\u6709\u6548\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cn.hostease.com\/blog\/wp-content\/uploads\/2026\/08\/postgresql-pg-dump-wal-validation.webp\" alt=\"\u6062\u590d\u70b9\u9a8c\u8bc1\u8fc7\u7a0b\" loading=\"lazy\" \/><\/p>\n<h2>\u628a\u6f14\u7ec3\u7ed3\u679c\u91cf\u5316\uff1aRPO\u3001RTO \u548c\u5931\u8d25\u539f\u56e0<\/h2>\n<p>\u4e00\u6b21\u5408\u683c\u7684 PostgreSQL \u5907\u4efd\u6062\u590d\u6f14\u7ec3\uff0c\u6700\u540e\u8981\u6c89\u6dc0\u6210\u53ef\u91cf\u5316\u8bb0\u5f55\u3002RPO\uff08Recovery Point Objective\uff0c\u6062\u590d\u70b9\u76ee\u6807\uff09\u56de\u7b54\u201c\u6700\u591a\u4e22\u591a\u5c11\u6570\u636e\u201d\uff0cRTO\uff08Recovery Time Objective\uff0c\u6062\u590d\u65f6\u95f4\u76ee\u6807\uff09\u56de\u7b54\u201c\u591a\u4e45\u6062\u590d\u670d\u52a1\u201d\u3002\u4f8b\u5982\u672c\u6b21\u6f14\u7ec3\u53ef\u4ee5\u8bb0\u5f55\uff1apg_dump\uff08\u4e00\u79cd PostgreSQL \u903b\u8f91\u5907\u4efd\u5de5\u5177\uff09\u5bfc\u51fa\u8017\u65f6 8 \u5206\u949f\uff0c\u903b\u8f91\u6062\u590d\u8017\u65f6 14 \u5206\u949f\uff1bWAL\uff08Write-Ahead Logging\uff0c\u9884\u5199\u65e5\u5fd7\uff09\u65f6\u95f4\u70b9\u6062\u590d\u8017\u65f6 11 \u5206\u949f\uff0c\u6062\u590d\u70b9\u8bef\u5dee\u63a7\u5236\u5728 1 \u5206\u949f\u5185\u3002<\/p>\n<ul>\n<li>\u5907\u4efd\u6587\u4ef6\u6821\u9a8c\uff1a\u8bb0\u5f55 dump \u6587\u4ef6\u5927\u5c0f\u3001\u5bf9\u8c61\u6e05\u5355\u884c\u6570\u3001<code>pg_restore -l<\/code> \u8f93\u51fa\u662f\u5426\u5305\u542b\u5173\u952e schema\u3002<\/li>\n<li>WAL\uff08Write-Ahead Logging\uff0c\u9884\u5199\u65e5\u5fd7\uff09\u8fde\u7eed\u6027\uff1a\u8bb0\u5f55\u5f52\u6863\u76ee\u5f55\u6700\u540e 10 \u4e2a\u6587\u4ef6\u3001\u6700\u8fd1\u4e00\u6b21 <code>pg_switch_wal()<\/code> \u662f\u5426\u6210\u529f\u3002<\/li>\n<li>\u6062\u590d\u9a8c\u8bc1\uff1a\u8bb0\u5f55 3 \u5230 5 \u6761\u5173\u952e SQL \u7684\u6062\u590d\u524d\u540e\u7ed3\u679c\uff0c\u4f8b\u5982\u8ba2\u5355\u6570\u3001\u6700\u8fd1\u4e00\u7b14\u8ba2\u5355 ID\u3001\u914d\u7f6e\u8868\u7248\u672c\u53f7\u3002<\/li>\n<li>\u8017\u65f6\u6307\u6807\uff1a\u5206\u522b\u8bb0\u5f55\u5bfc\u51fa\u3001\u590d\u5236\u3001\u6062\u590d\u3001\u5e94\u7528\u9a8c\u8bc1\u8017\u65f6\uff0c\u907f\u514d\u53ea\u5199\u201c\u6062\u590d\u6210\u529f\u201d\u3002<\/li>\n<\/ul>\n<p>\u5982\u679c\u6d4b\u8bd5\u73af\u5883\u8dd1\u5728 <a href=\"https:\/\/cn.hostease.com\/vps\/\">VPS\uff08\u865a\u62df\u4e13\u7528\u670d\u52a1\u5668\uff09\u4e3b\u673a<\/a> \u6216[\u72ec\u7acb\u670d\u52a1\u5668](https:\/\/cn.hostease.com\/dedicated-server\/)\u4e0a\uff0c\u4e5f\u8981\u628a\u78c1\u76d8\u541e\u5410\u3001CPU\uff08\u4e2d\u592e\u5904\u7406\u5668\uff09\u548c\u5185\u5b58\u5360\u7528\u5199\u8fdb\u8bb0\u5f55\u3002\u6062\u590d\u901f\u5ea6\u5f80\u5f80\u53d7\u78c1\u76d8 I\/O\uff08\u8f93\u5165\u8f93\u51fa\uff09\u5f71\u54cd\uff0c\u6bd4\u5355\u7eaf\u7684\u6570\u636e\u5e93\u53c2\u6570\u66f4\u660e\u663e\uff1b\u5982\u679c\u8fd8\u8981\u6392\u67e5\u67e5\u8be2\u6027\u80fd\uff0c\u53ef\u53c2\u8003 <a href=\"https:\/\/cn.hostease.com\/blog\/guides\/mysql-slow-query-analysis\/\">MySQL \u6162\u67e5\u8be2\u65e5\u5fd7\u5206\u6790\u5b9e\u6218<\/a> \u7684\u8bb0\u5f55\u65b9\u6cd5\u3002Hostease \u5728\u4e3b\u673a\u4e0e\u670d\u52a1\u5668\u65b9\u6848\u4e2d\u63d0\u4f9b\u4e0d\u540c\u8d44\u6e90\u89c4\u683c\uff0c\u5b9e\u9645\u9009\u62e9\u4ecd\u5e94\u4ee5\u6570\u636e\u5e93\u5927\u5c0f\u3001\u6062\u590d\u7a97\u53e3\u548c\u9884\u7b97\u4e3a\u4f9d\u636e\uff0c\u4e0d\u8981\u53ea\u770b\u5355\u9879\u914d\u7f6e\u3002<\/p>\n<h2>\u5e38\u89c1\u95ee\u9898\uff1a\u4e3a\u4ec0\u4e48\u5907\u4efd\u6709\u4e86\uff0c\u6062\u590d\u8fd8\u662f\u5931\u8d25<\/h2>\n<p>\u7b2c\u4e00\u4e2a\u5e38\u89c1\u95ee\u9898\u662f\u89d2\u8272\u548c\u6743\u9650\u7f3a\u5931\u3002pg_dump\uff08\u4e00\u79cd PostgreSQL \u903b\u8f91\u5907\u4efd\u5de5\u5177\uff09\u5907\u4efd\u7684\u662f\u6570\u636e\u5e93\u5bf9\u8c61\uff0c\u4e0d\u4e00\u5b9a\u5305\u542b\u96c6\u7fa4\u7ea7\u89d2\u8272\u3002\u89e3\u51b3\u65b9\u6cd5\u662f\u5728\u6f14\u7ec3\u6d41\u7a0b\u4e2d\u52a0\u5165 <code>pg_dumpall --roles-only<\/code>\uff0c\u5e76\u5728\u6062\u590d\u524d\u5bfc\u5165\u3002\u7b2c\u4e8c\u4e2a\u95ee\u9898\u662f WAL\uff08Write-Ahead Logging\uff0c\u9884\u5199\u65e5\u5fd7\uff09\u5f52\u6863\u4e0d\u8fde\u7eed\u3002\u53ea\u8981\u7f3a\u5c11\u4e2d\u95f4\u67d0\u4e2a\u6bb5\uff0c\u65f6\u95f4\u70b9\u6062\u590d\u5c31\u53ef\u80fd\u505c\u5728\u534a\u8def\uff0c\u6240\u4ee5\u5f52\u6863\u76ee\u5f55\u9700\u8981\u76d1\u63a7\u78c1\u76d8\u7a7a\u95f4\u548c\u6587\u4ef6\u6570\u91cf\u3002<\/p>\n<h2>\u5efa\u8bae\u7684\u6267\u884c\u9891\u7387\u4e0e\u843d\u5730\u65b9\u5f0f<\/h2>\n<p>\u603b\u7ed3\u6765\u770b\uff0cPostgreSQL \u5907\u4efd\u6062\u590d\u6f14\u7ec3\u5e94\u81f3\u5c11\u6309\u6708\u6267\u884c\u4e00\u6b21\uff1b\u5982\u679c\u4e1a\u52a1\u6bcf\u5929\u90fd\u6709\u8ba2\u5355\u6216\u4f1a\u5458\u6570\u636e\u53d8\u5316\uff0c\u5efa\u8bae\u5728\u91cd\u5927\u7248\u672c\u53d1\u5e03\u524d\u989d\u5916\u505a\u4e00\u6b21\u3002\u63a8\u8350\u628a\u6f14\u7ec3\u5206\u6210\u4e09\u6863\uff1a\u6bcf\u5468\u68c0\u67e5 pg_dump\uff08\u4e00\u79cd PostgreSQL \u903b\u8f91\u5907\u4efd\u5de5\u5177\uff09\u6587\u4ef6\u548c\u5bf9\u8c61\u6e05\u5355\uff1b\u6bcf\u6708\u505a\u4e00\u6b21\u6d4b\u8bd5\u5e93\u6062\u590d\uff1b\u6bcf\u5b63\u5ea6\u505a\u4e00\u6b21\u5b8c\u6574 WAL\uff08Write-Ahead Logging\uff0c\u9884\u5199\u65e5\u5fd7\uff09\u65f6\u95f4\u70b9\u6062\u590d\uff0c\u5e76\u628a RPO\uff08Recovery Point Objective\uff0c\u6062\u590d\u70b9\u76ee\u6807\uff09\u548c RTO\uff08Recovery Time Objective\uff0c\u6062\u590d\u65f6\u95f4\u76ee\u6807\uff09\u5199\u5165\u8fd0\u7ef4\u6587\u6863\u3002<\/p>\n<p>\u5982\u679c\u4f60\u9700\u8981\u4e3a\u4f01\u4e1a\u7f51\u7ad9\u3001\u5916\u8d38\u7ad9\u6216\u4f1a\u5458\u7cfb\u7edf\u5efa\u7acb\u66f4\u7a33\u59a5\u7684\u6570\u636e\u5e93\u707e\u5907\u6d41\u7a0b\uff0c\u53ef\u4ee5\u8003\u8651\u4ece\u201c\u5907\u4efd\u6587\u4ef6\u5b58\u5728\u201d\u5347\u7ea7\u5230\u201c\u6062\u590d\u6d41\u7a0b\u53ef\u9a8c\u8bc1\u201d\u3002\u5148\u7528\u672c\u6587\u547d\u4ee4\u5b8c\u6210\u4e00\u8f6e\u6f14\u7ec3\uff0c\u518d\u6839\u636e\u6570\u636e\u5e93\u5927\u5c0f\u3001\u4e1a\u52a1\u4f4e\u5cf0\u671f\u548c\u670d\u52a1\u5668\u8d44\u6e90\u8c03\u6574\u9891\u7387\u3002\u771f\u6b63\u53ef\u9760\u7684\u5907\u4efd\uff0c\u4e0d\u662f\u5b58\u653e\u5728\u67d0\u4e2a\u76ee\u5f55\u91cc\u7684\u6587\u4ef6\uff0c\u800c\u662f\u5728\u4e8b\u6545\u53d1\u751f\u524d\u5df2\u7ecf\u88ab\u6062\u590d\u3001\u6838\u5bf9\u5e76\u8bb0\u5f55\u8fc7\u7684\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7528\u4e00\u5957\u53ef\u590d\u73b0\u6d41\u7a0b\u5b8c\u6210 PostgreSQL \u5907\u4efd\u6062\u590d\u6f14\u7ec3\uff0c\u8986\u76d6 pg_dump \u903b\u8f91\u5907\u4efd\u3001WAL \u5f52\u6863\u3001\u6062\u590d\u70b9\u9a8c\u8bc1\u4e0e\u5e38\u89c1\u95ee\u9898\u6392\u67e5\u3002<\/p>\n","protected":false},"author":2,"featured_media":32620,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4099],"tags":[4830,4402,4831,4832],"class_list":["post-32624","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-pgdump","tag-postgresql","tag-wal","tag-4832"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/cn.hostease.com\/blog\/wp-content\/uploads\/2026\/08\/postgresql-pg-dump-wal-cover.webp","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/posts\/32624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/comments?post=32624"}],"version-history":[{"count":1,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/posts\/32624\/revisions"}],"predecessor-version":[{"id":32625,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/posts\/32624\/revisions\/32625"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/media\/32620"}],"wp:attachment":[{"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/media?parent=32624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/categories?post=32624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.hostease.com\/blog\/wp-json\/wp\/v2\/tags?post=32624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}