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 1wFsTR-005enE-04 for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Apr 2026 11:44:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wFsTQ-001cqR-0t for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Apr 2026 11:44:00 +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 1wFsTP-001cqJ-32 for pgsql-hackers@lists.postgresql.org; Thu, 23 Apr 2026 11:43:59 +0000 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wFsTN-00000002dtQ-2PcO for pgsql-hackers@lists.postgresql.org; Thu, 23 Apr 2026 11:43:59 +0000 Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-38e9653b580so69751841fa.2 for ; Thu, 23 Apr 2026 04:43:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776944636; cv=none; d=google.com; s=arc-20240605; b=Ea6XSSvZePxOC9UR6xcMAw39PjPUL+78qBlGHzlfvQeviLw+8XfjZnPLthL70Be4nv AI86jyrxuucBk4g7IrEhf5bANm/zecHt2LpIy5UGoIy0wUo1GD/nzVfiGyEVzkhbu0Bh p9WUkRYpCH1g2+I5Oc2EonIbqTirQdeOB5YeX1zV4uc2/0xrEkZPEyS2X2HZZpUFquDX 5wEor0uT7YdPmKWQT2QHc8owcxPstv+3ONjuF60OlD4KR3z8Iy9as4M/EAbUA4DSAssW /XG8EVB5YePqLWgwFMTtHhrBv7Z68478Bd2Gq4nTFKnEN/buYlW9270FBOVQmIch78h1 3gvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ZrnxP4mRL/rYrsYzXlRLodr26KX13aaE3GEkTMMpcVg=; fh=NBjRu8PWpiDF1z64U9oC2u0jp/mMK7DTkHxtcLq5aLM=; b=ZkZO9AOh+wJAU6PsxNXlDRy0BfN726fDC3+Ul8/4wOIGlRSfl36KcgM15XagpVWSiX 3xu/e8n3dL8zB9u10Hhe/8TtALpZGIeAQdTV4RThnEJE+MjC0NYCz9Ykep5dnd8AtANZ Q82T3eeLcnkuKTa0tzRPg2X6I7lhg+G315uWi2P4a5vZqAo/BKChT5+vLLGqzTIiVS2T 4Zilz5SBriHTjAxWz4ymOBnoiUmljF2HBZDgZjuzelH+bg+PpUED/vOTImyz356fkbQV LH58cdLxEsYLIvj9+e1ecWtD7rvm8t96fhry4HwdqrmLyM1A9pPHGs5VaWFdcbq6kWIH Ff2g==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776944636; x=1777549436; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZrnxP4mRL/rYrsYzXlRLodr26KX13aaE3GEkTMMpcVg=; b=Cd2VD034i+96RpNrypL8mgWr5ZKI8V245VIn6ziaR98e0/TGNs9Lg1yGdjWWc3ASLZ 8KebeMf8fB42ymVD9DBPBWAq5tizjLmQC++F4MY5FDELizID9IpfzSiHZ9yK/Jh//YvD ND5ktlMDeK8h7feTqce0/4oxXHwS9NemhtGBP79FDq16PZuK55qNRAnUMNy/xJg09rZ1 kwgwCX6ZG5rb5wrs1Fb7JQgEZNG3LGXhCZ42x0HxWryE71ljaCrdWicVT+fl5N51Nv12 MkPSu/1E/2rWGjIJO0H2yn261djqxecNDnpU8Voy1CLVdPVs7LO6MwlfchSvaIRwV0O7 /SiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776944636; x=1777549436; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ZrnxP4mRL/rYrsYzXlRLodr26KX13aaE3GEkTMMpcVg=; b=kwoT55lIimzt+pUgE6QnX5xprcLxXgtM6ChNOATMc6zLY0GNjRVw4eRqU0itb2zhNX W9b745Mn10A9I0I7SGgXhDI2JID26SwkSsJIriIOgRf7kjGnFSqFVnQweCAYu893UlKq y4bD2J+fdGenuglvnqAWHy7IvmjsvG/tigE/SdraJWuP8Elg7PpYBMRVUkpaKPjnDqYS kgpWppXCWriDSwp7y6DFysvRyRPTLCod2njPnojcggiftFtcNjwQk3Veo6SqRzBBp9dT Or+g90ggZYk5cH3ndKweImh5nZki/QHVttMapfDxPNkvAE/3C//BxAXLfsDBROwwNP6i g2mQ== X-Forwarded-Encrypted: i=1; AFNElJ/PLRdGOd94Yy3JcUMozpd7hZ7j4fW9q2TGMnDr4FvhLa5vycz7SPjDWJNr//LSiBLL3TdHFD72Mi2GoPYL@lists.postgresql.org X-Gm-Message-State: AOJu0Yzu5lHRUPp2vMgu6u9W4ldKaupIywT/CDQgziDxbUQ0xASgH25S A/184PkhsbdoU0rlUZWSMt3w53R8csDWgEQs4gj09SclVtw8t2/wkl2GrO+tmin9cTqvw3zep7u Gnm6cXCZuiqgu8prqy/nfq7+hqcyDjK8= X-Gm-Gg: AeBDieu75UtUNb/gqKVUd2TS9E2svSTPEN9yjErjdz994ywh85FR1xSmzZoAMn5UrX+ wjBQh3sAYFHav0MndsDFcvRKVNk/IhPcfEt7LsSXW+ZKVO/OHAouZ6Luw52wrfSn+yWIihO79r4 W89nGcxw0nSJy0zzvqfqF2Ip3cEz89MhtBADcnbVtIp4At0GE2iS1BG1S0xBkOrloHCB9mssdcL bB4RBvIwLm4BZYIGL27VI/g/aC4PQ4qVxJ+Ikin6vuVkYW/WdnV1T0q9kbbPDGb/nXRZOK/Mcg4 QSwjjg64PgCEtAyAPJT4IJpaFakKhoONpKuPJFdBr7I+Nb4g42sUYNMqPUGauxVyQi7mdJPd/i/ Vqa9Y X-Received: by 2002:a05:6512:6d2:b0:5a2:abc3:eaa8 with SMTP id 2adb3069b0e04-5a4172f60a8mr9369782e87.41.1776944635985; Thu, 23 Apr 2026 04:43:55 -0700 (PDT) MIME-Version: 1.0 References: <9539.1775724194@localhost> <112208.1776173876@localhost> <25514.1776264611@localhost> <38385.1776277704@localhost> <44458.1776540188@localhost> <68264.1776707092@localhost> In-Reply-To: <68264.1776707092@localhost> From: Mihail Nikalayeu Date: Thu, 23 Apr 2026 13:43:18 +0200 X-Gm-Features: AQROBzDX7U2JNie_wESqJAZgMxLiBn7G3_6OvcovXntZMmUjYItjLF0xNeQFTtw Message-ID: Subject: Re: Adding REPACK [concurrently] To: Antonin Houska Cc: Andres Freund , Amit Kapila , Alvaro Herrera , Srinath Reddy Sadipiralla , Matthias van de Meent , Pg Hackers , Robert Treat Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello! On Mon, Apr 20, 2026 at 7:44=E2=80=AFPM Antonin Houska wro= te: > When another process tries to get the lock after that, it checks this fie= ld, > and if it's set, it checks for deadlocks even if deadlock timeout hasn't > expired yet. If the process is already in the lock's queue and sleeping, = the > lock upgrading process wakes it up so it checks the flag immediately. In any way there is no sense in waking up other backends just to force them to cancel themselves. Better to go in the [0] way - and just cancel another backend if we are repack and found cycle in the deadlock detector. We currently have all required infrastructure, even as the comment described the possibility [1]: > * Get this process out of wait state. (Note: we could do this mor= e > * efficiently by relying on lockAwaited, but use this coding to > * preserve the flexibility to kill some other transaction than th= e > * one detecting the deadlock.) At the same time version [2] (with FutureWaitLock, explained in more detail in [3]) is correct and cancels other backends without pointless waiting, but it feels too complicated due to the complexity of supporting the FastLock path. Also, here's one simple idea inspired by your version. What about adding a new field "do not try to upgrade that lock" to the LOCK structure? If some backends try to (it has some lockmode and tries to upgrade it) and it does not has flag 'deadlock_protected' from [0] - just fail fast with "future deadlock detected". That way [0] ensures correctness and "do not try to upgrade that lock" just optimization to fail quickly for the most common scenarios. Some 2+ backend loops might still wait a long time to be cancelled (which is solved by [2], but complicated) - but I think this is a super rare case we can ignore (because repack is still protected from deadlock). Mikhail. [0]: https://www.postgresql.org/message-id/flat/CADzfLwURKVNQ%2B%2BDpi7bjoG= fj-8pchDQEVex3eWBx0NCYn6TbDQ%40mail.gmail.com#bceb18354aa20c130a94b1deedd76= fb7. [1]: https://github.com/postgres/postgres/blob/master/src/backend/storage/l= mgr/proc.c#L1870-L1873 [2]: https://www.postgresql.org/message-id/flat/CADzfLwUSnGnkfLwCWHQ%3DVVuA= Y1YTo%2B0Lr7pb%2BOPWUZbcYKSRUw%40mail.gmail.com#e7ba203b7402de332dfb58ce532= 9a73a [3]: https://www.postgresql.org/message-id/flat/CADzfLwVf-3mjMwSTOcj9djNzGd= -UjBOYbFjxgXRhtKuH_4rajA%40mail.gmail.com#b69f9c1d1d3d1cbf7f6d66be790894c4