Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vzIT7-000sQS-2b for pgsql-general@arkaria.postgresql.org; Sun, 08 Mar 2026 18:03:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vzIT6-00BH4m-0s for pgsql-general@arkaria.postgresql.org; Sun, 08 Mar 2026 18:03:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vzIT5-00BH4X-37 for pgsql-general@lists.postgresql.org; Sun, 08 Mar 2026 18:03:08 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vzIT4-00000001b30-1Leb for pgsql-general@lists.postgresql.org; Sun, 08 Mar 2026 18:03:08 +0000 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-439af00d33cso7923939f8f.1 for ; Sun, 08 Mar 2026 11:03:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1772992985; x=1773597785; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=vnMMqpybMjcSlbQX0E+THG2SvqOKr4lskDwnwhz6WcM=; b=Y/7nBx3z39L3yZY00hwpjM6fzBFBZL8aMmFbNdPmigV0xx66cW32bWqqUGDoWTZFXz Swv9WGqEkJ8wZh5BuTh+MC41e516UelnN8GwGY7ngulHexDQPu52PaqeXHkdRuU9RUKl GQCNW0KnBRo/3ZtX5ZvdcwNdPEk+8OuvMn/hpINDOw6zkHiyPQbOgoNX34jE6xf2EuMC PGCsgxWhQPM1PuXR6eSWneExN3eiPbe3Zcgm7so3COELKoUWuG9+KPWrPijsBTJMdp7l 03TQfLnkrD/hfQ4ldDPfIsJ+b29EYEVNqCgJZZhO4GrG+IXcfyl4XDUD9CVwZHrnI9BB tKiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772992985; x=1773597785; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vnMMqpybMjcSlbQX0E+THG2SvqOKr4lskDwnwhz6WcM=; b=TYLqYaqXcgqM/zCeFJQWLDM+zAQNKlhTjS5nEdXtUHeLMUBmJmCzj5wmF6eB31WqIp NXKAsZ1ZkHVnQxiXM23ISBwdQBoWPJkP+V1OU7mxgjAxptD9XndMeH1daqS5uVB08sh8 GV5PRUQLNf+D7m1n+xJhoDso+tzURnRu9a3WQoxunVrHoV2HMG6w4djMwv7IcXjKG4hN g00DzgtLQr0piZGRJfKofTB42Z8xmqU8gmirU2Rz0nRaZ6998/Tpmu8RV414/wahbAr3 YnbF4n5/r3JNoQ5iOn+p5v5GWQ0RU132tjmZ2r8L0W7/g0CQpmoBaxoJ9wtJwsstnjUG EQoA== X-Forwarded-Encrypted: i=1; AJvYcCUISDdx+WLCTo+gJuNilsSfOsuk95aiU34tZCx7lYOmD3mzS30fgqSMmX2QNM2kYEPtlQOAgLViwc5coUvB@lists.postgresql.org X-Gm-Message-State: AOJu0YzCe20h16RXpLcereOas4JfAGAVBcLJiMTSgdevI7DKKt9M5XqD IJTVRpQ+CTjUAHQsB3t59Jjx4nL8o2A4xtW2zeCJ8IQ80iBX1KlGTHq/DG34qZsAyC+s26BFuv+ yM2F7 X-Gm-Gg: ATEYQzyT/l5sX4fwbWz7gk8H2Pl/RtSoDuUMryaEcgjtFIFH8GrVovTNBFTvEE/vipB N3QvCWnk0EWbX1EgCtzXvUxuk44l+aLVDc5FohmhirDCF2dJ6g/z6zqwaUMqqOCimWOPX1zxOnz q0WFPiZLFaKyE2uWBg3zB1OoacpSvjPJ1R7qlwHeWAewECcbHTG9Z0iwDBYKbjyWR1E89xwkdB2 5HrJDHnUn9LwUhkkm4XvmMPXu5/OBlM8X7wx1y+5SDYjmm7J1ztFVak2rxdkmbPIq40rC3VWzxE BnpnKXb2L/NqEapMAfrX2rY611gjs1lP+FNHtj5FY57G9+LE0Jud2cUU8HYem93k0BkaEma4CK/ XKwe5de0F4eT7KLlQDKTeAmeWmKLwHEJOQzhcjZoH64GtLo6gYg9uwHDubRkGrKi7CROmHloT8d 6fCCB4CDnHhdfiOec2eaMMMvzQ1JHNw+X8GDxKdpafYMWDcyOj+ys= X-Received: by 2002:a05:6000:2885:b0:439:b65a:fd35 with SMTP id ffacd0b85a97d-439da89dc67mr15605865f8f.59.1772992985503; Sun, 08 Mar 2026 11:03:05 -0700 (PDT) Received: from laurenz.albe-K4N0CV00F97414D ([193.32.29.227]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-439dae2ba06sm20597050f8f.24.2026.03.08.11.03.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Mar 2026 11:03:05 -0700 (PDT) Message-ID: <55c5a250a9026af4132d90954c081b11d5752522.camel@cybertec.at> Subject: Re: Unexpected deadlock across two separate rows, using Postgres 17 and Django's select_for_update() From: Laurenz Albe To: felix.quintgz@yahoo.com, pgsql-general@lists.postgresql.org Date: Sun, 08 Mar 2026 19:03:04 +0100 In-Reply-To: <1164079167.6346688.1772982934392@mail.yahoo.com> References: <1164079167.6346688.1772982934392@mail.yahoo.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.3 (3.58.3-1.fc43) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, 2026-03-08 at 15:15 +0000, felix.quintgz@yahoo.com wrote: > This is pure speculation. > It's possible that using SELECT FOR UPDATE also locks the rows in the par= ent tables referenced in the field list. > I believe this happened in older versions of PostgreSQL. I thought about that too, but since both updates affect the same table, the foreign key would have to reference the table itself. You are right that a SELECT ... FOR UPDATE will place a lock on any referenced row (and FOR UPDATE will probably use a lock that is too strong!), but those locks would still be SHARE locks, which can coexist. Yours, Laurenz Albe