scribase
SQLSTATE 25006read_only_sql_transactionHTTP 405

Postgres error 25006: read only sql transaction

cannot execute INSERT in a read-only transaction

A write was sent to a connection or transaction that only allows reads.

Common causes

  • Connecting to a read replica or a standby.
  • A transaction started with SET TRANSACTION READ ONLY, or default_transaction_read_only is on for the role or database.
  • A database switched to read-only after hitting a storage limit.

How to fix it

  • Send writes to the primary connection string.
  • Check show default_transaction_read_only; and the role settings.
  • Free or add space if the database was put in read-only mode for size.

Through a REST API

PostgREST, the REST layer behind supabase-js and Scribase, answers HTTP 405 for this error and returns the SQLSTATE in the code field of the JSON error body. PostgREST answers 405 when a write reaches a read-only transaction, for example a POST to a function marked STABLE.

Questions

What does Postgres error 25006 mean?

25006 is read_only_sql_transaction in class 25 (Invalid Transaction State). A write was sent to a connection or transaction that only allows reads.

How do I fix 25006?

Send writes to the primary connection string. Check show default_transaction_read_only; and the role settings. Free or add space if the database was put in read-only mode for size.

What HTTP status does a REST API return for 25006?

PostgREST, the REST layer behind supabase-js, answers 405.

Other class 25 errors

  • 25P02 current transaction is aborted, commands ignored until end of transaction block