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.94.2) (envelope-from ) id 1uuJGc-006hYz-FD for pgsql-general@arkaria.postgresql.org; Thu, 04 Sep 2025 23:21:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uuJGa-0039ww-TI for pgsql-general@arkaria.postgresql.org; Thu, 04 Sep 2025 23:21:21 +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.94.2) (envelope-from ) id 1uuJGa-0039wn-IB for pgsql-general@lists.postgresql.org; Thu, 04 Sep 2025 23:21:20 +0000 Received: from mail-oa1-x2d.google.com ([2001:4860:4864:20::2d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uuJGY-000aCO-2g for pgsql-general@postgresql.org; Thu, 04 Sep 2025 23:21:19 +0000 Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-30cce872d9cso1530610fac.1 for ; Thu, 04 Sep 2025 16:21:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757028078; x=1757632878; darn=postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=leLt/ZTRgKKPvGHEqIRgkC49yvCwBKvbTouP0XanXlI=; b=HqxcFRR/jEsWaSgZN2gYBpmecwBtCa1VwvbuAFygRTic96OOJJsgZeWZiSFPXmRoyL 2chNmoKJ6JvEzazWl9sAYkMQJqG5N8QQcdGW0lj/tHalf6PdvB0Vf7p/VR/QQUexdGkA cnT97d0BpWVuDsJ2R0R19IFhvwlXR0PNgPWoyLfjXp+hvlk+FBiHYrXS17FBf7m8N0+/ elqpXilHs1Y6U46eQM0eIV35zf7LcW/jdtL90eMO6AZ044cPdG7JIhKa1nSkZ1W9FFAm 8IrUpWZC46xX02C9odaU2FH9r7zdWbHOOOY/39D2QbPIC8cWKLgngjInqyijKYlHlIIx +TXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757028078; x=1757632878; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=leLt/ZTRgKKPvGHEqIRgkC49yvCwBKvbTouP0XanXlI=; b=mmNdXEZk9/YkwKVmDSQTk4PNfMVKTvxZgR4cVFzo/Bn6KPFDVQ78fP72AfeU74BM1P fdrtrwmj+ahGlHbhXpZhm+XMB7CdVhXvvlC6dw+XvD+GX7HbUwvihDizvD103rO5ydYk ib+S3ehLQgSSrkMwNh1zPgiLCK4NlBeR8tJMygUKUPwbN9GKhSG99jpOC9ynAFbmC2XF exYML4BDQC3fh3MmabSI8dLSBfMwwSfGG0i2weOm89wt0bPHu4upV7vC5HggriR0lgH4 leYpsNSEzDp3KQABLOyy64HaTAWsJ1Yrt4olVA5l8s34qgjGm3DiffEmdmzAsPwYbI0x XcmA== X-Gm-Message-State: AOJu0YztQ7dZD1kPWCfpVqtI0rYOHGv1+ZlsAz/B6aB6JJi49aanf9+w BeHQDYvI4lB6EnXfcKSVpaMSa68ZyhCrmmn7uDIfugWTd32fLg1SJFRzRI4F7HxJe0P9XzSKejZ Ahfj/gwrx14JAF4ym4YvxtLWiMoQzk2InLwvr X-Gm-Gg: ASbGncsDaTTdLURPcchOyCFX+pwJy8P+70JqTN23yaSYgdHzRqV0SzYRotTKn0rCEu7 /k2md74wnS1IQC/n92LjHCdqgv32lgeYh669ppelyLFD+EuLB8p9Q2e6AvokmPMMb1qw8+qDJ26 AT4RbS1qOrFHR7KfQwigtrRFyTGVBYalF7SFDJNxxpl3V1q+mq/+dgG0obTzESMCRyyWNTNgCaw N7z8hxK X-Google-Smtp-Source: AGHT+IHkp0QG9POdo9oH0jva9SDK7l8UJp27/fKwNM44rJL5inKugFcYRLFkCXUUl63np0/WQQ7onbQxItmzLTrSbG0= X-Received: by 2002:a05:6870:bb15:b0:315:914b:8e3f with SMTP id 586e51a60fabf-31963475a25mr10173405fac.43.1757028077934; Thu, 04 Sep 2025 16:21:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ron Johnson Date: Thu, 4 Sep 2025 19:21:07 -0400 X-Gm-Features: Ac12FXxwW3MrRI6JL5cU677ZRRMHabtD8lxdgA15ayN1uWZgi9i3Ku420X4zqi0 Message-ID: Subject: Re: Debugging query performance in postgres To: pgsql-general Content-Type: multipart/alternative; boundary="000000000000721b63063e01fa3a" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000721b63063e01fa3a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Sep 4, 2025 at 12:58=E2=80=AFPM veem v wrote: > Hello, > We have a situation in which we had a dml query within a procedure that > was running fine but suddenly the plan flipped and it started running > longer. > That sounds like something that bit me once. Took a while to figure out, and was very puzzling. This list explained the problem and gave me the solution. If you run the same query multiple times in, after five executions, the PG query optimizer decides to use a generic plan. This disables that choice to use a generic plan: set plan_cache_mode =3D force_custom_plan; Setting that returned the procedures to their previously-rapid execution. --=20 Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --000000000000721b63063e01fa3a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Sep 4, 2025 at 12:58=E2=80=AFPM v= eem v <veema0000@gmail.com>= ; wrote:
Hello,
We have a = situation in which we had a dml query within a procedure that was running f= ine but suddenly the plan flipped and it started running longer.
=C2=A0
That sounds=C2=A0like something that bi= t me once.=C2=A0 Took a while to figure out, and was very puzzling.

This list explained the problem and gave me the solution.= =C2=A0 If you run the same query multiple times in, after five executions, = the PG query optimizer decides to use a generic plan.=C2=A0 This disables t= hat choice to use a generic plan:

set plan_cache_m= ode =3D force_custom_plan;

Setting that returned t= he procedures to their previously-rapid execution.

--
Death to <Redacted>, and butter sau= ce.
Don't boil me, I'm still alive.
<Redacted&g= t; lobster!
--000000000000721b63063e01fa3a--