PostgreSQL ERROR 25006: cannot execute INSERT/UPDATE in a read-only transaction

Application sent write queries to a read replica or failover left primary in recovery.

Runs locally in browser Free · No login Independently Verified 2026-11-25 v4.1.0
Identifier: PostgreSQL ERROR 25006 Platform: PostgreSQL
Common Root Causes:
  • Application sent write queries to a read replica or failover left primary in recovery.

Interactive Diagnostic Checklist

Verified Solutions:
  1. Route write traffic strictly to the primary endpoint (`target_session_attrs=read-write`).
Safe Diagnostic Command:
SELECT pg_is_in_recovery();
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.

Technical Explanation

Application sent write queries to a read replica or failover left primary in recovery. Recommended diagnostic: `SELECT pg_is_in_recovery();`. Remediation: Route write traffic strictly to the primary endpoint (`target_session_attrs=read-write`).

Worked Examples

  • Run `SELECT pg_is_in_recovery();` to verify root cause before applying the remediation.

Limitations & Assumptions

  • Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.

Source References & Verification

Resource ID: err-pg-cannot-execute-in-read-only · Independently verified: 2026-11-25

Related Resources