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 1w8ULV-000aFO-1R for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Apr 2026 02:33:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w8ULU-009SXu-0S for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Apr 2026 02:33:16 +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 1w8ULT-009SXm-2Z for pgsql-hackers@lists.postgresql.org; Fri, 03 Apr 2026 02:33:16 +0000 Received: from mail-qv1-xf34.google.com ([2607:f8b0:4864:20::f34]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w8ULR-00000000HlD-3rE0 for pgsql-hackers@lists.postgresql.org; Fri, 03 Apr 2026 02:33:15 +0000 Received: by mail-qv1-xf34.google.com with SMTP id 6a1803df08f44-8a3342d301aso19117686d6.2 for ; Thu, 02 Apr 2026 19:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775183593; cv=none; d=google.com; s=arc-20240605; b=GQhGinAI3sevs+3QCile7Q0tmWn/uNoKgg8nPeF6eQDIFjw82ZHjh01uwgk31a6M2Z BsX4+K+qePnYFjoYOAgYpaNO55HinXUSNG6P26jZpVRErBvHDBuM09yw3TDU9dA7ZrU6 QLXlbseVR1EmuyVUftvKJvwvDca+vmSPnUwvZZGm6imfehWAJ1htEKi7I5HxfaQM8t6e dl/6lUXq4O34A2pYAFkoOQp8f7G+ZmLGcDATAla8/HyMOrQDqsGcGyugoPFwUl0hXnhL ogpPiGxA5CQ8hzkWom4zKUkrzIp0yo9xn8W//j9D6I3ZaBeo9cnJ6nhQ5/aLWbi594ZL sBvA== 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=qnxniclr8jvyKiZ3Q+uHcL3qcxkpS/NPMwax4YSiL1k=; fh=Ge0fDvHILHwh1RJGoDE6IbRCgt22LnHbo6+QHIeNRws=; b=JM0BEoqF+fxDnVieYTnizG7aiUsFjtVf51XLdSOOMhbxN3HSMCpodsh9mefi+yFDIb qNMwXJSyt1wwQ9V/tZKQOst8h1cNwCR7lKcZaRXD9cWXDe6FnLt2xLbFSOY+fHg/1rsx 0ovGS4PVJYhOs86IXfMsAhTI+LMdy30ecHxKPbQMj/pYlilRbJK2Y6hIqIWNijb4MER8 3V6EyEzmPFZL38s5KqSLJs+yPtwtwi0Pro956BOw3bmAakIXwFAX+WBx+/rjMsyIvb2C EuDGvkiz1Lj/RKoB3Pw7utaIAKcMAuAlKUGGIBcJ1Y31zt3n5OrKFkd/e/zOCuu7omzg LgMw==; 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=fittl.com; s=google; t=1775183593; x=1775788393; 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=qnxniclr8jvyKiZ3Q+uHcL3qcxkpS/NPMwax4YSiL1k=; b=M1JH2mKs6QZ6j/jHW4Lnit/dX3DMdU+7zxdD7b+UOM9ROj+bAgS4794IC1a1dF00ms qgvuk5cm0lNxxEuj6nXkzCirVtiLPaDwfllp6asHoE0PWRt8PQJqJpWR2Pj5olCEbBEO cjplO+ETmBrVAHGvm1SrSPP1bjjoQ7iKKbFW4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775183593; x=1775788393; 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=qnxniclr8jvyKiZ3Q+uHcL3qcxkpS/NPMwax4YSiL1k=; b=Jic01PhvPMo+i+3CxbE1MvmzmEcKNtF69+aLN1FMZOjUOEPXCYed37embfPmsxIycV GUdHKcJ2Q7N7ROzsxRjetmC79EZM/5QL9wA+fT5ga7vqT9bMxcpA37oGydGaxQWN/2Cj 1RArL7SOWxJSNTf2ww48s/+eXLPEBEIDRnqUfuERuKr1tP0exGHSHGwK6DFWn+1fyNuv EM4EfyzIexplMUzFirSBknOVLeK/Tc8guLQBhKwp1B1DMMojtg2SisNBksjHW+lF0ewY dbntIeAwzKkqbIPpbLvYHpbPQfB/KsqDYIqGa2QBPhuYY+TcFxt01416m5VpDoG9lgCb +yNQ== X-Forwarded-Encrypted: i=1; AJvYcCX50glfG5VkjilE89EHYSFID9Ee0WlcgqgyWAKwxDfVkgcF5EoIQmNYUawOYcxmpbtftk4F2WjmV3rYQlux@lists.postgresql.org X-Gm-Message-State: AOJu0YzwASJOjYBFnub2LMxxG01aeYU3owcwwmSneSqqKKr7CxMFm4sU qQS+Z4x77s2lsfhXT+/sT1WeD68rIJ4pTNM1xWfYTCK6dBPxSifFAhvnCy1cewmewnJ/iwMeqzq DMaUDx987i9AgXJxDYJr1ldpnwgZrK+/cd6ziCdz7 X-Gm-Gg: AeBDieuVm57bXPJv3hoTik/xiBYh4cC8TOAzCuJojDefDpZnpteo4I5iA45S+rEWMTs BQJwnhydqahLnRld9cH9qucwpE1X+FDKOZxFezsnqqHyKpdzRiHvD6WiHVvRC0ZdwPcpKiZR0/c DB/8x0izmN3QzIOZY98oLlFfgvnQ4DnwNdcEYRKApuAaSq4h6RaXD5hjhpvGi1hodmfmA5eFQiW o34yLExI1oAKh1UqvHwoypEz3bdxxrHUdBFKcMHXRAWKllrN861/+f/a7rdc3YKoRWOlgTISucQ 1Rq01YMQzIAABgYP0r5kduwSSYjU1kJ1fS36MkJKzSza7xH7CoxMPiWONIhOPMBnDi8upy2m X-Received: by 2002:a05:6214:3281:b0:8a5:cdf2:48aa with SMTP id 6a1803df08f44-8a704abbe36mr25148596d6.47.1775183592779; Thu, 02 Apr 2026 19:33:12 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Lukas Fittl Date: Thu, 2 Apr 2026 19:32:36 -0700 X-Gm-Features: AQROBzAUgVmTuuFpiGQM5F7OsNr3EG904y-JJr7r_bBHle0IRq9AviQ_WGTOGNE Message-ID: Subject: Re: Add custom EXPLAIN options support to auto_explain To: Robert Haas Cc: Matheus Alcantara , pgsql-hackers@lists.postgresql.org, Tom Lane 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 On Tue, Mar 31, 2026 at 9:19=E2=80=AFAM Robert Haas = wrote: > > On Mon, Mar 30, 2026 at 5:49=E2=80=AFPM Robert Haas wrote: > > I'm currently poking at some ideas for fixing this... more soon. > > Here are some patches. I got started poking at this in earnest > because, on the pg_plan_advice thread, Lukas was saying that instead > of adopting pg_collect_advice, we should just add an option to send > advice strings for each executed query to the server log. I went to > implement that and then felt like it should really be part of > auto_explain rather than its own thing, which took me down a bit of a > rathole. But I eventually found my way back out of it, so here's a > patch set implementing auto_explain.log_extension_options. Thanks for the effort, I think this is a good approach to solve the immediate need for plan advice (to have a facility to capture the advice strings for a set of queries), whilst avoiding introducing a new module, or completely new log settings. FWIW, initially I wasn't sure about this approach, since I typically see auto_explain focused on capturing outliers, so it wouldn't necessarily help you to capture the "good plan" (since that won't be an outlier). But since a superuser can modify auto_explain on a per-session basis this is similar to having a dedicated log setting, and it seems reasonable to not just have the advice string but also the plan that it is associated with. Its also useful that auto_explain has a sample rate option, so one could sample 1% of all queries for a few minutes to get a sense for the workload and the associated plan advice strings. And, just as a data point on why this is more generally useful besides pg_plan_advice and pg_overexplain: I've been thinking of utilizing the custom EXPLAIN option mechanism to log Plan ID values in EXPLAIN for an extension I maintain (pg_stat_plans), and this would allow that extension to also log the Plan IDs in auto_explain output, which would be very useful. > Anyway, if you apply all these patches it does solve the problem that > pg_collect_advice was targeting, modulo the need for some log parsing. > You can do this: > > pg_plan_advice.always_store_advice_details =3D on > auto_explain.log_min_duration =3D 0 > auto_explain.log_extension_options =3D 'plan_advice' > > And then you get log output like this: > > 2026-03-31 12:16:18.784 EDT [75224] LOG: duration: 0.013 ms plan: > Query Text: select 1; > Result (cost=3D0.00..0.01 rows=3D1 width=3D4) > Generated Plan Advice: > NO_GATHER("*RESULT*") Looks good, that makes sense to me in terms of user experience to target for this release. I have only skimmed the code before running out of energy for today, but will do a closer code review tomorrow. Thanks, Lukas --=20 Lukas Fittl