Deepak Mahto: Exploring PostgreSQL 19: A Developer’s Guide to New Features – Part 1: INSERT ON CONFLICT DO SELECT
2026年11月30日
AI 摘要 AI 生成,可能有误
PostgreSQL 19 引入了 INSERT … ON CONFLICT DO SELECT,这是一种新的冲突处理动作,在发生冲突时返回已存在的行而不对其进行修改,从而在单条语句中实现原子性的“获取或创建”。这消除了以往的变通方案,例如先执行 DO NOTHING 再进行第二次 SELECT、在每次查找时都会产生死元组和 VACUUM 负担的哑 DO UPDATE,以及会创建子事务和中止行的 Oracle 风格 EXCEPTION 块。本文介绍了该功能的规则(必须使用 RETURNING 子句和冲突目标,可选地通过 FOR UPDATE 进行行锁定)、如何在 RETURNING 中使用 OLD/NEW 区分插入的行与查询获取的行,以及从 Oracle 和 SQL Server 代码迁移的模式。
Read time: ~8 minutes
PostgreSQL 19 finally lets INSERT hand back the row that already exists, no dummy update, no exception block, no second round trip.
PostgreSQL 19 was released on November 19, 2026. With it, I’m starting a new series: what’s new in PostgreSQL 19 primarily for application developers, the people writing SQL and PL/pgSQL every day, or supporting migrations to PostgreSQL.
继续阅读全文
为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。
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.
AI 摘要This article is Part 2 of a series on PostgreSQL 19's WAIT FOR LSN feature, offering DBAs a hands-on walkthrough using just two psql sessions to demonstrate read-your-writes consistency on replicas, timeout handling with NO_THROW, monitoring waiting sessions, and how WAIT FOR behaves when a standby is stuck compared to synchronous replication. It also explains the feature's errors and restrictions—such as being unusable while holding snapshots or locks and only allowed as a top-level statement—showing why each exists to prevent deadlock cycles with recovery. Finally, it recounts the feature's long development history, including multiple commits and rejections over more than six years.
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.
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.
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.