Transactions
PizzaSQL supports BEGIN, COMMIT, ROLLBACK, SAVEPOINT, RELEASE, and ROLLBACK TO SAVEPOINT for data manipulation. Transactions stage writes in the session and validate observed data when committing. This is not PostgreSQL MVCC, and schema changes are not transactional.
The model: staged writes and optimistic validation
Section titled âThe model: staged writes and optimistic validationâA transaction maintains a session-local overlay:
- Reads consult staged writes and deletes first, which provides read-your-writes behavior.
- Reads remember the row versions and table or predicate generations they observed.
- Inserts, updates, and deletes remain staged until
COMMIT. COMMITsubmits the comparisons and writes as one compare-and-batch operation to PizzaKV.
If observed data changed before commit, validation fails with a serialization conflict instead of overwriting the concurrent change. ROLLBACK discards the staged overlay without applying it to storage.
Transaction control
Section titled âTransaction controlâBEGIN; -- or BEGIN TRANSACTIONUPDATE accounts SET balance = balance - 100 WHERE name = 'alice';UPDATE accounts SET balance = balance + 100 WHERE name = 'bob';COMMIT;BEGIN;INSERT INTO log VALUES (1);SAVEPOINT sp1;INSERT INTO log VALUES (2);ROLLBACK TO sp1; -- undoes the second insertRELEASE sp1;COMMIT; -- keeps the first insertBEGINinside an open transaction is an error.COMMIT/ROLLBACKwith no open transaction is an error.SAVEPOINToutside a transaction implicitly opens one.ROLLBACK TO namediscards staged operations back to the savepoint and removes savepoints created after it.RELEASE nameremoves a savepoint; releasing the outer-most savepoint has no effect on the transaction.
Guarantees and limitations
Section titled âGuarantees and limitationsâ- DML is staged until commit. An open transactionâs data writes are visible to that session through its overlay and are not published as independent storage operations.
- Conflicts are optimistic. Another connection can continue working while a transaction is open. A transaction that observed stale rows or table generations can fail at commit and should be retried.
- DDL is not transactional.
CREATE TABLE,DROP TABLE,ALTER TABLE,CREATE INDEX, andDROP INDEXwrite through the schema manager rather than the transaction overlay. Rolling back does not undo DDL executed inside a transaction. - This is not MVCC. PizzaSQL does not provide PostgreSQL snapshots, row locks, or the full PostgreSQL isolation-level model.
Failed transactions over the wire
Section titled âFailed transactions over the wireâOn the PostgreSQL protocol, the connection tracks transaction state. If a statement inside a transaction block errors:
- The connection enters a âfailed transactionâ state and rejects further commands with SQLSTATE
25P02until the client sendsROLLBACK(orROLLBACK TO SAVEPOINT). - This mirrors PostgreSQLâs aborted-transaction behaviour.
Managed service restrictions
Section titled âManaged service restrictionsâ- The managed HTTP query and execute endpoints reject transaction statements (
BEGIN,COMMIT,ROLLBACK,SAVEPOINT,RELEASE) with501 Not Implemented, and the/executeendpointâstransaction: trueflag is rejected too. Use the PostgreSQL wire protocol if you need transactions on the managed service. - The managed PostgreSQL proxy forwards transaction statements to the engine, so transactions work normally over
psql/drivers. - The engineâs own raw HTTP API and CLI do support transaction statements, but those surfaces are internal to the platform.
Practical guidance
Section titled âPractical guidanceâ- Keep transactions short to reduce the chance of a serialization conflict.
- Do not rely on rolling back DDL â migrate schema outside of transactions, or test-and-recover manually.
- Retry a transaction when the PostgreSQL connection returns SQLSTATE
40001. - Prefer the PostgreSQL connection path for anything that needs multi-statement atomicity on the managed service.