Jan Kristof Nidzwetzki: Barriers, Volatile, and Atomics: How PostgreSQL Orders Memory Accesses
2026年11月26日
In the PostgreSQL source code, you will find memory and compiler barriers in various places like pg_memory_barrier(), pg_write_barrier(), pg_read_barrier(), or pg_compiler_barrier(). These macros are needed to ensure that the compiler and CPU do not reorder memory accesses in a way that would break the correctness of the code. Closely related are volatile variables and atomic operations, which you will find in the source code as well.
PostgreSQL uses a process-based architecture, where a separate process handles each database connection. These processes use shared memory to communicate, allowing multiple processes to read and write values simultaneously. On multi-processor systems, these processes can run on different CPU cores, each with its own caches.
Intuitively, you would expect that if one process writes two values to shared memory, another process reading them would see the same order. But that’s not always the case, and it can cause tricky bugs that are hard to track down. To make matters worse, code that has run fine on x86 for years might suddenly break on ARM, a common platform for PostgreSQL, like AWS Graviton servers or Apple Silicon machines.
继续阅读全文
为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。
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.
WAIT FOR LSN in PostgreSQL 19, a 3-part series Part 1: Stop Fighting Synchronous Replication: Meet WAIT FOR LSN (you are here) Part 2: Hands-on with WAIT FOR LSN: a walkthrough for DBAs Part 3: WAIT FOR LSN under load: numbers, tuning and t
`server_version` and `server_version_num` look simple until you upgrade packages without restarting the server, or put a pooler in front of it. (I consult on PostgreSQL through PGX Inc..)
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: w
A customer asked me recently how to optimize performance writing to PostgreSQL from a Flink pipeline. Without hesitation, I recommended using PostgreSQL’s COPY interface. The result was approximately twice the throughput. This post explores