Using transactions

Developer-first transactions — syntax, visibility, conflicts, and failure cases.

Version
Latest
v0.1.0 · latest 1 min read
diagram
flowchart LR
    B["BEGIN\nbuffer statements"] --> W["writes\nWAL Data + memory buffer"]
    W --> C["COMMIT\none storage txn: batch + fsync + publish"]
    W --> R["ROLLBACK\nAbort + discard"]
    C --> V["visible per\nMVCC snapshot rules"]
Diagram source · mermaidcopy included
mermaidsource
flowchart LR
    B["BEGIN\nbuffer statements"] --> W["writes\nWAL Data + memory buffer"]
    W --> C["COMMIT\none storage txn: batch + fsync + publish"]
    W --> R["ROLLBACK\nAbort + discard"]
    C --> V["visible per\nMVCC snapshot rules"]

See Run transactions for the task guide. This page is the precise reference.

textsource
BEGIN [TRANSACTION|WORK] [ISOLATION LEVEL …|READ ONLY|…]
START TRANSACTION […] | SET [SESSION|LOCAL] TRANSACTION … | SET … CHARACTERISTICS …
COMMIT [opts] | ROLLBACK [TO [SAVEPOINT] name] [opts]
  • execute_all splits batches depth-aware on ;; BEGIN buffers into pending; COMMIT|ROLLBACK runs the group as one storage transaction.
  • In-txn writes allowed: INSERT/UPDATE/DELETE + CREATE TABLE|VIEW. COPY and UPDATE…FROM in-txn → Unsupported.
  • SET search_path in-batch affects later statements.
  • SET TRANSACTION ISOLATION LEVEL {READ COMMITTED | REPEATABLE READ} and SET SESSION CHARACTERISTICS are accepted and stored as the session default; SERIALIZABLE is rejected, as is changing it mid-transaction or issuing SET TRANSACTION outside a transaction block.
  • Idle transactions are reaped after idle_in_transaction_session_timeout (default 60s, 0 disables): the connection closes with 25P03 — commit or roll back promptly. See Pooling and errors.

Isolation options parse but the engine is single-writer with MVCC snapshots (see MVCC); there is no multi-writer serializable scheduler to tune in v0.1.0.

Was this page helpful?