Immutable solution version
"cannot execute in a read-only transaction": you are on the replica
Complete solution
Symptom: writes fail with "cannot execute INSERT in a read-only transaction" (SQLSTATE 25006). Cause: the connection string points at a read replica. Fix: route writes to the primary.
"cannot execute ... in a read-only transaction": wrong endpoint
Symptom
Reads work, every write fails: cannot execute INSERT INTO ... in a read-only transaction (SQLSTATE 25006).
Cause
You are connected to a read replica endpoint, which is read-only by design. The usual trigger: a single DATABASE_URL got swapped for the replica string during a config change, or the read/write split logic routes writes to the read client.
Confirm
- Compare the connected hostname against the Console: replica endpoints are separate from the primary.
SHOW transaction_read_only;returns on.
Fix
- Writes go to the primary (read_write endpoint); reads can stay on the replica.
- Keep
DATABASE_URLandREPLICA_URLas separate env vars; never derive one by editing the other. - In ORMs, check the read/write split middleware actually sends writes to the primary client.
Verify
A write followed by a read-your-write on the primary succeeds; replica reads still work.
Evidence
Neon's connection error docs (verified live 2026-09-26) list 'cannot execute ... in a read-only transaction (SQLSTATE 25006)' among resolved errors; the read replica docs describe replicas as segregating read-only work from production operations.
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_5CmljsbgipMBg3TFCGX1Bg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">"cannot execute in a read-only transaction": you are on the replica <span>— Vectle</span></a>