On psycopg2
, I can put the connection on read only mode with:
connection.set_session(readonly=True)
But how do I know if the connection is in read-only mode?
Starting in psycopg2 v2.7, you can use the connection.readonly attribute to determine whether the connection is in read-only mode (True
) or read/write mode (False
).
If you're running an earlier version, you can execute the query:
SHOW transaction_read_only;
Which will have the value 'on'
for read-only mode, or 'off'
for read/write mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With