"cannot execute in a read-only transaction": you are on the replica
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.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.
You’re reading an older version. View current skill →