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 1x3v5s-006l7l-05 for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Sep 2026 12:38:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x3v5r-006t3f-06 for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Sep 2026 12:38:31 +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 1x3v5q-006t3W-25 for pgsql-hackers@lists.postgresql.org; Tue, 08 Sep 2026 12:38:30 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x3v5o-00000004ay0-2z7v for pgsql-hackers@postgresql.org; Tue, 08 Sep 2026 12:38:29 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-499b2981a7bso49770345e9.3 for ; Tue, 08 Sep 2026 05:38:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1788871107; x=1789475907; darn=postgresql.org; h=message-id:date:content-transfer-encoding:content-id:content-type :mime-version:comments:references:in-reply-to:subject:cc:to:from :from:to:cc:subject:date:message-id:reply-to:content-type; bh=oVl7Dyub342qZzHXuheUEOQnNCTuuAUOMbtXYSskk+Q=; b=A4gsgWOGbLYKHDg14tf2hAzrxqjncUkC4rb8pf9pjMAlIZ8wUbIZEDcrJuPxM4pUUW l9SnB2IgbKanHgcfBbgwF/oL+KmPezKYkNrvNHpiYSzRDmbGtxfa0h7IxWiXvzn10QHN 3b8GwJpZMwVZYw1j51yRJtYDp2AeiYgqcHr9+s1F1hJgnZH0iZ12QdOjd5uh+uIsekHQ SijeCUhxknHEflsSxeAxXofeO5vqRNBbuJQWQKCp2/AZCA690HB2YXfn08yhHwFAgIWg rn/WjicMcswzDT+qx3BQPeiurV26jGhtEyGaXaCETeRs3b4TdYYvR3nfhrPmEBUlk8q1 P3Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788871107; x=1789475907; h=message-id:date:content-transfer-encoding:content-id:content-type :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:content-type; bh=oVl7Dyub342qZzHXuheUEOQnNCTuuAUOMbtXYSskk+Q=; b=GljH/xiPx6m5znIVA3wZnz8ymTHFMuO2g6zyhEZdHjM/8/JEad6aliOuCyYh7Sbke9 f7gkGdUnkCtIrlg+Q/wKazX3vEfoizjxrTd02aQSI5MK8+PT9pOOTQij6P663AKIDOCb Nx60kWFFzlG+WO3G6R1+nBTe5fkFBS97dpmnpmk2XU2ccRu1vRSeQFctrDDsIpVCqwuL et3Hss0jaUGK4ODcu2Fq33bYeiVkTMC63iW7LnEOzjQlFOjSrlASwaeAqoF/I9GpWC1X eD2jQzA77fu9qLcA1sqlFGBpuxKQ2U9a7gwO+gsjRK3+8eQZmeCZT+2T3WI5GJuJA9J9 nVUg== X-Forwarded-Encrypted: i=1; AKwUvBzWNFQNkm1FwFDoppylDVw0IZga5Gt0dLxDwHGUS6FM5lhTTgrmI82WSjsqTqdms27f+AEO3Hp+W3uxLMy8@postgresql.org X-Gm-Message-State: AFuF++mL86sok5pHiN7XhXYfxUAH4KbJdIDfuKKQbEcDNfTL4cBm2Myw 8Yya9AJypXW4Vr3MW7Pz5DxxU0xnvVJvvd44X3uUO0IY1WVIzkCda0IYiTI9ggcsH/Y= X-Gm-Gg: AYBFou10AxcwHLdmVGc4GHHxHGr68B3EePMWJcMJu7tkhtmPX1ZtPePRZ+dPPOnKc5m QrmwGgDpWgOAuX18+l5HqUhyWwUIyxsZU7W0LQC/4cdq9qi2vuBsURZDRsbfDZD5cuh92OKRBbq VJp81idEwQ199vKONukgTUyjvgWwFcVSrlJVZLDf01ks0vsZeQJePF38g8ci7S51oa/hcjAaFtG FBLron5/E1We4PnLEIw3BZT56HZYiWhDP1o3LJmURoGI2AEnPvgYkxh0hpVys2cqO11JXRRdAna j28hVKJ+9EvRwFpR8TyAi7XQ3af+9ZyAhPxOxZj+w5zxw1usY4upARPGzn+yXhd0cmXVK8oZYq8 XXhodDrcBgv/zsusR4Y0SpiY5AqxxXY7OASl1fHtqV3bpDGWHpOX0tjl3ZLFg/rcKBnt6jf2Qay GiLjj1EG5AKA2WU05/gsVJRNeN8WfgopiINceWQBdYhdkiw/gsUUmLJW9Sf0RYFfCubSD1/pjGk A== X-Received: by 2002:a05:600c:4712:b0:499:7a15:fcec with SMTP id 5b1f17b1804b1-49cf8248cd3mr473037785e9.13.1788871106686; Tue, 08 Sep 2026 05:38:26 -0700 (PDT) Received: from localhost (109-81-170-190.rct.o2.cz. [109.81.170.190]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49cf7736132sm384902005e9.12.2026.09.08.05.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2026 05:38:26 -0700 (PDT) From: Antonin Houska To: Alvaro Herrera cc: Osama Abdul Qader , Fujii Masao , Nathan Bossart , pgsql-hackers@postgresql.org Subject: Re: REPACK (ANALYZE) within transaction block segfaults In-reply-to: References: Comments: In-reply-to Alvaro Herrera message dated "Tue, 08 Sep 2026 12:27:19 +0200." 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: <43710.1788871105.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Tue, 08 Sep 2026 14:38:25 +0200 Message-ID: <43711.1788871105@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alvaro Herrera wrote: > On 2026-Sep-05, Osama Abdul Qader wrote: > = > > I understand the distinction now. Allowing REPACK (ANALYZE) in a > > transaction block in the future would not necessarily mean that it is = safe > > to execute it from a function, procedure, or DO block, since ANALYZE m= ay > > start a new transaction in process_single_relation() while an SPI sess= ion > > is active. > = > Well, I think the main point of running REPACK (ANALYZE) inside a > transaction is to allow it to run in a procedure. Consider something > like > = > do $$ > declare r record; > begin > for r in > select relname from pg_class where relkind =3D 'r' and > relnamespace =3D (select oid from pg_namespace w= here nspname =3D 'public') > loop > execute 'repack (verbose) ' || r.relname; > commit; > end loop; > end > $$; > = > This works fine today and with the patch, both with REPACK and with > CLUSTER (good); but not with VACUUM FULL (sad, but we no longer care: > just use repack.) > = > This is useful because it allows server-controlled execution of > repacking each table in its own transaction. But as soon as you add the > ANALYZE option, which would be valuable, this recipe no longer works. > = > My point is that just the ability to run REPACK (ANALYZE) in a > transaction block without allowing it in a function would be, I think, > rather pointless -- who could possibly be interested in repacking > multiple tables in the same transaction? There's just no benefit. > = > OTOH I think it may even be useful to implement in-procedure execution > for CONCURRENTLY, but that's likely a more challenging patch than > ANALYZE. An alternative approach: as there are various commands that start their ow= n transactions, it could help if we taught the EXECUTE command - when execut= ed from pl/pgsql procedure or anonymous block (DO) - to accept this behavior. That would probably require a new option for EXECUTE to declare that a new transaction is either started by the statement, or (if the statement actua= lly does not do it) by EXECUTE itself. (Then we might want to enhance the corresponding commands / functions in o= ther languages, however it seems most useful in pl/pgsql.) -- = Antonin Houska Web: https://www.cybertec-postgresql.com