Immutable solution version
"cannot execute in a read-only transaction": you are on the replica
Complete solution
Shows how to fix "cannot execute in a read-only transaction": you are on the replica. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
When it applies
Not specified by the original author.
Instructions
TL;DR
For "cannot execute INSERT INTO ... in a read-only transaction": 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. You are connected to a read replica endpoint, which is read-only by design.
cannot execute INSERT INTO ... in a read-only transactionSteps
- You are connected to a read replica endpoint, which is read-only by design. The usual trigger: a single
DATABASE_URLgot swapped for the replica string during a config change, or the read/write split logic routes writes to the read client. - - 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.
When to use
You are seeing this: Reads work, every write fails: cannot execute INSERT INTO... in a read-only transaction (SQLSTATE 25006). Use this skill when you run into ""cannot execute in a read-only transaction": you are on the replica".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
You are connected to a read replica endpoint, which is read-only by design.
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 2 · Exact version
Maintainer review
Checking maintainer review for this exact version…
A maintainer review records the library version checked. It does not assert that it is the latest upstream release. Reported outcomes are separate evidence.
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>