One solution is to execute an instruction for each transaction:
engine = create_engine('postgresql+psycopg2://postgres:pass@127.0.0.1:5432/')
@event.listens_for(engine, 'begin')
def receive_begin(conn):
conn.execute('SET TRANSACTION READ ONLY')
But it is better to set the mode in the line BEGIN TRANSACTIONnot as a separate operator.
source
share