Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pqh29-00034D-3e for psycopg@arkaria.postgresql.org; Sun, 23 Apr 2023 21:14:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pqh26-00079Q-Hy for psycopg@arkaria.postgresql.org; Sun, 23 Apr 2023 21:14:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pqgb5-0004UJ-7t for psycopg@lists.postgresql.org; Sun, 23 Apr 2023 20:46:11 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1pqgb2-001VbN-37 for psycopg@postgresql.org; Sun, 23 Apr 2023 20:46:09 +0000 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1a68d61579bso29882275ad.1 for ; Sun, 23 Apr 2023 13:46:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682282767; x=1684874767; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=EAH0CT2ihj9bUPn2UnGljojKBzDwbrMuAgrg53vcnRM=; b=FZErQZGcB3h0AsZVJhzHD3h51h7n5zpPhab4+4hjCR6A0v8B0yeKYVWdyUC60JepQT 5lpHV7V4O6Oz583d3MOBcQ58lsPwYLrUnHfo/HzIgHin9lhyqHa59BHoKPIh9z1sct08 LgxbajjPOBe9Vz0pGDAZWwJLjGONrtKr7WNzdvH9z6KFCpC5b/DJLbHSamEWathvAOva 49fGqAII8OMpGkJ1srl5Qc4cGFEoq7Xj+nzDjuv6sutasakTpRvn8MN5hjG+RUW/M0sc 1fW5xq/2/CeqO49Q0l4k6JsojzG4USvFg3tsjpUvoxc6nRD49H/GqUFtsCkZN29UEALi WCIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682282767; x=1684874767; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=EAH0CT2ihj9bUPn2UnGljojKBzDwbrMuAgrg53vcnRM=; b=YrzkuzLgg5HFKfhjHDH2XMzxUPy+mDvdq6ola70Tyh7uDqA0hzhUqT7qjEBv8gp4rM OalobPOA6ULlTm7nutQP0Unqf7ST+F38FriS88xqk5kS/us8LfDRj5Nl/12D/d1adW2A pjhM329gB1t7HXbic30Sg81Dlbrr0UcX5183/Q7g0zJlaS2QdIfczHzZhTUU7Zln99mx XXwAWK2OAiJEEhIVrdxRBECFI7SMIvshtR/ij1KU5OKReeg+WJJEyqpM3+ZQI8J1DnPu JVK/8kIdHESmph4oPyJIFrbBGvyt3pWIi4fgyyObgXq0H9KduPScejfw73SK/yDr/woX 6tZw== X-Gm-Message-State: AAQBX9cpgCwmDwziTnqBVX6CfIuSDZjVg/GeIVKES3/L6bsAWyTQQzMV 45WElnVOtkOdBduz1uqq2VF9GkrBuSy55wIhAnzzF3bhILI= X-Google-Smtp-Source: AKy350bWfXdeuvcCcnwOq+OYl3CzAqZXT398jmgs9c8J0sSfjOrVdXlGJRs4siRI6RIROERRBwPvkpuIwbLkd50m9ns= X-Received: by 2002:a17:902:c941:b0:1a2:8940:6dae with SMTP id i1-20020a170902c94100b001a289406daemr12938729pla.34.1682282766781; Sun, 23 Apr 2023 13:46:06 -0700 (PDT) MIME-Version: 1.0 From: "Michael P. McDonnell" Date: Sun, 23 Apr 2023 15:45:56 -0500 Message-ID: Subject: Consecutive Inserts Freeze Execution of Psycopg3 To: psycopg@postgresql.org Content-Type: multipart/alternative; boundary="000000000000b9d34505fa06fa1e" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b9d34505fa06fa1e Content-Type: text/plain; charset="UTF-8" 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) 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. --000000000000b9d34505fa06fa1e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Python 3.10.6
psycopg library 3.1.8

Running cons= ecutive inserts sourced in files.
All inserts are of the same format:
INSERT INTO _____ (field1, field2, field3)
SELECT field1, field2, f= ield3 FROM ____, Join ___, join ___ etc...

The code I've wr= itten is this:

for qi in range(qlen):
=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 query =3D queries[qi]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 qparams =3D params[qi]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = with self.connection.cursor() as conn:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 conn.execute(query, qparams)

Wh= en 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 att= ack this would be awesome as I have re-written my code a dozen times and am= just slinging mud to see what sticks.
--000000000000b9d34505fa06fa1e--