Skip to content

Sessions & Transactions

tonic is session-aware. Query files and serve --stdio can preserve transaction state across statements when execution uses a reusable session.

Autocommit is execution intent, not saved connection config.

Valid values are on and off. The default is on.

Terminal window
tonic query exec --target warehouse --autocommit off --sql 'update jobs set touched = true where id = 1'

For inline SQL, autocommit=off wraps the single non-transaction statement in a transaction and commits on success.

Primary session autocommit resolves in this order:

  1. tonic-file: autocommit=...
  2. CLI --autocommit
  3. default on

Handle session autocommit resolves in this order:

  1. tonic-bind: ... autocommit=...
  2. tonic-file: autocommit=...
  3. CLI --autocommit
  4. default on

Ephemeral sessions always use autocommit=on.

Transaction control is SQL-first:

begin;
update accounts set plan = 'pro' where id = 1;
commit;

Supported transaction-control actions include begin, start transaction, commit, rollback, rollback to, savepoint, and release savepoint.

Inline query exec --sql rejects transaction-control statements. Use a query file or a service session for multi-statement transaction control.

Statement errors do not automatically destroy reusable sessions. The runtime does not auto-commit or auto-rollback just because a statement failed.

When a reusable session closes with an open transaction, tonic attempts a best-effort rollback before closing the underlying connection.