Transactions
Syntax
BEGIN;
INSERT INTO accounts (id, balance) VALUES (1, 100);
UPDATE accounts SET balance = balance - 50 WHERE id = 1;
UPDATE accounts SET balance = balance + 50 WHERE id = 2;
COMMIT; -- or ROLLBACK
How it works
Transactions are implemented via a compensating-action log: every mutation records its inverse (INSERT → DELETE, UPDATE → restore the pre-image, DELETE → re-insert). ROLLBACK replays the log in reverse.
This is not MVCC — the current model is closer to read-committed, without snapshot isolation. But ROLLBACK genuinely undoes every change in the session, and the WAL (fsynced on every commit) guarantees a committed transaction survives any crash — kill, SIGTERM, power loss.
Writer serialization
Writes are serialized SQLite-style: a database-wide writer lock with DEFERRED/IMMEDIATE modes — concurrent writers never interleave, which keeps reasoning about consistency simple at the cost of sequential writes.
Related pages
← Previous
Functions & expressionsNext →
HTTP API