Jobin Augustine: Stop Fighting Synchronous Replication: Meet WAIT FOR LSN – Part 2 – walkthrough for DBAs

2026年12月2日

AI 摘要 AI 生成,可能有误

本文是 PostgreSQL 19 的 WAIT FOR LSN 功能系列文章的第二部分,为 DBA 提供了一份动手实操指南,仅使用两个 psql 会话即可演示副本上的读己之写(read-your-writes)一致性、通过 NO_THROW 进行的超时处理、对等待中会话的监控,以及当备库卡住时 WAIT FOR 与同步复制相比的行为表现。本文还解释了该功能的错误和限制——例如在持有快照或锁时无法使用、且只能作为顶层语句使用——并说明了每条限制存在的原因:防止与恢复进程形成死锁循环。最后,文章回顾了该功能漫长的开发历史,包括六年多时间里的多次提交与被拒。

WAIT FOR LSN in PostgreSQL 19, a 3-part series

  • Part 1: Stop Fighting Synchronous Replication: Meet WAIT FOR LSN – Understand the benefits
  • Part 2: A walkthrough for DBAs (you are here)
  • 继续阅读全文

    为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

    更多来自 Planet PostgreSQL

    Hubert 'depesz' Lubaczewski: Missed in PostgreSQL 19 : Toggle logical decoding dynamically based on logical slot presence.

    AI 摘要On December 23, 2025, Masahiko Sawada committed a patch to PostgreSQL that allows logical decoding to be toggled dynamically based on the presence of logical replication slots. Previously, logical decoding required wal_level to be set to 'logical' at server start, meaning users had to bear the overhead of logical-level WAL logging even when no logical replication slots were in use. Despite this improvement, the feature was missed in PostgreSQL 19.

    Christophe Pettus: All Your GUCs in a Row: session_preload_libraries

    AI 摘要This blog post by Christophe Pettus discusses the PostgreSQL parameter session_preload_libraries, reaffirming the earlier advice to use it instead of local_preload_libraries. The author notes that despite the parameter's simple job of calling dlopen(), there is more fine print to explain than expected, starting with the fact that its default value is empty.

    Umair Shahid: How a 40 TB PostgreSQL Cutover Took One Night

    AI 摘要A regulated payments company successfully migrated over 40 TB of production data to a new EDB Postgres cluster with a single-night cutover, made possible by months of preparation using a replication-based approach. Key lessons included sizing the timeline around the largest tables (8.6 TB and 4.5 TB), using parallel workers to speed up backfill, monitoring WAL growth on the source, and building regulatory notice periods into the schedule. The team also stresses post-cutover 'hypercare' monitoring for a week, which caught a standby replication lag early and prevented potential production issues.

    Dimitri Fontaine: What Changes for SQL in PostgreSQL 19

    AI 摘要This article analyzes what PostgreSQL 19.0, released on November 19, changes for SQL, based on running the queries from The Art of PostgreSQL on versions 19.0 and 18.6 and reading the final release notes. The findings include 7 headline features withdrawn before release, 11 changes affecting existing SQL, roughly 20 new features, and an 8-step upgrade checklist. While release-day posts emphasize REPACK, plan advice, and ON CONFLICT DO SELECT, the change with the most consequences for existing SQL is that the planner now reads NOT NULL constraints and rewrites queries with them.

    Jobin Augustine: Stop Fighting Synchronous Replication: Meet WAIT FOR LSN – Part 1

    AI 摘要This article, the first in a three-part series, introduces PostgreSQL 19's WAIT FOR LSN feature, which allows applications to wait until a given WAL position has reached a standby, offering a flexible alternative to synchronous replication. It explains the drawbacks of synchronous replication—such as all commits hanging indefinitely when a standby fails, with statement_timeout providing no help—and demonstrates how combining WAIT FOR LSN (with modes like standby_replay and standby_flush) with synchronous_commit = off gives per-transaction durability and read-your-writes guarantees. The author also covers important caveats, including timeout handling, connection pool sizing on the standby, and critical tuning of wal_writer_flush_after and wal_writer_delay, while cautioning readers to wait for PostgreSQL 19.1 before production use due to a bug in 19.0.