Re: Consecutive Inserts Freeze Execution of Psycopg3

From: "Michael P(dot) McDonnell" <bzaks1424(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: Consecutive Inserts Freeze Execution of Psycopg3
Date: 2023-04-23 21:55:34
Message-ID: CAHmCLHrdxjeuRDxS7w2P-9LZ_C5wxsoVyLrVJwRRwrMOXVu4dQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

That helped a ton, I don't understand why I've had to rewrite the crap out
of all of this to get it to work (dropping SqlAlchemy, upgrading from
psycopg2 to psycopg, etc...) but it's working now and I can work around it.
Thank you.

On Sun, Apr 23, 2023 at 4:25 PM Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
wrote:

> On 4/23/23 13:45, Michael P. McDonnell wrote:
> > Python 3.10.6
> > psycopg library 3.1.8
> >
> > Running consecutive inserts sourced in files.
> > All inserts are of the same format:
> >
> > INSERT INTO _____ (field1, field2, field3)
> > SELECT field1, field2, field3 FROM ____, Join ___, join ___ etc...
> >
> > The code I've written is this:
> >
> > for qi in range(qlen):
> > query = queries[qi]
> > qparams = params[qi]
> > with self.connection.cursor() as conn:
> > conn.execute(query, qparams)
>
> In above you are running the context manager(with) over the cursor not
> the connection. This will not automatically commit the transaction. You
> will need to either explicitly do connection.commit() or use the with
> over the connection per:
>
> https://www.psycopg.org/psycopg3/docs/basic/transactions.html
>
> >
> > When I run the queries in dbeaver - the first query takes 120s (it's
> > 1.9M rows), the second query takes 2s (7000 rows).
> > When I run the queries in python - it freezes on the second query.
> >
> > Any guidance on how to attack this would be awesome as I have re-written
> > my code a dozen times and am just slinging mud to see what sticks.
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com
>
>

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Adrian Klaver 2023-04-24 00:15:32 Re: Consecutive Inserts Freeze Execution of Psycopg3
Previous Message Adrian Klaver 2023-04-23 21:25:25 Re: Consecutive Inserts Freeze Execution of Psycopg3