Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read the readonly status on psycopg2?

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?

like image 460
eltonplima Avatar asked Oct 31 '22 02:10

eltonplima


1 Answers

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.

like image 187
Uyghur Lives Matter Avatar answered Nov 15 '22 07:11

Uyghur Lives Matter