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 1wD4yU-002a8q-0c for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Apr 2026 18:28:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wD4yT-001PG3-1H for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Apr 2026 18:28:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wD4yT-001PFv-0F for pgsql-hackers@lists.postgresql.org; Wed, 15 Apr 2026 18:28:29 +0000 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wD4yQ-00000001BpH-3xvF for pgsql-hackers@lists.postgresql.org; Wed, 15 Apr 2026 18:28:28 +0000 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-488a8ca4aadso84603615e9.3 for ; Wed, 15 Apr 2026 11:28:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1776277706; x=1776882506; darn=lists.postgresql.org; h=message-id:date:content-transfer-encoding:content-id:mime-version :comments:references:in-reply-to:subject:cc:to:from:from:to:cc :subject:date:message-id:reply-to; bh=Y0DSWH5eDXYoH2G8OWz+16+Quu1GMA+zv7uEY6WRpF8=; b=quG/vXh3T8ObWHMob21TCJSrAjlwJhMSrlHPrLrrv5gFPwLgI4sEpE453sLAHRzxDN BXZkRTowWpu8G9bZT5Ym1j3Dh/e+FOZ9L/omnb0eHZoHJc/qHKpg0JOFlrwYZ7ZXBx6h m1ADR4RUgIq3KNW1nVcE3FSsLOOTtFYm22vDIvCqDUhKCDkhehKCMqQOfUmoB/0irqWU eDULskisG8fPF9bbXL8unGXixs/gPVfyODhB0t62kp5gIOmcq0vYqLofcj7z5I69BVLM Rl207vv6xQtVyATXu//noYFG1IXVfO7gdGrJle/L0I11eETr/f84OFASv0jTvYUzL2h0 gaTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776277706; x=1776882506; h=message-id:date:content-transfer-encoding:content-id:mime-version :comments:references:in-reply-to:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Y0DSWH5eDXYoH2G8OWz+16+Quu1GMA+zv7uEY6WRpF8=; b=IqucaJwHsgOqOhOW/ji7eqT+Vv2Tq8jCJSVQCcwgxGP1oag1KGW/lbF6wobVj0Wx4h h2ZvSbW7Hh7SQA6YYTepaHvAFj4hJTS0/dyEP8q8d3baWbizmRVP0+TKiHMl70eBzEwp fkbynraTbmztkEeqCk6MWKxQqe+aXIFeHtRx5fg+IThbBQKr5Cz2q5O4Wtcxz5gdvil9 yfMxqTvOexasNC/GFm8UOgQTjEIZTjFmglBvf1Lx1ItYztREPwBvExAdFLnGi6hHkq3X GVxfkk2xm0sexVLOuraXCSG2W/Q8vN/VAVVODJjiHgk/lhuXH/PQmojyIhXmdXLi0c8x fTLg== X-Forwarded-Encrypted: i=1; AFNElJ88x4W1cldWSYTtm6S1v+lzsE+Y1qy+9nvKrmdRGXiM2CkY3q+iFotF/dwgayWM6RSIQt/gFCozIHrCzBW+@lists.postgresql.org X-Gm-Message-State: AOJu0Yz+hwZLQOHsnZ6yuzn65aYxiSkfRi20e4RBDpyWbGNXg2q3yl0C qaUAqniaVm1ro5B9QUP36Ubiam9+rvOmtKWBa9gFfDThUOXLcqjqCLysZsWzLYPoIKU= X-Gm-Gg: AeBDieuJ2IreFJgliLO1uS5TBZTISqWwHUSMI59apn8XejfEDTrkbUDG6nEMMtqRELH 93noljc6tMO51xsNZ8rOpKBrgCi246YcIaTHfoFZEIMZc9U+YdbumgWaPOJ/jSx7czqigvePSlC I97H3vEDJlrEAe41OHIUnAxJpqkp00z3fjRbnTWjzv2kc4jkiCv1bFkldUrEdoj1m9rlJcfl9zo U9k3nlQ5jNnxp/nwWvPhKCkJ1t7X7PUJiXG0M4Z7vBmgf6FDUx2zVJW/ForXJWfNU9tqoVVDXCQ 9MN8ek7U0zLW24z/4KN5t5CJ1IHGYiPwAUBaz/bytxijiA1AT3xgwm7tJqMnGCNGM+jkISFA9Oq DMnN+Dv1Nf8M1wREINUOIQzYPjIN3cLI8OI69hkD/hChfPNpfAfBATg1R0/pzjpgtw8Gww/rsGv bSrhdBU5IwpBuuq2GX5Bze7kNxXLYdYBud6xmP X-Received: by 2002:a05:600c:4709:b0:488:ae6c:42c0 with SMTP id 5b1f17b1804b1-488d67d2ab2mr275122065e9.7.1776277705943; Wed, 15 Apr 2026 11:28:25 -0700 (PDT) Received: from localhost (109-81-168-142.rct.o2.cz. [109.81.168.142]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488ede1e050sm254442095e9.5.2026.04.15.11.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2026 11:28:25 -0700 (PDT) From: Antonin Houska To: Andres Freund cc: Mihail Nikalayeu , Amit Kapila , Alvaro Herrera , Srinath Reddy Sadipiralla , Matthias van de Meent , Pg Hackers , Robert Treat Subject: Re: Adding REPACK [concurrently] In-reply-to: References: <9539.1775724194@localhost> <112208.1776173876@localhost> <25514.1776264611@localhost> Comments: In-reply-to Andres Freund message dated "Wed, 15 Apr 2026 10:59:51 -0400." X-Mailer: MH-E 8.6+git; nmh 1.8; GNU Emacs 28.3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <38384.1776277704.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Wed, 15 Apr 2026 20:28:24 +0200 Message-ID: <38385.1776277704@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund wrote: > On 2026-04-15 16:50:11 +0200, Antonin Houska wrote: > > I thought of a "hypothetical graph", which would include the to-be-gra= nted > > lock, but the major issue is that it will not work correctly without t= he > > locking the LMGR's LW locks we do in CheckDeadLock(): > > = > > for (i =3D 0; i < NUM_LOCK_PARTITIONS; i++) > > LWLockAcquire(LockHashPartitionLockByIndex(i), LW_EXCLUSIVE); > > = > > And obviously, doing this each time we want to insert a lock into the = queue > > would be bad for performance. > = > Hence my suggestion to do this as part of the deadlock check. Then we do= n't do > this unnecessary work outside of the case where we actually need it. > That does need to deal with the case of the deadlock check running first= in > the backend doing repack, but that's not that hard - I think it'd be goo= d > enough to set its deadlock timeout temporarily to a higher value. The ba= ckend > *should* still run the deadlock detector, because it could probably stil= l get > into a deadlock (e.g. due to a pg_class access or something). Yes, the question is when we should run that check. I thought that it shou= ld happen during each lock acquisition, and that made me worried about performance. AFAIU you suggest REPACK to do something like: 1. Acquire ShareUpdateExclusiveLock 2. Perform the "enhanced check" to see if a future request for AccessExclusiveLock can trigger a deadlock. 3. Do major part of the work (copy the table, build indexes, ...) 4. Request AccessExclusive lock. 5. Finish the work (process the remaining concurrent changes and swap the table files). This makes me concerned that if another session does BEGIN; TABLE t; between steps 2 and 4, and something like -- Get AccessExclusiveLock ALTER TABLE t ADD COLUMN j int; just after step 4, the two session will probably up in a deadlock anyway. = In other words, even if REPACK does the check early, it does not prevent othe= r sessions from getting in the way. Maybe I'm still missing something. -- = Antonin Houska Web: https://www.cybertec-postgresql.com