Developer beta 0.1.0-beta.1 documentation. The build is not available for download yet; these pages describe the beta as built and tested on Linux x86-64.

Transactions

BEGIN;
UPDATE accounts SET balance = balance - 10 WHERE id = 1;
UPDATE accounts SET balance = balance + 10 WHERE id = 2;
COMMIT;

What you get

  • Atomicity. The writes of a transaction are applied together or not at all. A commit spanning several tables is journaled (prepare → batches → commit) so a crash at any point leaves either every table’s writes or none of them; recovery discards the batches of a transaction without a commit marker.
  • Durability. COMMIT returns after the write-ahead log is synced (with the default sync_on_write). Acknowledged transactions survive a crash or power loss. A write that fails (a full disk, an I/O error) is never acknowledged and never reappears after a restart: the table refuses further writes until the server is restarted and recovery re-verifies its log (table … is poisoned errors, /health 503). With --no-sync a multi-table transaction is still synced before its commit marker; only single-table statements are acknowledged before they reach disk.
  • Read your writes. Inside a transaction, statements see the transaction’s own uncommitted changes. Other connections do not see them until COMMIT.
  • Isolation: read committed with optimistic write validation. A statement sees the latest committed state. At COMMIT, every row the transaction wrote must be unchanged since the transaction first touched it; otherwise the commit fails with a serialization error and nothing is applied (“first committer wins”). Retry the transaction in that case.

Uncertain outcomes

In one rare case a commit’s outcome is not known when the error is returned: the disk refused the write, then refused the rollback of its bytes, then refused the record of where they end — three I/O failures in a row. The bytes may be complete on disk, and only recovery can tell. HolaDB then answers with an uncertain outcome instead of a failure:

  • native protocol: error code UncertainOutcome (24); PostgreSQL protocol: SQLSTATE 08007 (transaction resolution unknown). The message names the commit position the write reaches if it was applied;
  • the server refuses every write until it is restarted (reads go on), so nothing else commits before recovery decides;
  • after the restart, the write was applied exactly when the recovered position (position()’s second value in the SDKs and the client, any user may call it) is at least the position in the message.

Do not retry such a write blindly: if it was applied, a retry writes it twice. Resolve it first. A failed write of one table inside a multi-table transaction, and a failed transaction prepare, are not uncertain: no commit marker was written, so the transaction is definitely not applied.

What you do not get

  • No snapshot for reads: two SELECTs in one transaction can see different committed states.
  • No range or phantom protection: a SELECT count(*) followed by an insert elsewhere is not detected.
  • No SELECT … FOR UPDATE, no explicit locks, no savepoints.
  • Schema changes (CREATE/DROP/ALTER) do not run inside a transaction; they are refused with DDL inside a transaction is not supported. A schema change made by another connection while your transaction is open fails your next statement and your COMMIT with a serialization error (the schema changed by another connection since this transaction began); nothing of the transaction is applied. Retry it.

Failed statements

Any statement that fails inside a transaction aborts the transaction: later statements are refused with current transaction is aborted (…); ROLLBACK first, and COMMIT reports ROLLBACK instead of committing. This is the PostgreSQL behaviour and what libpq drivers expect.

“Fails” means at any stage and on every path — the native protocol, the PostgreSQL protocol and the embedded API alike: a statement that does not parse, an unsupported construct, a constraint violation, a permission error, a statement timeout, a wrong number of parameters. Nothing of the transaction is applied, whatever succeeded before the failure. Outside a transaction each statement is its own transaction (autocommit) and a failure affects only that statement. With several statements in one request, the statements after a failed one are not run.

Connections

A transaction belongs to a connection (a session). Closing the connection rolls back an open transaction. In the SDKs, the transaction object rolls back when dropped without commit (Rust), when the with block raises (Python) or when the callback throws (TypeScript).

Only one transaction can be open per connection; BEGIN inside a transaction is an error.