News for hackers. Stuff that matters.
Re:Testing Postgres race conditions with synchronization bar... by anvevoice on Monday February 16, 2026 @05:06PM (#47040980)
One pattern I've found useful alongside this: Postgres advisory locks (pg_advisory_xact_lock) for cases where the contention isn't row-level but logic-level. For example, if two requests try to create the "first" resource of a type - there's no existing row to SELECT FOR UPDATE against.

Advisory locks let you serialize on an arbitrary key (like a hash of the entity type + parent ID) without needing a dummy row or separate lock table. They auto-release on transaction end, so no cleanup.

The barrier testing approach from the article would work nicely here too - inject the barrier between acquiring the advisory lock and the subsequent insert, then verify the second transaction blocks until the first commits.

Re:Testing Postgres race conditions with synchronization bar... by lirbank on Monday February 16, 2026 @05:12PM (#47041038)
Nice - that's a good case for barriers too. When there's no row to SELECT FOR UPDATE against, you'd inject the barrier after acquiring the advisory lock and verify the second transaction blocks until the first commits.
Re:Testing Postgres race conditions with synchronization bar... by klysm on Monday February 16, 2026 @06:21PM (#47041679)
Seems like a good way to materialize the conflict.
Re:Testing Postgres race conditions with synchronization bar... by deepsun on Monday February 16, 2026 @07:01PM (#47041990)
I always did "INSERT ... ON CONFLICT DO NOTHING".
Re:Testing Postgres race conditions with synchronization bar... by nurettin on Tuesday February 17, 2026 @12:23AM (#47043992)
Does that queue when the table is locked? Or just skip writes entirely whenever there is a transaction?
Re:Testing Postgres race conditions with synchronization bar... by deepsun on Tuesday February 17, 2026 @09:46PM (#47056537)
Yes, unless you SET LOCAL lock_timeout = '1ms'; inside the transaction.