跳到正文
每分钟自动更新
  1. Simon Willison

    PostgreSQL 19 Released

    中文摘要

    PostgreSQL 19 版本发布 每年 PostgreSQL 都会在 9 月发布新版本,但今年的版本推迟了两个月才发布,这主要是因为 PostgreSQL 团队需要处理大量问题,这些问题是由于持续的 AI 报告的漏洞灾难所导致的。这次的发布绝对值得等待。我最喜欢的新功能是这个:对于将读取操作发送到备用服务器的应用程序,PostgreSQL 19 新增了“读自己写”的一致性,通过新的 WAIT FOR LSN 命令实现。备用服务器上的会话可以使用 WAIT FOR LSN 命令,等待直到备用服务器已经重放了到特定日志序列号(LSN)的预写日志(WAL)后再运行查询,这样应用程序就可以在主服务器上读取它刚刚写入的数据。在实际操作中,这看起来像这样: UPDATE movie SET genre = 'Dramatic' WHERE genre = 'Drama'; SELECT pg_current_wal_insert_lsn(); 该命令会返回类似 0/0306EE20 的值。将该值存储在某个地方(一个签名的 cookie 就可以),这样在后续请求中,你的应用程序可以执行: WAIT FOR LSN '0/0306EE20' WITH (TIMEOUT '0.1s'); SELECT * FROM movie WHERE genre = 'Drama'; 超时是可选的——如果你提供了超时时间,而你所连接的副本没有赶上,你将会收到一个错误。

    英文原文

    PostgreSQL 19 Released Most years PostgreSQL ships a new release in September, but this year's release came two months later thanks mainly to the flurry of issues that the PostgreSQL team needed to address as part of the ongoing AI-reported vulnerability apocalypse. This release was definitely worth the wait. My favorite new feature is this one: For applications that send reads to standbys, PostgreSQL 19 adds "read-your-writes" consistency with the new WAIT FOR LSN command. A session on a standby can use WAIT FOR LSN to wait until the standby has replayed the write-ahead log (WAL) up to a specific log sequence number (LSN) before running a query, so the application can read data it just wrote on the primary. In practice, that looks like this: UPDATE movie SET genre = 'Dramatic' WHERE genre = 'Drama'; SELECT pg_current_wal_insert_lsn(); That returns a value like 0/0306EE20 . Store that somewhere (a signed cookie would work) such that on a subsequent request your application can do: WAIT FOR LSN '0/0306EE20' WITH (TIMEOUT '0.1s'); SELECT * FROM movie WHERE genre = 'Drama'; The timeout is optional - if you provide one you'll get an error if the replica you are talking to doesn't catch

已经到底了