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 1tk1wU-00GQoE-NO for pgsql-general@arkaria.postgresql.org; Mon, 17 Feb 2025 14:17:50 +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 1tk1wS-00GGbp-JM for pgsql-general@arkaria.postgresql.org; Mon, 17 Feb 2025 14:17:48 +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.94.2) (envelope-from ) id 1tk1wS-00GGbh-6U for pgsql-general@lists.postgresql.org; Mon, 17 Feb 2025 14:17:48 +0000 Received: from mail-oa1-x29.google.com ([2001:4860:4864:20::29]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tk1wP-001LcU-2W for pgsql-general@postgresql.org; Mon, 17 Feb 2025 14:17:47 +0000 Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-2bc79a81e6bso919156fac.0 for ; Mon, 17 Feb 2025 06:17:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739801864; x=1740406664; 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=tyaz7+AdGfgV/i1eFZK9lXRk8pg8sxtN1B6dKZPY+vI=; b=Z6wpueub+XxByzYkgANfhXzrvkvelzMkbZMihSuekOqjKr3VyFsnRIAwprP/EfzCRL n9H6ddX2zQ5pBSuLLG2OnDEVx7559ulA8Jr2LQdSYj3pBvcBFxV0+/TJ0O3VMwKs0K7F goeWNis+kfiidgb8k6iNJmAalZ3wqcPJvUXl8vp8reMd/URgn4yJrXj3OPgVeTdqWzO6 vBgxoI8v7if39XZflApqQZruJ0Kp+kC5+VtsFow1GhATV+Qy8FuFMRZQ9sKrmf1SA7Ow nrKChSt/UtDiHLtcuGfQDgVrh83UbmPTq2VY15uxV5kWUDol83tU+c0hUSfItpfHcpIG qWKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739801864; x=1740406664; 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=tyaz7+AdGfgV/i1eFZK9lXRk8pg8sxtN1B6dKZPY+vI=; b=jJUR8qzfCtidQ8pdWbAFySor8Et7oGCPTKUCac+jDZshqlQ4m/B5K0warJrGRmXCFy FwufZjXAH4OnSaSm3zglo/gr+xB4i1KgHn2KHOM4T3d+Vj18Lxnlc+LgIgsOBRk0PJUI wRRbTAC+50V+W8Yz9vBZlG0/NhDCHogp+YymZRawah3AWwVPtxvkgBOZC/c9ZF7Wturn Rg6xip3nBon+ZQWD2bAFDg+z0vy8/GaAu4z4cktiOgMItAphJzHZU0kVMMba3809Hft+ rQrdF9F7DmgXrZ/JGxbKV8VRfzo5LjgOujcynzNyxrVd+hHEHi00ZLhMi/yMzjC+SEnc pMZw== X-Gm-Message-State: AOJu0YzeIztMMxKoxthKcjClnReihOgiF42iAhBz8SPuY9KuBmixjZtU B4AKKOayiFHIOaDhYjO2qTo3h//rnjrjTQsgAHB+NDZP6nGTGYrQJk/T9weLG7OIasu/I1PfL+K cjWwwfd5sBH7cfTvFKgQ/JF6b1I6XxC3E X-Gm-Gg: ASbGncsvQgNlW8840bZgZS8hwEBCWELOJcqHVqTqshBtWLf/jcpcagILj5c0MrWKDw2 /zxb4AwFnNsG1rok4qihdErlEAk9c7gcoxBFq0pHB+bbYBmv1G/j1OzRkGScUZ0RMOLKYK6YpwA == X-Google-Smtp-Source: AGHT+IHBrNJ+wRnxFkWVIcvK2LdUoVGAysczbsIyeMGUJgy9X2vA5SB2yqFrC0fCSUSCL0XzvDKU2zUqjKF6VwcCJ6I= X-Received: by 2002:a05:6870:6b96:b0:29e:55ae:6170 with SMTP id 586e51a60fabf-2bc99cee962mr6076336fac.29.1739801863578; Mon, 17 Feb 2025 06:17:43 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Ron Johnson Date: Mon, 17 Feb 2025 09:17:32 -0500 X-Gm-Features: AWEUYZkwv1vG6CmmcIMRqWkjQXb_1pBmkP2BSTqGDS_61E5KgXiG2BAilt6M27o Message-ID: Subject: Re: The performance issues caused by upgrading PostgreSQL to version 16.3. To: pgsql-general Content-Type: multipart/alternative; boundary="0000000000000eea49062e5730db" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000000eea49062e5730db Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 17, 2025 at 2:55=E2=80=AFAM =E9=A6=AC =E9=A8=B0=E9=A3=9B wrote: > Dear PostgreSQL Community, > > I hope this message finds you well. I am reaching out to seek your > technical assistance regarding a performance issue we encountered after > upgrading our PostgreSQL version from 12.19 to 16.3. > We have noticed a significant performance problem with a specific SQL > query on one of our application screens. > Interestingly, when we isolate the problematic SQL statement and replace > its parameters with actual values, it executes in just a few seconds in > pgAdmin. > However, when we run the same SQL query through our application using > Npgsql, it takes over ten minutes to complete. We are using NpgsqlCommand.ExecuteReader to execute the SQL query, and the > parameters are set using NpgsqlCommand.Parameters.Add. > The main table involved in this query contains approximately 800,000 > records. > We believe that the SQL statement itself does not have performance issues= , > but there may be problems related to how the SQL is executed in the > application or how the parameters are set. > However, we are unable to pinpoint the exact cause of the performance > degradation. > Your situation sounds like something we encountered a few years ago in PG12. The solution was to add: set plan_cache_mode =3D force_custom_plan This is only for when the first five or six executions of a prepared statement run fast, and performance drops after that. Test the query using PREPARE ( https://www.postgresql.org/docs/16/sql-prepare.html) and ten different parameter sets, with and without "set plan_cache_mode =3D force_custom_plan= ". --=20 Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --0000000000000eea49062e5730db Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, Feb 17, 2025 at 2:55=E2=80=AFAM = =E9=A6=AC=E3=80=80=E9=A8=B0=E9=A3=9B <ma-tengfei@nec.cn> wrote:
Dear Postg= reSQL Community,

I hope this message finds you well. I am reaching out to seek your technica= l assistance regarding a performance issue we encountered after upgrading o= ur PostgreSQL version from 12.19 to 16.3.
We have noticed a significant performance problem with a specific SQL query= on one of our application screens.
Interestingly, when we isolate the problematic SQL statement and replace it= s parameters with actual values, it executes in just a few seconds in pgAdm= in.
However, when we run the same SQL query through our application using Npgsq= l, it takes over ten minutes to complete.=C2=A0
We are using NpgsqlCommand.ExecuteReader to execute the SQL query, and the = parameters are set using NpgsqlCommand.Parameters.Add.
The main table involved in this query contains approximately 800,000 record= s.
We believe that the SQL statement itself does not have performance issues, = but there may be problems related to how the SQL is executed in the applica= tion or how the parameters are set.
However, we are unable to pinpoint the exact cause of the performance degra= dation.
=C2=A0
Your situation sounds like so= mething we encountered a few years ago in PG12.=C2=A0 The solution was to a= dd:
set plan_cache_mode =3D force_custom_plan

This is only for when the first five or six executions of a prepared = statement run fast, and performance drops after that.
Test the qu= ery using PREPARE (https://www.postgresql.org/docs/16/sql-prepare.html) and ten di= fferent parameter sets, with and without "set plan_cache_mode =3D forc= e_custom_plan".

--
Death to <Redacted>, and butter sauce.
Don't boil m= e, I'm still alive.
<Redacted> lobster!
<= /div>
--0000000000000eea49062e5730db--