{"id":4560,"date":"2026-06-14T19:31:10","date_gmt":"2026-06-14T19:31:10","guid":{"rendered":"https:\/\/cloudsave.app\/?p=4560"},"modified":"2026-06-15T15:05:19","modified_gmt":"2026-06-15T15:05:19","slug":"l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u","status":"publish","type":"post","link":"https:\/\/cloudsave.app\/vi\/knowledge-base\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\/","title":{"rendered":"L\u01b0u tr\u1eef WAL trong PostgreSQL: Nh\u1eefng c\u1ea1m b\u1eaby ph\u1ed5 bi\u1ebfn v\u00e0 r\u1ee7i ro m\u1ea5t d\u1eef li\u1ec7u"},"content":{"rendered":"<p>\u0110\u1ed1i v\u1edbi c\u00e1c Qu\u1ea3n tr\u1ecb vi\u00ean C\u01a1 s\u1edf d\u1eef li\u1ec7u (DBA) v\u00e0 k\u1ef9 s\u01b0 DevOps \u0111ang qu\u1ea3n l\u00fd PostgreSQL trong m\u00f4i tr\u01b0\u1eddng production, vi\u1ec7c \u0111\u1ea1t \u0111\u01b0\u1ee3c M\u1ee5c ti\u00eau \u0110i\u1ec3m ph\u1ee5c h\u1ed3i (RPO) g\u1ea7n b\u1eb1ng 0 l\u00e0 m\u1ed9t y\u00eau c\u1ea7u ti\u00ean quy\u1ebft. Tr\u1ecdng t\u00e2m c\u1ee7a kh\u1ea3 n\u0103ng ph\u1ee5c h\u1ed3i sau th\u1ea3m h\u1ecda v\u00e0 Ph\u1ee5c h\u1ed3i t\u1ea1i th\u1eddi \u0111i\u1ec3m (PITR) c\u1ee7a PostgreSQL ch\u00ednh l\u00e0 Write-Ahead Logging (WAL). Trong khi WAL \u0111\u1ea3m b\u1ea3o t\u00ednh tu\u00e2n th\u1ee7 ACID b\u1eb1ng c\u00e1ch ghi l\u1ea1i c\u00e1c giao d\u1ecbch tr\u01b0\u1edbc khi ch\u00fang \u0111\u01b0\u1ee3c ghi v\u00e0o c\u00e1c t\u1ec7p d\u1eef li\u1ec7u, th\u00ec <em>l\u01b0u tr\u1eef<\/em> WAL (WAL archiving) l\u00e0 c\u01a1 ch\u1ebf b\u1ea3o t\u1ed3n c\u00e1c t\u1ec7p nh\u1eadt k\u00fd n\u00e0y \u0111\u1ec3 sao l\u01b0u v\u00e0 sao ch\u00e9p l\u00e2u d\u00e0i.<\/p>\n<p>Tuy nhi\u00ean, vi\u1ec7c c\u1ea5u h\u00ecnh l\u01b0u tr\u1eef WAL kh\u00f4ng ph\u1ea3i l\u00e0 thao t\u00e1c &#8220;c\u00e0i \u0111\u1eb7t xong r\u1ed3i \u0111\u1ec3 \u0111\u00f3&#8221;. C\u00e1c c\u1ea5u h\u00ecnh sai, l\u1ed7i im l\u1eb7ng v\u00e0 hi\u1ec3u l\u1ea7m v\u1ec1 ki\u1ebfn tr\u00fac c\u00f3 th\u1ec3 d\u1eabn \u0111\u1ebfn m\u1ea5t m\u00e1t d\u1eef li\u1ec7u th\u1ea3m kh\u1ed1c, k\u1ecbch b\u1ea3n &#8220;split-brain&#8221; (ph\u00e2n m\u1ea3nh h\u1ec7 th\u1ed1ng) ho\u1eb7c l\u00e0m gi\u00e1n \u0111o\u1ea1n ho\u00e0n to\u00e0n c\u01a1 s\u1edf d\u1eef li\u1ec7u.<\/p>\n<p>Trong h\u01b0\u1edbng d\u1eabn to\u00e0n di\u1ec7n n\u00e0y, ch\u00fang ta s\u1ebd kh\u00e1m ph\u00e1 ki\u1ebfn tr\u00fac l\u01b0u tr\u1eef WAL c\u1ee7a PostgreSQL, x\u00e1c \u0111\u1ecbnh c\u00e1c c\u1ea1m b\u1eaby ph\u1ed5 bi\u1ebfn nh\u1ea5t d\u1eabn \u0111\u1ebfn m\u1ea5t d\u1eef li\u1ec7u v\u00e0 v\u1ea1ch ra c\u00e1c ph\u01b0\u01a1ng ph\u00e1p th\u1ef1c h\u00e0nh t\u1ed1t nh\u1ea5t \u1edf c\u1ea5p \u0111\u1ed9 production \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o c\u01a1 s\u1edf d\u1eef li\u1ec7u c\u1ee7a b\u1ea1n lu\u00f4n ki\u00ean c\u1ed1.<\/p>\n<h2>T\u00ecm hi\u1ec3u v\u1ec1 Ki\u1ebfn tr\u00fac WAL c\u1ee7a PostgreSQL<\/h2>\n<p>Tr\u01b0\u1edbc khi \u0111i s\u00e2u v\u00e0o c\u00e1c c\u1ea1m b\u1eaby, \u0111i\u1ec1u quan tr\u1ecdng l\u00e0 ph\u1ea3i hi\u1ec3u c\u00e1ch PostgreSQL x\u1eed l\u00fd c\u00e1c t\u1ec7p nh\u1eadt k\u00fd giao d\u1ecbch.<\/p>\n<p>PostgreSQL ghi t\u1ea5t c\u1ea3 c\u00e1c s\u1eeda \u0111\u1ed5i v\u00e0o c\u00e1c ph\u00e2n \u0111o\u1ea1n WAL (m\u1eb7c \u0111\u1ecbnh l\u00e0 t\u1ec7p 16MB) n\u1eb1m trong th\u01b0 m\u1ee5c <code>pg_wal<\/code> (tr\u01b0\u1edbc \u0111\u00e2y l\u00e0 <code>pg_xlog<\/code> trong c\u00e1c phi\u00ean b\u1ea3n tr\u01b0\u1edbc 10). M\u1ed7i giao d\u1ecbch \u0111\u01b0\u1ee3c ghi l\u1ea1i theo tr\u00ecnh t\u1ef1, \u0111\u01b0\u1ee3c \u0111\u00e1nh d\u1ea5u b\u1eb1ng S\u1ed1 th\u1ee9 t\u1ef1 nh\u1eadt k\u00fd (LSN).<\/p>\n<p>Khi m\u1ed9t ph\u00e2n \u0111o\u1ea1n WAL \u0111\u1ea7y, PostgreSQL s\u1ebd chuy\u1ec3n sang ph\u00e2n \u0111o\u1ea1n m\u1edbi. \u0110\u1ec3 ng\u0103n th\u01b0 m\u1ee5c <code>pg_wal<\/code> t\u0103ng tr\u01b0\u1edfng v\u00f4 h\u1ea1n, PostgreSQL s\u1ebd t\u00e1i ch\u1ebf ho\u1eb7c x\u00f3a c\u00e1c ph\u00e2n \u0111o\u1ea1n WAL c\u0169 khi ch\u00fang kh\u00f4ng c\u00f2n c\u1ea7n thi\u1ebft cho vi\u1ec7c ph\u1ee5c h\u1ed3i sau s\u1ef1 c\u1ed1 ho\u1eb7c sao ch\u00e9p.<\/p>\n<p><strong>L\u01b0u tr\u1eef WAL<\/strong> s\u1ebd can thi\u1ec7p v\u00e0o qu\u00e1 tr\u00ecnh t\u00e1i ch\u1ebf n\u00e0y. Khi <code>archive_mode<\/code> \u0111\u01b0\u1ee3c b\u1eadt, PostgreSQL s\u1ebd th\u1ef1c thi m\u1ed9t <code>archive_command<\/code> do ng\u01b0\u1eddi d\u00f9ng \u0111\u1ecbnh ngh\u0129a (ho\u1eb7c s\u1eed d\u1ee5ng <code>archive_library<\/code> trong PostgreSQL 15+) \u0111\u1ec3 sao ch\u00e9p ph\u00e2n \u0111o\u1ea1n WAL \u0111\u00e3 ho\u00e0n t\u1ea5t \u0111\u1ebfn m\u1ed9t v\u1ecb tr\u00ed ph\u1ee5 an to\u00e0n tr\u01b0\u1edbc khi n\u00f3 b\u1ecb x\u00f3a ho\u1eb7c ghi \u0111\u00e8.<\/p>\n<p>\u0110\u1ec3 th\u1ef1c hi\u1ec7n Ph\u1ee5c h\u1ed3i t\u1ea1i th\u1eddi \u0111i\u1ec3m (PITR), b\u1ea1n c\u1ea7n hai th\u00e0nh ph\u1ea7n:<br \/>\n1. M\u1ed9t b\u1ea3n sao l\u01b0u c\u01a1 s\u1edf (base backup) h\u1ee3p l\u1ec7.<br \/>\n2. M\u1ed9t chu\u1ed7i t\u1ec7p WAL \u0111\u00e3 l\u01b0u tr\u1eef kh\u00f4ng b\u1ecb gi\u00e1n \u0111o\u1ea1n t\u1eeb th\u1eddi \u0111i\u1ec3m sao l\u01b0u c\u01a1 s\u1edf \u0111\u1ebfn th\u1eddi \u0111i\u1ec3m ph\u1ee5c h\u1ed3i m\u1ee5c ti\u00eau c\u1ee7a b\u1ea1n.<\/p>\n<p>N\u1ebfu chu\u1ed7i WAL \u0111\u00f3 b\u1ecb \u0111\u1ee9t, qu\u00e1 tr\u00ecnh PITR c\u1ee7a b\u1ea1n s\u1ebd th\u1ea5t b\u1ea1i.<\/p>\n<h2>C\u1ea5u h\u00ecnh l\u01b0u tr\u1eef WAL cho m\u00f4i tr\u01b0\u1eddng Production<\/h2>\n<p>\u0110\u1ec3 b\u1eadt l\u01b0u tr\u1eef WAL, b\u1ea1n ph\u1ea3i s\u1eeda \u0111\u1ed5i t\u1ec7p <code>postgresql.conf<\/code> c\u1ee7a m\u00ecnh. C\u1ea5u h\u00ecnh c\u01a1 b\u1ea3n y\u00eau c\u1ea7u thi\u1ebft l\u1eadp <code>wal_level<\/code>, b\u1eadt <code>archive_mode<\/code> v\u00e0 x\u00e1c \u0111\u1ecbnh <code>archive_command<\/code>.<\/p>\n<pre><code class=\"language-ini\"># postgresql.conf\nwal_level = replica             # 'replica' ho\u1eb7c 'logical' l\u00e0 b\u1eaft bu\u1ed9c \u0111\u1ec3 l\u01b0u tr\u1eef\narchive_mode = on               # B\u1eadt ti\u1ebfn tr\u00ecnh l\u01b0u tr\u1eef\narchive_command = 'test ! -f \/mnt\/nfs\/archive\/%f &amp;&amp; cp %p \/mnt\/nfs\/archive\/%f'\narchive_timeout = 600           # Bu\u1ed9c chuy\u1ec3n \u0111\u1ed5i WAL m\u1ed7i 10 ph\u00fat\n<\/code><\/pre>\n<p>Trong <code>archive_command<\/code>:<br \/>\n* <code>%p<\/code> \u0111\u1ea1i di\u1ec7n cho \u0111\u01b0\u1eddng d\u1eabn \u0111\u1ea7y \u0111\u1ee7 \u0111\u1ebfn t\u1ec7p WAL c\u1ea7n l\u01b0u tr\u1eef.<br \/>\n* <code>%f<\/code> \u0111\u1ea1i di\u1ec7n cho t\u00ean t\u1ec7p c\u1ee7a t\u1ec7p WAL.<\/p>\n<p>M\u1eb7c d\u00f9 c\u1ea5u h\u00ecnh tr\u00ean c\u00f3 v\u1ebb \u0111\u01a1n gi\u1ea3n, nh\u01b0ng vi\u1ec7c d\u1ef1a v\u00e0o c\u00e1c l\u1ec7nh shell \u0111\u01a1n gi\u1ea3n trong m\u00f4i tr\u01b0\u1eddng doanh nghi\u1ec7p s\u1ebd mang l\u1ea1i nh\u1eefng r\u1ee7i ro \u0111\u00e1ng k\u1ec3.<\/p>\n<h2>C\u00e1c c\u1ea1m b\u1eaby ph\u1ed5 bi\u1ebfn trong l\u01b0u tr\u1eef WAL<\/h2>\n<h3>C\u1ea1m b\u1eaby 1: &#8220;Th\u00e0nh c\u00f4ng im l\u1eb7ng&#8221; c\u1ee7a <code>archive_command<\/code><\/h3>\n<p>PostgreSQL ho\u00e0n to\u00e0n d\u1ef1a v\u00e0o m\u00e3 tho\u00e1t (exit code) c\u1ee7a <code>archive_command<\/code>. N\u1ebfu l\u1ec7nh tr\u1ea3 v\u1ec1 <code>0<\/code>, PostgreSQL gi\u1ea3 \u0111\u1ecbnh r\u1eb1ng t\u1ec7p WAL \u0111\u00e3 \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef an to\u00e0n v\u00e0 ti\u1ebfn h\u00e0nh t\u00e1i ch\u1ebf t\u1ec7p g\u1ed1c.<\/p>\n<p>M\u1ed9t sai l\u1ea7m ph\u1ed5 bi\u1ebfn l\u00e0 s\u1eed d\u1ee5ng l\u1ec7nh tr\u1ea3 v\u1ec1 <code>0<\/code> ngay c\u1ea3 khi d\u1eef li\u1ec7u ch\u01b0a \u0111\u01b0\u1ee3c ghi an to\u00e0n v\u00e0o b\u1ed9 l\u01b0u tr\u1eef b\u1ec1n v\u1eefng. V\u00ed d\u1ee5, m\u1ed9t l\u1ec7nh <code>cp<\/code> \u0111\u01a1n gi\u1ea3n c\u00f3 th\u1ec3 tr\u1ea3 v\u1ec1 th\u00e0nh c\u00f4ng ngay khi d\u1eef li\u1ec7u ch\u1ea1m v\u00e0o b\u1ed9 nh\u1edb \u0111\u1ec7m trang (page cache) c\u1ee7a h\u1ec7 \u0111i\u1ec1u h\u00e0nh tr\u00ean m\u00e1y ch\u1ee7 \u0111\u00edch. N\u1ebfu m\u00e1y ch\u1ee7 \u0111\u00edch b\u1ecb m\u1ea5t \u0111i\u1ec7n tr\u01b0\u1edbc khi b\u1ed9 nh\u1edb \u0111\u1ec7m \u0111\u01b0\u1ee3c ghi v\u00e0o \u0111\u0129a, t\u1ec7p WAL s\u1ebd b\u1ecb m\u1ea5t, nh\u01b0ng PostgreSQL \u0111\u00e3 x\u00f3a b\u1ea3n sao c\u1ee5c b\u1ed9 c\u1ee7a n\u00f3.<\/p>\n<p><strong>R\u1ee7i ro:<\/strong> Chu\u1ed7i WAL b\u1ecb \u0111\u1ee9t v\u00e0 kh\u00f4ng th\u1ec3 th\u1ef1c hi\u1ec7n PITR, ch\u1ec9 \u0111\u01b0\u1ee3c ph\u00e1t hi\u1ec7n trong k\u1ecbch b\u1ea3n ph\u1ee5c h\u1ed3i sau th\u1ea3m h\u1ecda.<\/p>\n<p><strong>C\u00e1ch gi\u1ea3m thi\u1ec3u:<\/strong> \u0110\u1ea3m b\u1ea3o t\u1eadp l\u1ec7nh l\u01b0u tr\u1eef c\u1ee7a b\u1ea1n th\u1ef1c thi vi\u1ec7c ghi \u0111\u1ed3ng b\u1ed9. N\u1ebfu s\u1eed d\u1ee5ng c\u00e1c l\u1ec7nh shell ti\u00eau chu\u1ea9n, h\u00e3y s\u1eed d\u1ee5ng c\u00e1c c\u00f4ng c\u1ee5 \u0111\u1ea3m b\u1ea3o d\u1eef li\u1ec7u \u0111\u01b0\u1ee3c ghi xu\u1ed1ng \u0111\u0129a, ho\u1eb7c vi\u1ebft m\u1ed9t t\u1eadp l\u1ec7nh bao b\u1ecdc (wrapper script) \u0111\u1ec3 x\u00e1c minh k\u00edch th\u01b0\u1edbc t\u1ec7p v\u00e0 t\u1ed5ng ki\u1ec3m tra (checksum) sau khi chuy\u1ec3n.<\/p>\n<h3>C\u1ea1m b\u1eaby 2: C\u1ea1n ki\u1ec7t ph\u00e2n v\u00f9ng <code>pg_wal<\/code> (WAL Bloat)<\/h3>\n<p>N\u1ebfu <code>archive_command<\/code> th\u1ea5t b\u1ea1i (tr\u1ea3 v\u1ec1 m\u00e3 tho\u00e1t kh\u00e1c 0)\u2014do m\u1ea5t m\u1ea1ng, quy\u1ec1n truy c\u1eadp kh\u00f4ng ch\u00ednh x\u00e1c ho\u1eb7c \u0111\u0129a \u0111\u00edch \u0111\u1ea7y\u2014PostgreSQL s\u1ebd gi\u1eef l\u1ea1i t\u1ec7p WAL trong th\u01b0 m\u1ee5c <code>pg_wal<\/code> v\u00e0 th\u1eed l\u1ea1i l\u1ec7nh v\u00f4 th\u1eddi h\u1ea1n.<\/p>\n<p>M\u1eb7c d\u00f9 \u0111i\u1ec1u n\u00e0y ng\u0103n ng\u1eeba m\u1ea5t d\u1eef li\u1ec7u b\u1eb1ng c\u00e1ch kh\u00f4ng x\u00f3a c\u00e1c WAL ch\u01b0a \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef, nh\u01b0ng n\u00f3 g\u00e2y ra r\u1ee7i ro nghi\u00eam tr\u1ecdng v\u1ec1 t\u00ednh s\u1eb5n s\u00e0ng. N\u1ebfu th\u01b0 m\u1ee5c <code>pg_wal<\/code> n\u1eb1m tr\u00ean m\u1ed9t ph\u00e2n v\u00f9ng b\u1ecb \u0111\u1ea7y 100%, PostgreSQL s\u1ebd \u0111\u01b0a ra c\u1ea3nh b\u00e1o <code>PANIC<\/code> v\u00e0 b\u1ecb treo. C\u01a1 s\u1edf d\u1eef li\u1ec7u s\u1ebd kh\u00f4ng kh\u1edfi \u0111\u1ed9ng l\u1ea1i cho \u0111\u1ebfn khi gi\u1ea3i ph\u00f3ng \u0111\u01b0\u1ee3c dung l\u01b0\u1ee3ng.<\/p>\n<p><strong>R\u1ee7i ro:<\/strong> C\u01a1 s\u1edf d\u1eef li\u1ec7u ng\u1eebng ho\u1ea1t \u0111\u1ed9ng ho\u00e0n to\u00e0n do ph\u00e2n v\u00f9ng <code>pg_wal<\/code> b\u1ecb \u0111\u1ea7y.<\/p>\n<p><strong>C\u00e1ch gi\u1ea3m thi\u1ec3u:<\/strong><br \/>\n1. Lu\u00f4n \u0111\u1eb7t <code>pg_wal<\/code> tr\u00ean m\u1ed9t ph\u00e2n v\u00f9ng \u0111\u0129a chuy\u00ean d\u1ee5ng.<br \/>\n2. Tri\u1ec3n khai gi\u00e1m s\u00e1t ch\u1eb7t ch\u1ebd k\u00edch th\u01b0\u1edbc th\u01b0 m\u1ee5c <code>pg_wal<\/code>.<br \/>\n3. Gi\u00e1m s\u00e1t view <code>pg_stat_archiver<\/code> \u0111\u1ec3 ph\u00e1t hi\u1ec7n ngay c\u00e1c l\u1ec7nh l\u01b0u tr\u1eef b\u1ecb l\u1ed7i.<\/p>\n<h3>C\u1ea1m b\u1eaby 3: Sao l\u01b0u c\u01a1 s\u1edf kh\u00f4ng \u0111\u1ea7y \u0111\u1ee7<\/h3>\n<p>M\u1ed9t b\u1ea3n sao l\u01b0u c\u01a1 s\u1edf s\u1ebd v\u00f4 d\u1ee5ng n\u1ebfu thi\u1ebfu c\u00e1c t\u1ec7p WAL \u0111\u01b0\u1ee3c t\u1ea1o <em>trong qu\u00e1 tr\u00ecnh<\/em> sao l\u01b0u. N\u1ebfu b\u1ea1n ch\u1ee5p nhanh (snapshot) \u1edf c\u1ea5p \u0111\u1ed9 h\u1ec7 th\u1ed1ng t\u1ec7p ho\u1eb7c s\u1eed d\u1ee5ng <code>pg_basebackup<\/code> m\u00e0 kh\u00f4ng truy\u1ec1n ph\u00e1t c\u00e1c WAL (<code>-X stream<\/code>), b\u1ea1n ph\u1ea3i \u0111\u1ea3m b\u1ea3o r\u1eb1ng c\u00e1c t\u1ec7p WAL \u0111\u01b0\u1ee3c t\u1ea1o gi\u1eefa th\u1eddi \u0111i\u1ec3m b\u1eaft \u0111\u1ea7u v\u00e0 k\u1ebft th\u00fac sao l\u01b0u \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef th\u00e0nh c\u00f4ng.<\/p>\n<p>N\u1ebfu tr\u00ecnh l\u01b0u tr\u1eef c\u1ee7a b\u1ea1n b\u1ecb ch\u1eadm ho\u1eb7c l\u1ed7i, v\u00e0 c\u00e1c t\u1ec7p WAL c\u1ee5 th\u1ec3 \u0111\u00f3 b\u1ecb m\u1ea5t, b\u1ea3n sao l\u01b0u c\u01a1 s\u1edf kh\u00f4ng th\u1ec3 \u0111\u01b0\u1ee3c \u0111\u01b0a v\u1ec1 tr\u1ea1ng th\u00e1i nh\u1ea5t qu\u00e1n.<\/p>\n<p><strong>R\u1ee7i ro:<\/strong> C\u00e1c b\u1ea3n sao l\u01b0u c\u01a1 s\u1edf b\u1ecb h\u1ecfng ho\u1eb7c kh\u00f4ng th\u1ec3 ph\u1ee5c h\u1ed3i.<\/p>\n<p><strong>C\u00e1ch gi\u1ea3m thi\u1ec3u:<\/strong> S\u1eed d\u1ee5ng <code>pg_basebackup -X stream<\/code> \u0111\u1ec3 bao g\u1ed3m c\u00e1c t\u1ec7p WAL c\u1ea7n thi\u1ebft trong ch\u00ednh g\u00f3i sao l\u01b0u, ho\u1eb7c s\u1eed d\u1ee5ng c\u00e1c gi\u1ea3i ph\u00e1p sao l\u01b0u doanh nghi\u1ec7p t\u1ef1 \u0111\u1ed9ng qu\u1ea3n l\u00fd s\u1ef1 ph\u1ee5 thu\u1ed9c gi\u1eefa c\u00e1c b\u1ea3n sao l\u01b0u c\u01a1 s\u1edf v\u00e0 c\u00e1c ph\u00e2n \u0111o\u1ea1n WAL.<\/p>\n<h3>C\u1ea1m b\u1eaby 4: Nh\u1ea7m l\u1eabn Timeline v\u00e0 k\u1ecbch b\u1ea3n Split-Brain<\/h3>\n<p>Khi m\u1ed9t m\u00e1y ch\u1ee7 d\u1ef1 ph\u00f2ng (standby) \u0111\u01b0\u1ee3c n\u00e2ng c\u1ea5p l\u00ean m\u00e1y ch\u1ee7 ch\u00ednh (primary), PostgreSQL s\u1ebd t\u0103ng &#8220;Timeline ID&#8221; (ph\u1ea7n \u0111\u1ea7u c\u1ee7a t\u00ean t\u1ec7p WAL, v\u00ed d\u1ee5: <code>0000000200000001000000A4<\/code>). \u0110i\u1ec1u n\u00e0y ng\u0103n m\u00e1y ch\u1ee7 ch\u00ednh m\u1edbi ghi \u0111\u00e8 l\u00ean l\u1ecbch s\u1eed WAL c\u1ee7a m\u00e1y ch\u1ee7 ch\u00ednh c\u0169.<\/p>\n<p>Tuy nhi\u00ean, n\u1ebfu m\u00e1y ch\u1ee7 ch\u00ednh c\u0169 v\u00f4 t\u00ecnh \u0111\u01b0\u1ee3c kh\u1edfi \u0111\u1ed9ng m\u00e0 kh\u00f4ng \u0111\u01b0\u1ee3c c\u00e1ch ly \u0111\u00fang c\u00e1ch (k\u1ecbch b\u1ea3n split-brain), n\u00f3 c\u00f3 th\u1ec3 c\u1ed1 g\u1eafng \u0111\u1ea9y c\u00e1c t\u1ec7p WAL v\u00e0o c\u00f9ng v\u1ecb tr\u00ed l\u01b0u tr\u1eef b\u1eb1ng timeline c\u0169. N\u1ebfu <code>archive_command<\/code> c\u1ee7a b\u1ea1n ghi \u0111\u00e8 t\u1ec7p m\u1ed9t c\u00e1ch m\u00f9 qu\u00e1ng, b\u1ea1n c\u00f3 th\u1ec3 l\u00e0m h\u1ecfng kho l\u01b0u tr\u1eef c\u1ee7a m\u00ecnh.<\/p>\n<p><strong>R\u1ee7i ro:<\/strong> C\u00e1c t\u1ec7p WAL b\u1ecb ghi \u0111\u00e8, kho l\u01b0u tr\u1eef b\u1ecb h\u1ecfng v\u00e0 c\u01a1 s\u1edf d\u1eef li\u1ec7u kh\u00f4ng th\u1ec3 ph\u1ee5c h\u1ed3i.<\/p>\n<p><strong>C\u00e1ch gi\u1ea3m thi\u1ec3u:<\/strong> <code>archive_command<\/code> c\u1ee7a b\u1ea1n <em>kh\u00f4ng bao gi\u1edd<\/em> \u0111\u01b0\u1ee3c ghi \u0111\u00e8 l\u00ean m\u1ed9t t\u1ec7p hi\u1ec7n c\u00f3. H\u00e3y l\u01b0u \u00fd trong c\u1ea5u h\u00ecnh c\u01a1 b\u1ea3n tr\u01b0\u1edbc \u0111\u00f3, ch\u00fang ta \u0111\u00e3 s\u1eed d\u1ee5ng <code>test ! -f \/mnt\/nfs\/archive\/%f<\/code> \u0111\u1ec3 b\u00e1o l\u1ed7i r\u00f5 r\u00e0ng n\u1ebfu t\u1ec7p \u0111\u00e3 t\u1ed3n t\u1ea1i.<\/p>\n<h2>Gi\u1ea3m thi\u1ec3u r\u1ee7i ro m\u1ea5t d\u1eef li\u1ec7u: C\u00e1c ph\u01b0\u01a1ng ph\u00e1p th\u1ef1c h\u00e0nh t\u1ed1t nh\u1ea5t cho Production<\/h2>\n<p>\u0110\u1ec3 c\u1ee7ng c\u1ed1 chi\u1ebfn l\u01b0\u1ee3c l\u01b0u tr\u1eef PostgreSQL c\u1ee7a b\u1ea1n, h\u00e3y tri\u1ec3n khai c\u00e1c ph\u01b0\u01a1ng ph\u00e1p th\u1ef1c h\u00e0nh t\u1ed1t nh\u1ea5t sau \u0111\u00e2y.<\/p>\n<h3>1. Gi\u00e1m s\u00e1t ti\u1ebfn tr\u00ecnh l\u01b0u tr\u1eef m\u1ed9t c\u00e1ch t\u1ef1 nhi\u00ean<\/h3>\n<p>PostgreSQL cung c\u1ea5p m\u1ed9t view t\u00edch h\u1ee3p s\u1eb5n, <code>pg_stat_archiver<\/code>, theo d\u00f5i s\u1ef1 th\u00e0nh c\u00f4ng v\u00e0 th\u1ea5t b\u1ea1i c\u1ee7a qu\u00e1 tr\u00ecnh l\u01b0u tr\u1eef c\u1ee7a b\u1ea1n. B\u1ea1n n\u00ean t\u00edch h\u1ee3p view n\u00e0y v\u00e0o h\u1ec7 th\u1ed1ng quan s\u00e1t c\u1ee7a m\u00ecnh (v\u00ed d\u1ee5: Prometheus, Datadog ho\u1eb7c Zabbix).<\/p>\n<pre><code class=\"language-sql\">SELECT \n    archived_count,\n    last_archived_wal,\n    last_archived_time,\n    failed_count,\n    last_failed_wal,\n    last_failed_time,\n    stats_reset\nFROM pg_stat_archiver;\n<\/code><\/pre>\n<p><strong>C\u00e1c ng\u01b0\u1ee1ng c\u1ea3nh b\u00e1o c\u1ea7n c\u1ea5u h\u00ecnh:<\/strong><br \/>\n* C\u1ea3nh b\u00e1o n\u1ebfu <code>failed_count<\/code> t\u0103ng l\u00ean.<br \/>\n* C\u1ea3nh b\u00e1o n\u1ebfu ch\u00eanh l\u1ec7ch th\u1eddi gian gi\u1eefa <code>now()<\/code> v\u00e0 <code>last_archived_time<\/code> v\u01b0\u1ee3t qu\u00e1 ng\u01b0\u1ee1ng RPO c\u1ee7a b\u1ea1n (v\u00ed d\u1ee5: 15 ph\u00fat), l\u01b0u \u00fd r\u1eb1ng c\u00e1c c\u01a1 s\u1edf d\u1eef li\u1ec7u c\u00f3 l\u01b0u l\u01b0\u1ee3ng th\u1ea5p c\u00f3 th\u1ec3 c\u00f3 \u0111\u1ed9 tr\u1ec5 t\u1ef1 nhi\u00ean tr\u1eeb khi <code>archive_timeout<\/code> \u0111\u01b0\u1ee3c thi\u1ebft l\u1eadp.<\/p>\n<h3>2. T\u1eadn d\u1ee5ng <code>archive_timeout<\/code><\/h3>\n<p>Trong c\u00e1c c\u01a1 s\u1edf d\u1eef li\u1ec7u c\u00f3 kh\u1ed1i l\u01b0\u1ee3ng ghi th\u1ea5p, m\u1ed9t t\u1ec7p WAL 16MB c\u00f3 th\u1ec3 m\u1ea5t h\u00e0ng gi\u1edd \u0111\u1ec3 \u0111\u1ea7y. Cho \u0111\u1ebfn khi n\u00f3 \u0111\u1ea7y, n\u00f3 s\u1ebd kh\u00f4ng \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef. N\u1ebfu m\u00e1y ch\u1ee7 b\u1ecb treo v\u00e0 \u0111\u0129a c\u1ee5c b\u1ed9 b\u1ecb m\u1ea5t, b\u1ea1n s\u1ebd m\u1ea5t h\u00e0ng gi\u1edd giao d\u1ecbch.<\/p>\n<p>Thi\u1ebft l\u1eadp <code>archive_timeout = 600<\/code> (10 ph\u00fat) bu\u1ed9c PostgreSQL chuy\u1ec3n sang t\u1ec7p WAL m\u1edbi v\u00e0 l\u01b0u tr\u1eef t\u1ec7p hi\u1ec7n t\u1ea1i, ngay c\u1ea3 khi n\u00f3 ch\u01b0a \u0111\u1ea7y. \u0110i\u1ec1u n\u00e0y \u0111\u1ea3m b\u1ea3o RPO c\u1ee7a b\u1ea1n kh\u00f4ng v\u01b0\u1ee3t qu\u00e1 10 ph\u00fat, v\u1edbi c\u00e1i gi\u00e1 l\u00e0 m\u1ee9c s\u1eed d\u1ee5ng l\u01b0u tr\u1eef cao h\u01a1n m\u1ed9t ch\u00fat do c\u00e1c t\u1ec7p WAL b\u1ecb \u0111\u1ea7y m\u1ed9t ph\u1ea7n.<\/p>\n<h3>3. Chuy\u1ec3n sang <code>archive_library<\/code> (PostgreSQL 15+)<\/h3>\n<p>Tr\u01b0\u1edbc \u0111\u00e2y, <code>archive_command<\/code> t\u1ea1o ra m\u1ed9t ti\u1ebfn tr\u00ecnh shell m\u1edbi cho m\u1ed7i t\u1ec7p WAL. Trong c\u00e1c m\u00f4i tr\u01b0\u1eddng c\u00f3 l\u01b0u l\u01b0\u1ee3ng cao t\u1ea1o ra h\u00e0ng tr\u0103m t\u1ec7p WAL m\u1ed7i ph\u00fat, chi ph\u00ed t\u1ea1o c\u00e1c ti\u1ebfn tr\u00ecnh shell tr\u1edf th\u00e0nh n\u00fat th\u1eaft hi\u1ec7u n\u0103ng.<\/p>\n<p>PostgreSQL 15 \u0111\u00e3 gi\u1edbi thi\u1ec7u tham s\u1ed1 <code>archive_library<\/code>, cho ph\u00e9p l\u01b0u tr\u1eef WAL \u0111\u01b0\u1ee3c x\u1eed l\u00fd b\u1edfi c\u00e1c m\u00f4-\u0111un C \u0111\u01b0\u1ee3c t\u1ea3i \u0111\u1ed9ng. \u0110i\u1ec1u n\u00e0y lo\u1ea1i b\u1ecf chi ph\u00ed t\u1ea1o shell v\u00e0 cung c\u1ea5p c\u01a1 ch\u1ebf l\u01b0u tr\u1eef hi\u1ec7u n\u0103ng cao, m\u1ea1nh m\u1ebd h\u01a1n nhi\u1ec1u. N\u1ebfu b\u1ea1n \u0111ang s\u1eed d\u1ee5ng PostgreSQL 15 tr\u1edf l\u00ean, h\u00e3y t\u00ecm c\u00e1c c\u00f4ng c\u1ee5 sao l\u01b0u h\u1ed7 tr\u1ee3 c\u00e1c m\u00f4-\u0111un l\u01b0u tr\u1eef t\u00f9y ch\u1ec9nh.<\/p>\n<h3>4. Th\u01b0\u1eddng xuy\u00ean ki\u1ec3m tra Ph\u1ee5c h\u1ed3i t\u1ea1i th\u1eddi \u0111i\u1ec3m (PITR)<\/h3>\n<p>M\u1ed9t b\u1ea3n sao l\u01b0u ch\u01b0a \u0111\u01b0\u1ee3c ki\u1ec3m tra kh\u00f4ng ph\u1ea3i l\u00e0 b\u1ea3n sao l\u01b0u; \u0111\u00f3 ch\u1ec9 l\u00e0 m\u1ed9t hy v\u1ecdng. C\u00e1ch duy nh\u1ea5t \u0111\u1ec3 x\u00e1c minh r\u1eb1ng vi\u1ec7c l\u01b0u tr\u1eef WAL c\u1ee7a b\u1ea1n \u0111ang ho\u1ea1t \u0111\u1ed9ng ch\u00ednh x\u00e1c, chu\u1ed7i WAL c\u1ee7a b\u1ea1n kh\u00f4ng b\u1ecb \u0111\u1ee9t v\u00e0 c\u00e1c b\u1ea3n sao l\u01b0u c\u01a1 s\u1edf c\u1ee7a b\u1ea1n nh\u1ea5t qu\u00e1n l\u00e0 th\u1ef1c hi\u1ec7n c\u00e1c b\u00e0i ki\u1ec3m tra PITR t\u1ef1 \u0111\u1ed9ng \u0111\u1ecbnh k\u1ef3.<\/p>\n<p>Kh\u1edfi ch\u1ea1y m\u1ed9t phi\u00ean b\u1ea3n t\u1ea1m th\u1eddi, kh\u00f4i ph\u1ee5c b\u1ea3n sao l\u01b0u c\u01a1 s\u1edf, c\u1ea5u h\u00ecnh <code>restore_command<\/code> \u0111\u1ec3 l\u1ea5y t\u1eeb kho l\u01b0u tr\u1eef c\u1ee7a b\u1ea1n v\u00e0 ph\u1ee5c h\u1ed3i \u0111\u1ebfn m\u1ed9t d\u1ea5u th\u1eddi gian c\u1ee5 th\u1ec3. X\u00e1c minh r\u1eb1ng c\u01a1 s\u1edf d\u1eef li\u1ec7u \u0111\u1ea1t \u0111\u1ebfn tr\u1ea1ng th\u00e1i nh\u1ea5t qu\u00e1n v\u00e0 m\u1edf k\u1ebft n\u1ed1i th\u00e0nh c\u00f4ng.<\/p>\n<h2>Sao l\u01b0u v\u00e0 Ph\u1ee5c h\u1ed3i Doanh nghi\u1ec7p v\u1edbi CloudSave<\/h2>\n<p>Vi\u1ec7c qu\u1ea3n l\u00fd c\u00e1c t\u1eadp l\u1ec7nh shell t\u00f9y ch\u1ec9nh cho <code>archive_command<\/code>, x\u1eed l\u00fd kh\u1eed tr\u00f9ng l\u1eb7p WAL v\u00e0 \u0111\u1ea3m b\u1ea3o l\u01b0u tr\u1eef ngo\u1ea1i vi an to\u00e0n cho c\u00e1c nh\u1eadt k\u00fd giao d\u1ecbch c\u00f3 th\u1ec3 nhanh ch\u00f3ng tr\u1edf th\u00e0nh g\u00e1nh n\u1eb7ng v\u1eadn h\u00e0nh cho c\u00e1c \u0111\u1ed9i ng\u0169 CNTT.<\/p>\n<p>\u0110\u00e2y l\u00e0 n\u01a1i CloudSave mang l\u1ea1i gi\u00e1 tr\u1ecb \u0111\u00e1ng k\u1ec3 cho c\u00e1c m\u00f4i tr\u01b0\u1eddng PostgreSQL doanh nghi\u1ec7p. CloudSave t\u00edch h\u1ee3p tr\u1ef1c ti\u1ebfp v\u1edbi c\u00e1c API sao l\u01b0u v\u00e0 l\u01b0u tr\u1eef WAL g\u1ed1c c\u1ee7a PostgreSQL \u0111\u1ec3 lo\u1ea1i b\u1ecf c\u00e1c c\u1ea1m b\u1eaby th\u1ee7 c\u00f4ng \u0111\u00e3 th\u1ea3o lu\u1eadn \u1edf tr\u00ean.<\/p>\n<p>Thay v\u00ec vi\u1ebft c\u00e1c t\u1eadp l\u1ec7nh bash mong manh, CloudSave cung c\u1ea5p m\u1ed9t t\u00edch h\u1ee3p m\u1ea1nh m\u1ebd, d\u1ef1a tr\u00ean t\u00e1c nh\u00e2n ho\u1eb7c kh\u00f4ng c\u1ea7n t\u00e1c nh\u00e2n gi\u00fap:<br \/>\n* <strong>\u0110\u1ea3m b\u1ea3o ph\u00e2n ph\u1ed1i:<\/strong> Thay th\u1ebf c\u00e1c l\u1ec7nh shell ti\u00eau chu\u1ea9n b\u1eb1ng c\u00e1c chuy\u1ec3n \u0111\u1ed5i \u0111\u01b0\u1ee3c x\u00e1c minh, ki\u1ec3m tra t\u1ed5ng ki\u1ec3m tra \u0111\u1ebfn b\u1ed9 l\u01b0u tr\u1eef \u0111\u00e1m m\u00e2y ho\u1eb7c ngo\u1ea1i vi an to\u00e0n.<br \/>\n* <strong>Ng\u0103n ch\u1eb7n WAL Bloat:<\/strong> Ch\u1ee7 \u0111\u1ed9ng gi\u00e1m s\u00e1t th\u01b0 m\u1ee5c <code>pg_wal<\/code> v\u00e0 c\u1ea3nh b\u00e1o cho qu\u1ea3n tr\u1ecb vi\u00ean r\u1ea5t l\u00e2u tr\u01b0\u1edbc khi x\u1ea3y ra t\u00ecnh tr\u1ea1ng c\u1ea1n ki\u1ec7t ph\u00e2n v\u00f9ng.<br \/>\n* <strong>T\u1ef1 \u0111\u1ed9ng h\u00f3a PITR:<\/strong> \u0110\u01a1n gi\u1ea3n h\u00f3a Ph\u1ee5c h\u1ed3i t\u1ea1i th\u1eddi \u0111i\u1ec3m th\u00f4ng qua giao di\u1ec7n tr\u1ef1c quan. B\u1ea1n ch\u1ecdn ch\u00ednh x\u00e1c ph\u00fat b\u1ea1n mu\u1ed1n ph\u1ee5c h\u1ed3i v\u00e0 CloudSave t\u1ef1 \u0111\u1ed9ng truy xu\u1ea5t b\u1ea3n sao l\u01b0u c\u01a1 s\u1edf ch\u00ednh x\u00e1c v\u00e0 truy\u1ec1n ph\u00e1t chu\u1ed7i t\u1ec7p WAL c\u1ea7n thi\u1ebft \u0111\u1ec3 \u0111\u1ea1t \u0111\u1ebfn tr\u1ea1ng th\u00e1i \u0111\u00f3.<br \/>\n* <strong>X\u1eed l\u00fd Timeline:<\/strong> Qu\u1ea3n l\u00fd th\u00f4ng minh l\u1ecbch s\u1eed timeline c\u1ee7a PostgreSQL, \u0111\u1ea3m b\u1ea3o r\u1eb1ng c\u00e1c k\u1ecbch b\u1ea3n chuy\u1ec3n \u0111\u1ed5i d\u1ef1 ph\u00f2ng (failover) v\u00e0 split-brain kh\u00f4ng l\u00e0m h\u1ecfng kho l\u01b0u tr\u1eef sao l\u01b0u c\u1ee7a b\u1ea1n.<\/p>\n<p>B\u1eb1ng c\u00e1ch gi\u1ea3m b\u1edbt g\u00e1nh n\u1eb7ng qu\u1ea3n l\u00fd WAL cho CloudSave, c\u00e1c DBA c\u00f3 th\u1ec3 t\u1eadp trung v\u00e0o t\u1ed1i \u01b0u h\u00f3a truy v\u1ea5n v\u00e0 hi\u1ec7u n\u0103ng c\u01a1 s\u1edf d\u1eef li\u1ec7u, bi\u1ebft r\u1eb1ng c\u00e1c SLA v\u1ec1 RPO v\u00e0 RTO c\u1ee7a h\u1ecd \u0111\u01b0\u1ee3c b\u1ea3o v\u1ec7 b\u1edfi m\u1ed9t n\u1ec1n t\u1ea3ng c\u1ea5p doanh nghi\u1ec7p.<\/p>\n<h2>K\u1ebft lu\u1eadn<\/h2>\n<p>L\u01b0u tr\u1eef WAL c\u1ee7a PostgreSQL l\u00e0 x\u01b0\u01a1ng s\u1ed1ng c\u1ee7a vi\u1ec7c ph\u1ee5c h\u1ed3i sau th\u1ea3m h\u1ecda c\u01a1 s\u1edf d\u1eef li\u1ec7u. M\u1eb7c d\u00f9 kh\u00e1i ni\u1ec7m sao ch\u00e9p t\u1ec7p t\u1eeb th\u01b0 m\u1ee5c n\u00e0y sang th\u01b0 m\u1ee5c kh\u00e1c c\u00f3 v\u1ebb \u0111\u01a1n gi\u1ea3n, nh\u01b0ng c\u00e1c tr\u01b0\u1eddng h\u1ee3p ngo\u1ea1i l\u1ec7\u2014l\u1ed7i im l\u1eb7ng, c\u1ea1n ki\u1ec7t \u0111\u0129a v\u00e0 ph\u00e2n k\u1ef3 timeline\u2014g\u00e2y ra r\u1ee7i ro nghi\u00eam tr\u1ecdng cho t\u00ednh to\u00e0n v\u1eb9n c\u1ee7a d\u1eef li\u1ec7u.<\/p>\n<p>B\u1eb1ng c\u00e1ch hi\u1ec3u ki\u1ebfn tr\u00fac c\u1ee7a <code>pg_wal<\/code>, tr\u00e1nh nghi\u00eam ng\u1eb7t c\u00e1c c\u1ea5u h\u00ecnh <code>archive_command<\/code> mang t\u00ednh ph\u00e1 ho\u1ea1i, gi\u00e1m s\u00e1t <code>pg_stat_archiver<\/code> v\u00e0 t\u1eadn d\u1ee5ng c\u00e1c n\u1ec1n t\u1ea3ng sao l\u01b0u doanh nghi\u1ec7p nh\u01b0 CloudSave, b\u1ea1n c\u00f3 th\u1ec3 x\u00e2y d\u1ef1ng m\u1ed9t c\u01a1 s\u1edf h\u1ea1 t\u1ea7ng PostgreSQL ki\u00ean c\u1ed1 c\u00f3 kh\u1ea3 n\u0103ng s\u1ed1ng s\u00f3t sau c\u00e1c l\u1ed7i ph\u1ea7n c\u1ee9ng, l\u1ed7i con ng\u01b0\u1eddi v\u00e0 c\u00e1c s\u1ef1 c\u1ed1 th\u1ea3m kh\u1ed1c m\u00e0 kh\u00f4ng l\u00e0m m\u1ea5t m\u1ed9t giao d\u1ecbch \u0111\u00e3 cam k\u1ebft n\u00e0o.<\/p>\n<blockquote>\n<p>Kh\u00e1m ph\u00e1 c\u00e1c c\u1ea1m b\u1eaby ph\u1ed5 bi\u1ebfn c\u1ee7a vi\u1ec7c l\u01b0u tr\u1eef WAL trong PostgreSQL d\u1eabn \u0111\u1ebfn m\u1ea5t d\u1eef li\u1ec7u. T\u00ecm hi\u1ec3u c\u00e1c ph\u01b0\u01a1ng ph\u00e1p th\u1ef1c h\u00e0nh t\u1ed1t nh\u1ea5t t\u1eeb chuy\u00ean gia DBA, c\u00e1c m\u1eb9o c\u1ea5u h\u00ecnh v\u00e0 c\u00e1ch \u0111\u1ea3m b\u1ea3o Ph\u1ee5c h\u1ed3i t\u1ea1i th\u1eddi \u0111i\u1ec3m (PITR) \u0111\u00e1ng tin c\u1eady cho c\u00e1c c\u01a1 s\u1edf d\u1eef li\u1ec7u doanh nghi\u1ec7p.<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>**<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"PostgreSQL WAL Archiving: Pitfalls & Data Loss Risks","rank_math_description":"**","rank_math_focus_keyword":"postgresql wal archiving","footnotes":""},"categories":[767],"tags":[768,1228,771,772,773,774,3266],"class_list":["post-4560","post","type-post","status-publish","format-standard","hentry","category-database-backup","tag-data-loss-prevention","tag-database-administration","tag-pitr","tag-point-in-time-recovery","tag-postgresql","tag-rpo","tag-wal-archiving"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.7 (Yoast SEO v27.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>PostgreSQL WAL Archiving: Pitfalls &amp; Data Loss Risks<\/title>\n<meta name=\"description\" content=\"**\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudsave.app\/vi\/knowledge-base\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"L\u01b0u tr\u1eef WAL trong PostgreSQL: Nh\u1eefng c\u1ea1m b\u1eaby ph\u1ed5 bi\u1ebfn v\u00e0 r\u1ee7i ro m\u1ea5t d\u1eef li\u1ec7u\" \/>\n<meta property=\"og:description\" content=\"**\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudsave.app\/vi\/knowledge-base\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\/\" \/>\n<meta property=\"og:site_name\" content=\"CloudSave\" \/>\n<meta property=\"article:published_time\" content=\"2026-06-14T19:31:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-15T15:05:19+00:00\" \/>\n<meta name=\"author\" content=\"shervinrv\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"shervinrv\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 ph\u00fat\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/knowledge-base\\\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/knowledge-base\\\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\\\/\"},\"author\":{\"name\":\"shervinrv\",\"@id\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/#\\\/schema\\\/person\\\/286beefe68281d868e87f46603a7ae4d\"},\"headline\":\"L\u01b0u tr\u1eef WAL trong PostgreSQL: Nh\u1eefng c\u1ea1m b\u1eaby ph\u1ed5 bi\u1ebfn v\u00e0 r\u1ee7i ro m\u1ea5t d\u1eef li\u1ec7u\",\"datePublished\":\"2026-06-14T19:31:10+00:00\",\"dateModified\":\"2026-06-15T15:05:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/knowledge-base\\\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\\\/\"},\"wordCount\":3628,\"publisher\":{\"@id\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/#\\\/schema\\\/person\\\/286beefe68281d868e87f46603a7ae4d\"},\"keywords\":[\"data loss prevention\",\"Database Administration\",\"pitr\",\"point-in-time recovery\",\"postgresql\",\"rpo\",\"wal archiving\"],\"articleSection\":[\"Database Backup\"],\"inLanguage\":\"vi\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/knowledge-base\\\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\\\/\",\"url\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/knowledge-base\\\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\\\/\",\"name\":\"PostgreSQL WAL Archiving: Pitfalls & Data Loss Risks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/#website\"},\"datePublished\":\"2026-06-14T19:31:10+00:00\",\"dateModified\":\"2026-06-15T15:05:19+00:00\",\"description\":\"**\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/knowledge-base\\\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\\\/#breadcrumb\"},\"inLanguage\":\"vi\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/cloudsave.app\\\/vi\\\/knowledge-base\\\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/knowledge-base\\\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"L\u01b0u tr\u1eef WAL trong PostgreSQL: Nh\u1eefng c\u1ea1m b\u1eaby ph\u1ed5 bi\u1ebfn v\u00e0 r\u1ee7i ro m\u1ea5t d\u1eef li\u1ec7u\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/#website\",\"url\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/\",\"name\":\"CloudSave\",\"description\":\"CloudSave\",\"publisher\":{\"@id\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/#\\\/schema\\\/person\\\/286beefe68281d868e87f46603a7ae4d\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"vi\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/#\\\/schema\\\/person\\\/286beefe68281d868e87f46603a7ae4d\",\"name\":\"shervinrv\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"vi\",\"@id\":\"https:\\\/\\\/cloudsave.app\\\/wp-content\\\/uploads\\\/2026\\\/02\\\/Logo_Name-2.png\",\"url\":\"https:\\\/\\\/cloudsave.app\\\/wp-content\\\/uploads\\\/2026\\\/02\\\/Logo_Name-2.png\",\"contentUrl\":\"https:\\\/\\\/cloudsave.app\\\/wp-content\\\/uploads\\\/2026\\\/02\\\/Logo_Name-2.png\",\"width\":859,\"height\":150,\"caption\":\"shervinrv\"},\"logo\":{\"@id\":\"https:\\\/\\\/cloudsave.app\\\/wp-content\\\/uploads\\\/2026\\\/02\\\/Logo_Name-2.png\"},\"sameAs\":[\"http:\\\/\\\/cloudsave.app\"],\"url\":\"https:\\\/\\\/cloudsave.app\\\/vi\\\/knowledge-base\\\/author\\\/shervinrv\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"PostgreSQL WAL Archiving: Pitfalls & Data Loss Risks","description":"**","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudsave.app\/vi\/knowledge-base\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\/","og_locale":"vi_VN","og_type":"article","og_title":"L\u01b0u tr\u1eef WAL trong PostgreSQL: Nh\u1eefng c\u1ea1m b\u1eaby ph\u1ed5 bi\u1ebfn v\u00e0 r\u1ee7i ro m\u1ea5t d\u1eef li\u1ec7u","og_description":"**","og_url":"https:\/\/cloudsave.app\/vi\/knowledge-base\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\/","og_site_name":"CloudSave","article_published_time":"2026-06-14T19:31:10+00:00","article_modified_time":"2026-06-15T15:05:19+00:00","author":"shervinrv","twitter_card":"summary_large_image","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"shervinrv","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"19 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/cloudsave.app\/vi\/knowledge-base\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\/#article","isPartOf":{"@id":"https:\/\/cloudsave.app\/vi\/knowledge-base\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\/"},"author":{"name":"shervinrv","@id":"https:\/\/cloudsave.app\/vi\/#\/schema\/person\/286beefe68281d868e87f46603a7ae4d"},"headline":"L\u01b0u tr\u1eef WAL trong PostgreSQL: Nh\u1eefng c\u1ea1m b\u1eaby ph\u1ed5 bi\u1ebfn v\u00e0 r\u1ee7i ro m\u1ea5t d\u1eef li\u1ec7u","datePublished":"2026-06-14T19:31:10+00:00","dateModified":"2026-06-15T15:05:19+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudsave.app\/vi\/knowledge-base\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\/"},"wordCount":3628,"publisher":{"@id":"https:\/\/cloudsave.app\/vi\/#\/schema\/person\/286beefe68281d868e87f46603a7ae4d"},"keywords":["data loss prevention","Database Administration","pitr","point-in-time recovery","postgresql","rpo","wal archiving"],"articleSection":["Database Backup"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/cloudsave.app\/vi\/knowledge-base\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\/","url":"https:\/\/cloudsave.app\/vi\/knowledge-base\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\/","name":"PostgreSQL WAL Archiving: Pitfalls & Data Loss Risks","isPartOf":{"@id":"https:\/\/cloudsave.app\/vi\/#website"},"datePublished":"2026-06-14T19:31:10+00:00","dateModified":"2026-06-15T15:05:19+00:00","description":"**","breadcrumb":{"@id":"https:\/\/cloudsave.app\/vi\/knowledge-base\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudsave.app\/vi\/knowledge-base\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cloudsave.app\/vi\/knowledge-base\/l%c6%b0u-tr%e1%bb%af-wal-trong-postgresql-nh%e1%bb%afng-c%e1%ba%a1m-b%e1%ba%aby-ph%e1%bb%95-bi%e1%ba%bfn-v%c3%a0-r%e1%bb%a7i-ro-m%e1%ba%a5t-d%e1%bb%af-li%e1%bb%87u\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudsave.app\/vi\/"},{"@type":"ListItem","position":2,"name":"L\u01b0u tr\u1eef WAL trong PostgreSQL: Nh\u1eefng c\u1ea1m b\u1eaby ph\u1ed5 bi\u1ebfn v\u00e0 r\u1ee7i ro m\u1ea5t d\u1eef li\u1ec7u"}]},{"@type":"WebSite","@id":"https:\/\/cloudsave.app\/vi\/#website","url":"https:\/\/cloudsave.app\/vi\/","name":"CloudSave","description":"CloudSave","publisher":{"@id":"https:\/\/cloudsave.app\/vi\/#\/schema\/person\/286beefe68281d868e87f46603a7ae4d"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudsave.app\/vi\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":["Person","Organization"],"@id":"https:\/\/cloudsave.app\/vi\/#\/schema\/person\/286beefe68281d868e87f46603a7ae4d","name":"shervinrv","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/cloudsave.app\/wp-content\/uploads\/2026\/02\/Logo_Name-2.png","url":"https:\/\/cloudsave.app\/wp-content\/uploads\/2026\/02\/Logo_Name-2.png","contentUrl":"https:\/\/cloudsave.app\/wp-content\/uploads\/2026\/02\/Logo_Name-2.png","width":859,"height":150,"caption":"shervinrv"},"logo":{"@id":"https:\/\/cloudsave.app\/wp-content\/uploads\/2026\/02\/Logo_Name-2.png"},"sameAs":["http:\/\/cloudsave.app"],"url":"https:\/\/cloudsave.app\/vi\/knowledge-base\/author\/shervinrv\/"}]}},"_links":{"self":[{"href":"https:\/\/cloudsave.app\/vi\/wp-json\/wp\/v2\/posts\/4560","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudsave.app\/vi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudsave.app\/vi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudsave.app\/vi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudsave.app\/vi\/wp-json\/wp\/v2\/comments?post=4560"}],"version-history":[{"count":3,"href":"https:\/\/cloudsave.app\/vi\/wp-json\/wp\/v2\/posts\/4560\/revisions"}],"predecessor-version":[{"id":5724,"href":"https:\/\/cloudsave.app\/vi\/wp-json\/wp\/v2\/posts\/4560\/revisions\/5724"}],"wp:attachment":[{"href":"https:\/\/cloudsave.app\/vi\/wp-json\/wp\/v2\/media?parent=4560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudsave.app\/vi\/wp-json\/wp\/v2\/categories?post=4560"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudsave.app\/vi\/wp-json\/wp\/v2\/tags?post=4560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}