← All notes

PostgreSQL transactions and isolation levels

Short answer

Wrap related statements in BEGIN; ... COMMIT; so they succeed or fail as one all-or-nothing unit. Use ROLLBACK to discard them. PostgreSQL's default isolation level is Read Committed. [S1][S2]

Example

BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE name = 'a';
UPDATE accounts SET balance = balance + 100 WHERE name = 'b';
COMMIT;

Isolation in brief

Levels differ in which anomalies they prevent, such as dirty reads, non-repeatable reads and phantom reads. [S2] Raise the level with SET TRANSACTION ISOLATION LEVEL ... only when you need it, and be ready to retry on serialization failures.

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: PostgreSQL Global Development Group, PostgreSQL: Documentation: 18: 3.4. Transactions, PostgreSQL License; PostgreSQL Global Development Group, PostgreSQL: Documentation: 18: 13.2. Transaction Isolation, PostgreSQL License.

Cite this

Permanent ID: iil:note:428gfz9t

iinventedlight. 2026. "PostgreSQL transactions and isolation levels." iinventedlight Library, iil:note:428gfz9t, version of 2026-11-04. https://iinventedlight.com/library/notes/postgres-transactions/. License: CC-BY-4.0.

@misc{iil_note_428gfz9t,
  author = {{iinventedlight}},
  title = {{PostgreSQL transactions and isolation levels}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/postgres-transactions/},
  note = {Permanent ID iil:note:428gfz9t. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/postgres-transactions.md.