Re: BUG #18882: Unexpected write skew at SERIALIZABLE with psycopg2.connect()

From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: 2023103793(at)ruc(dot)edu(dot)cn, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18882: Unexpected write skew at SERIALIZABLE with psycopg2.connect()
Date: 2025-04-08 11:09:54
Message-ID: CA+hUKGKp7Cj3q=fPCKKS9JSW-KiGbVNpBcRo0-nd+z_5cedoZA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Apr 8, 2025 at 9:18 PM PG Bug reporting form
<noreply(at)postgresql(dot)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.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2025-04-08 12:00:14 BUG #18883: Epoch issue
Previous Message PG Bug reporting form 2025-04-08 07:10:11 BUG #18882: Unexpected write skew at SERIALIZABLE with psycopg2.connect()