Re: BUG #18882: Unexpected write skew at SERIALIZABLE with psycopg2.connect()
Thomas Munro <thomas.munro@gmail.com>
From: Thomas Munro <thomas.munro@gmail.com>
To: 2023103793@ruc.edu.cn, pgsql-bugs@lists.postgresql.org
Date: 2025-04-08T11:09:54Z
Lists: pgsql-bugs
On Tue, Apr 8, 2025 at 9:18 PM PG Bug reporting form
<noreply@postgresql.org> wrote:
> cur1.execute("SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL
> SERIALIZABLE;")
> cur1.execute("START TRANSACTION;")
I think it sends an implicit BEGIN, so you're already in a
transaction, and then START TRANSACTION (= BEGIN) is ignored, and SET
SESSION will affect the *next* transaction. I bet your log says
"WARNING: there is already a transaction in progress". I think there
is a psycopg2 way to request SERIALIZABLE, something like
conn1.set_isolation_level(extensions.ISOLATION_LEVEL_SERIALIZABLE), or
you could probably use SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
instead of the SESSION version.