Autocommit and Multi-Statement Work

Autocommit typically gives each ordinary statement its own transaction when no explicit transaction is active. A multi-step promise often needs a deliberate boundary.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace two separate effects
  2. Test the midway failure
  3. Compare two independent writes with one unit of work
  4. Test through the real connection settings

Trace two separate effects

An insert can save an order, then a later statement rejects the line. With separate committed statements the first row can remain. See transaction boundaries.

Test the midway failure

Use a fixture where the first write is valid and the second fails a predictable rule. Verify which rows exist afterward. Partial-success tracking explains why both results need checking.[1]

Compare two independent writes with one unit of work

With autocommit, a parent insert can commit by itself and the later child insert can fail. An explicit transaction can defer commit until both succeed. Verify which behavior your driver or framework actually provides. See begin, commit and rollback.

Autocommit: parent write succeeds → committed
Child write fails → parent remains
One transaction: child write fails → roll back both where contract requires it

Test through the real connection settings

A test runner can wrap requests in transactions that differ from production. Check the observed state through another connection and account for runtime-specific settings. Include a valid parent and invalid child.

References

  1. PostgreSQL Global Development Group, Concurrency Control ↩