Lesson 4.1

Transactions and isolation levels

A transaction makes several statements succeed or fail together.

8mIntermediate8.9k students

Overview

Atomic, and only as isolated as you asked

A transaction makes several statements succeed or fail together. That much is familiar; the interesting part is what other transactions can see while yours is running.

The default read-committed level means each statement sees a fresh snapshot, so two statements in one transaction can see different data. Repeatable read fixes the snapshot for the whole transaction, and serializable additionally guarantees the outcome matches some serial order.

Stronger isolation means transactions can be aborted to preserve those guarantees. Code using serializable must be prepared to retry, and a retry loop is a normal part of the design, not a workaround.

In this lesson you will:

  • Group writes into an atomic unit
  • Compare read committed and serializable
  • Handle serialization failures with a retry

Resources

Previous Lesson
Next Lesson
Transactions and isolation levels — PostgreSQL for Application Developers — Vertex