25006ERRORTier 2 — Caution✅ HIGH confidenceread only SQL transaction
What this means
SQLSTATE 25006 is raised when a write operation (INSERT, UPDATE, DELETE, CREATE, etc.) is attempted inside a transaction that was explicitly set to READ ONLY, or on a standby server that does not allow writes.
Why it happens
- 1Issuing a DML or DDL statement inside a READ ONLY transaction
- 2Connecting to a standby (replica) server and attempting to write
- 3default_transaction_read_only = on in postgresql.conf and the application issues a write
How to reproduce
INSERT in a READ ONLY transaction.
BEGIN READ ONLY;
INSERT INTO orders (total) VALUES (100); -- write in READ ONLY txFix 1: Remove READ ONLY from the transaction if writes are needed
When the application should write and the READ ONLY was set unnecessarily.
BEGIN; -- or: BEGIN READ WRITE;
INSERT INTO orders (total) VALUES (100);
COMMIT;Why this works
Removing READ ONLY allows write operations in the transaction.
Fix 2: Route write traffic to the primary server
When connecting to a standby replica that is read-only.
Why this works
Use your connection routing logic (e.g., pgBouncer, HAProxy, libpq target_session_attrs=read-write) to direct write queries to the primary.
Sources
📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 25 — Invalid Transaction State
Confidence assessment
✅ HIGH confidence
Standard SQLSTATE. Stable across all versions.
See also
🔗 Related errors
📄 Reference pages