SQLSTATE 25006Severity mediumLab verified

Incident brief

Read-only SQL transaction

A write was attempted inside a transaction explicitly marked READ ONLY. PostgreSQL blocked the write instead of allowing it.

What lands in your log

ERROR: cannot execute INSERT in a read-only transaction

Reproduced on PostgreSQL 16.14Verified 2026-07-16 (Docker lab, PostgreSQL 16.14)Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What triggers it
BEGIN READ ONLY.
Fix
Don't open the transaction as READ ONLY if it needs to write to ordinary tables.
Proof
Reproduced on PostgreSQL 16.14 → An INSERT into an ordinary table inside a READ ONLY transaction was rejected with SQLSTATE 25006. No row was added.

Fix

What to do right now

Application-level steps for this error.

  • Don't open the transaction as READ ONLY if it needs to write to ordinary tables.
  • Writes to temporary tables are allowed even inside a READ ONLY transaction, see the premium test.
  • Don't assume SET SESSION CHARACTERISTICS can flip the current transaction to read/write mid-flight, see the counterexample.
Fix SQL
BEGIN;
INSERT INTO audit.events VALUES (1);
COMMIT;

Runbook to fix this

The runbook for this incident

Full step-by-step fixes for the condition behind this error: the diagnosis, the exact SQL, and output captured in the lab.

Connected

Everything this error touches

Every page this SQLSTATE connects to: the concept that explains it, the runbooks that fix it, the parameters you tune to prevent it, and the sibling errors it travels with. All real cross-references. Jump straight in, or open the full interactive map.

Open in the interactive map →

Verification

PG 16.14
Last verified
2026-07-16 (Docker lab, PostgreSQL 16.14)
Verification scope
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed
ShareLinkedInX

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops