Skip to content
Planet PostgreSQL·· 3d ago

How PostgreSQL 19’s WAIT FOR LSN Offers an Alternative to Synchronous Replication

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

Brief · Based on the source excerpt

PostgreSQL 19’s WAIT FOR LSN lets applications choose when and where to wait for an LSN to reach a standby so replica reads can see recent writes. The author recommends waiting for PostgreSQL 19.1 before production use because 19.0 lacks a critical fix.

Why It Matters

Applications that need to read their own writes from a replica can wait for WAL on demand rather than making every commit wait for a standby to satisfy that read requirement.

Technical Breakdown · Distilled from the original source

From Commit-Time Waiting to On-Demand Waiting

  • PostgreSQL generates a new log sequence number (LSN) whenever it writes to WAL. WAIT FOR LSN provides a way to wait for a specified LSN to reach a standby, while letting the application choose when and where to wait.
  • The author recalls two requirements that often led customers to synchronous replication: avoiding data loss and letting users see what they just saved even when reading from a replica. The operational problems he encountered included all commits hanging and standby failures causing database outages. For replica reads, on-demand waiting offers a different place to put that wait.

Production Adoption and Follow-Up Testing

  • The author tested the feature and took part in developer mailing list discussions before PostgreSQL 19 was released. He also tested PostgreSQL 19.0. He suggests starting application design and development around the feature but holding off on production use until PostgreSQL 19.1 because 19.0 lacks a critical fix.
  • Part 1 focuses on the trade-off with synchronous replication and the use of on-demand waiting. Part 2 covers a walkthrough using only psql and the feature’s history. Part 3 covers the load test results, two bugs found during testing, and a workaround for 19.0.
Source: Planet PostgreSQL· postgr.es

PG Radar summarizes verified changes and impact. Read the original post for full technical details and code samples.

Read Official Source

Related PostgreSQL Reference