Session ownership steps from two acquisitions to one and then zero through two unlocks; rollback leaves both acquisitions held.

Advisory lock lifetime belongs to its connection or transaction

An advisory lock lets an application coordinate work using an identifier that need not correspond to a table row. For example, workers can agree that only one connection may refresh a particular report at a time. PostgreSQL manages ownership and contention, while the application defines what the identifier means and which work requires it. ...

November 24, 2027 · 4 min · XB Field Notes
Debit A, credit B and a ledger row share one transaction boundary. COMMIT preserves all three transactional writes; ROLLBACK discards all three. The application must choose the required writes.

Transactions make atomic commits

A transaction lets related database changes commit together or be discarded together. Debiting an account, crediting another, and recording a ledger entry belong to the same decision when the operation requires all three. PostgreSQL provides that boundary through BEGIN, COMMIT, and ROLLBACK. The application must still place the correct statements inside it: atomic execution does not discover a forgotten credit or invent a missing business check. ...

May 12, 2027 · 5 min · XB Field Notes
Read Committed and Repeatable Read tracks both begin with reading zero and B committing an increment; their final A steps diverge to two or error 40001.

A transaction can fail and leave you to retry

A competing update does not automatically make a PostgreSQL transaction fail. The outcome depends on isolation, statement behavior, and the state another transaction commits. Treating every collision as the same retryable event can conceal invalid input or repeat a decision made from stale data. The useful boundary is a complete application operation whose reads and writes can be attempted again. ...

February 1, 2027 · 5 min · XB Field Notes
Writer A holds stable.lock, writer B waits at the shared lock, and an ordinary nonparticipating write bypasses the gate to data.

File locks protect a shared protocol and a specific object

A file lock coordinates participants that agree on what to lock, when to acquire it, and which operations belong inside the critical section. Linux offers several lock interfaces with different ownership and release rules. Choosing a filename and calling something named lock is insufficient: the protocol must identify the underlying object, the lock family, and the lifetime of every reference involved. ...

December 5, 2026 · 5 min · XB Field Notes
A retry loop encloses reading again, recomputing, writing and committing. Confirmed 40001 or 40P01 requires rollback, remaining budget and jitter. An unknown commit requires reconciliation before replay.

A bounded retry gives a transaction another chance

A retry can recover a transaction rejected because of concurrent work. It cannot guarantee success, and it does not automatically make external effects idempotent. The retry unit should include every database read and application decision that determined the writes. Reusing an amount calculated from the first attempt’s snapshot can defeat the purpose of starting a fresh transaction. ...

November 9, 2026 · 6 min · XB Field Notes
Lease A with token 1 expires and B obtains token 2. A resumes with a late write, but a resource that has already seen token 2 rejects token 1.

Locks and leases tame concurrent writers

Locks and leases coordinate access to shared resources, but their failure behavior depends on the implementation. Here the concern is exclusive writers; locks can also have shared modes. A lease adds a bounded validity period. Neither a familiar name nor a timeout alone proves that a delayed writer cannot damage data after another writer takes over. ...

October 4, 2026 · 6 min · XB Field Notes
Transaction A holds row 1 and needs row 2, while B holds row 2 and needs row 1. Directed waits form a cycle. PostgreSQL may reject either transaction with 40P01.

Deadlocks happen when two writers wait on each other

A deadlock requires a cycle of incompatible waits. If one transaction holds a row while another waits, the holder can still finish and release it. If both hold a resource the other needs, neither can complete that path. PostgreSQL detects the cycle and aborts one transaction, allowing the other to continue. The application must distinguish that rejection from an ordinary slow wait. ...

August 11, 2026 · 4 min · XB Field Notes
A retained Repeatable Read snapshot includes old row 1 and A’s own newly inserted row 3. After A commits, a fresh read includes new row 1, B’s row 2 and A’s row 3.

MVCC selects row versions through visibility rules

Multi-version concurrency control lets PostgreSQL keep different row versions and decide which ones a query may see. An ordinary reader can continue seeing an older committed version while another transaction writes a newer one. This reduces conflicts between reading and writing, but does not give every transaction one permanently frozen view. Snapshot lifetime depends on isolation, and a transaction can see its own earlier changes even when other transactions cannot. ...

August 8, 2026 · 4 min · XB Field Notes