Parameter · Client Connection Defaults / Statement Behavior
transaction_read_only
Sets the current transaction's read-only status.
- Default:
off - Type: bool
- Applies: Session (any user)
In plain words
Shows whether the current transaction may write. You can make a running transaction read-only at any time, but you can only switch back to read-write before its first query. On a standby server it is always on.
For DBAs and operators
Initialized from default_transaction_read_only at each transaction start; SET transaction_read_only = on equals SET TRANSACTION READ ONLY. Writes then fail with ERROR: cannot execute INSERT in a read-only transaction
Switching from read-only to read-write after the first query is refused (transaction read-write mode must be set before any query), and on a hot standby it is refused entirely (cannot set transaction read-write mode during recovery). Like transaction_isolation, a plain SET outside BEGIN … COMMIT only affects that one statement, which is why SHOW transaction_read_only right after it returns off again.
Read-only transactions still allow writes to temporary tables, and are a prerequisite for DEFERRABLE.
How to change it
Any user can change it for their session with SET.
See it in context
Related parameters
default_transaction_read_only in_hot_standby transaction_deferrable