Trong PostgreSQL, các replica bất đồng bộ thường trả về dữ liệu cũ vì chúng chỉ áp dụng WAL sau một khoảng trễ, gây ra hiện tượng đọc không thấy bản ghi vừa ghi trên primary.
Phiên bản PostgreSQL 19 bổ sung lệnh WAIT FOR cho phép một truy vấn READ chỉ định vị trí WAL (log sequence number) mà nó muốn chờ trước khi trả về kết quả.
Khi lệnh được thực hiện, phiên bản server sẽ tạm dừng việc đọc cho đến khi WAL đã được replay tới vị trí đó trên replica, từ đó đảm bảo read‑your‑writes mà không cần chuyển sang synchronous replication hoặc tăng toàn bộ độ trễ hệ thống.
Điều đáng học: thay vì phải bật synchronous replication toàn cluster hoặc chịu đọc stale data, разработчики có thể sử dụng WAIT FOR cho các giao dịch cụ thể nơi cần nhất quán đọc‑ghi, tiết kiệm tài nguyên và kiểm soát độ trễ chi tiết.
Ví dụ thực tế, một lệnh như SELECT ... WAIT FOR LSN '0/3000000' sẽ chỉ trả về sau khi replica đã áp dụng WAL tới LSN đó, cho phép ứng dụng xác nhận ngay lập tức việc ghi vừa thực hiện trên primary mà không ảnh hưởng đến các truy vấn khác.
AI summaries can be wrong. Read the original before relying on anything important.
Why read it: Bài này giúp lập trình viên hiểu cách sử dụng WAIT FOR trong PostgreSQL 19 để đảm bảo tính nhất quán read-your-writes trên bản sao bất đồng bộ.
Answer 3 short questions to earn reward points for this article. Only do it if you want the points.
3 questions · under a minute · optional
Source: https://clickhouse.com/blog/postgresql-19-wait-for-read-your-writes. 8 Sync News only summarizes and links out; content copyright belongs to the authors and original sources.
Read the news here, practice coding, follow structured courses and train for IELTS on our sibling products — all connected through one 8 Sync account.
The ecosystem home: product overviews, blog and full pricing.
ExploreLearn along a clear roadmap: videos, auto-graded quizzes, certificates and mentors who ship for a living.
View the roadmap1,000 DSA problems in Vietnamese, auto-graded across 7 languages — many FREE, right in your browser.
Practice for freeAI grading for all four IELTS skills with detailed rubric feedback.
Try it freeA 22 MB AI IDE for Vietnamese devs.
Download freeOrganizational memory for AI agents.
ExploreAI that staffs your Fanpage and qualifies leads for you.
Try itAgents write faster than humans can review. Typed graphs check every write, checked queries validate every question, and branches keep the human where true is decided.
Event-driven systems only agree eventually. Here’s how we check they actually got there: deadlines, data ownership, and a reconciliation job that walks the floor.
OccupySaaS is a protest movement in code: laid-off developers building clean-room, open-source, drop-in replacements for the SaaS giants. First up: ZeroAuthy (Auth0) and SalesCompel (Salesforce).
json vs jsonb in PostgreSQL 17 and 18, measured on six document shapes: when jsonb is 23% smaller or 41% larger, read speed, GIN, and what it changes.
An API can save an order and crash before publishing the message that tells other services about it.
Postgres 18’s new file_copy_method = clone setting lets you give every git worktree its own copy of your database in seconds, without eating up your disk.
If you have certain lines of code that repeat over and over again in a project, there's a pretty standard solution for it: using a function. But what about when you have the same project file setup th
Discover optimizer hints in MariaDB Server 13.0: MySQL-compatible syntax, query plan control, and advanced features for views and query blocks.
Loading comments…