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 1uuGdU-005xIL-5D for pgsql-general@arkaria.postgresql.org; Thu, 04 Sep 2025 20:32:49 +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 1uuGdS-002BAy-TK for pgsql-general@arkaria.postgresql.org; Thu, 04 Sep 2025 20:32:47 +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 1uuGdS-002BAg-Hg for pgsql-general@lists.postgresql.org; Thu, 04 Sep 2025 20:32:47 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uuGdO-000aqB-2O for pgsql-general@lists.postgresql.org; Thu, 04 Sep 2025 20:32:46 +0000 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-619487c8865so4671428a12.1 for ; Thu, 04 Sep 2025 13:32:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757017961; x=1757622761; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=0QtG5CAIIXNGs06ri2Ps3qvPaB8arFSTzXXdxs8+gAE=; b=OcO44FpJoVV8Lrb5cHeydZajtvsl+QkVtzkpp0eNgENJm6D2sHWzfDXbo6zjqAoaBe x81zX3Gniaax+eqtAVMEFAkN+6Rxlkl1TnUBuAy8y1FwrFakpZZvm7agJ0jq6fNlxGYi DVKukDTM5vo18Jl2HI3lXw4X9Fg4XFpfIj1zi/kWZzkwncj9CzhaE92+oyuTYQ0k9+I0 CXx8KOH7l0Ocr1znjQByJ5P2ImwDwVlgVpIT9zEUTKcq6o95FzUZKHMx/yvEdWkAlLAK zc00B2p8gj1Hd5L28Az3E7qmpFdrQ/G3cpKSK7Moo2izBB/KLznyOTQE3Z4VCHEFvcuH OF5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757017961; x=1757622761; h=cc: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=0QtG5CAIIXNGs06ri2Ps3qvPaB8arFSTzXXdxs8+gAE=; b=gHVrnELNs1qq4Go6NGlCBJ3cDighJVa3VC3ES+rKzuonNerADSxuIrKkdqBEycPhch Mu7tNgT08OUZwRW+QPR58x1V5yhrTmMRYvpHbrCEibEO7XUelYK6yt+HHJTmjoUTH8nF Z8cH4cyArcjGzGJFL1RP+RQ89Oqv0Q1cjvi/dGBLIIToNlo94DF/80tMjXsucF+r923k KL4FgyA5SwRRyCS3RzKzPigUW9FiBGQUCLyzH5vZmP7eUF+9YFMPaV9vU5FXTWAlQhTa PNRLkCRmTzffZLw3FjPdaTo2mkAq9cQ8BWAHe0qFZkwHCSYi+GvAOpMP2OqHp2YiCVOh fdDg== X-Gm-Message-State: AOJu0YxdNgWUMMOhpnKPoxpnwp1IdkUetNykLv1qC1o02BlMrAPkuvVr Hn6em0R+mSdzBXgoZbzASybxfXUBDiEdMRwm83M9oxK6b6e3hSMX6B/n7WamCh0qy0ExqF++8qA 9G2MM2mZlW4naa8YEund/qejFvihFLVyRViXZ X-Gm-Gg: ASbGncu254i5FR9HzJ21QctwmcM58NuJc93Lqps9v5JqprFh1WSNJYLhRipLh3B0QVL CX4/ne4/NKvJdjsHLUtX9+x74QMJd9PNedYazflkXWOxHslxggPB1t/3UeWwxhrqvSKKtlZq61d P7FNX47LHaWUvzN5oqJnkINTkesyr2W75A+dpAip0vPFXincXNl01wvFOUNgrmKXJ5gsYwVRZMt ybAZbyWYWuJPu7IzzLfQwpsEBepPjiEjA0RLa1MEuuM9+by X-Google-Smtp-Source: AGHT+IESvCJu3a4Pk5eA9aN2lXhZA9NJIJGvWAQnAn9le4tp8g8RX6hhnLSpMcMjXg9vb4k4zFjwE8DXlUqM4i6RNO0= X-Received: by 2002:a17:907:7289:b0:b04:776a:81cb with SMTP id a640c23a62f3a-b04931f3609mr115129766b.19.1757017960552; Thu, 04 Sep 2025 13:32:40 -0700 (PDT) MIME-Version: 1.0 References: <4794e640-e4a4-4730-985a-57be297122e0@aklaver.com> In-Reply-To: <4794e640-e4a4-4730-985a-57be297122e0@aklaver.com> From: veem v Date: Fri, 5 Sep 2025 02:02:28 +0530 X-Gm-Features: Ac12FXwP3kvzkg985CXXXI35T0yCCgxhzGlG4dMAMGS6JoAbwZXsAbecji9-xo0 Message-ID: Subject: Re: Debugging query performance in postgres To: Adrian Klaver Cc: pgsql-general Content-Type: multipart/alternative; boundary="000000000000671c7d063dff9f81" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000671c7d063dff9f81 Content-Type: text/plain; charset="UTF-8" On Thu, 4 Sept 2025 at 23:19, Adrian Klaver wrote: > On 9/4/25 09:57, 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. It took us a good amount of time to identify the cause and fix > > it. So I have below questions, > > What was the cause? > > Postgres version > > Was there any major changes in the database e.g schema changes or > quantity of data? > > Is autovacuum running? > > > 1)Do we have any data dictionary view or query available which gives us > > information on what were the queryids those are executing from within a > > procedure and how much time they are taking? > > 2)Also how to identify , if any specific queries has opted a different > > plan today as compared to past executions and also response time > > increased because of that? > > Take a look at: > > https://www.postgresql.org/docs/current/pgstatstatements.html > > We didn't get the exact root cause why the plan flipped but we have to add additional filters to get rid of the performance issue. The version is 16. Yes, autovacuum running. We don't have any major changes. But if there was a significant change in quantity of data , Yet to check that. The pg_stats_statement does show the execution stats of the individual query execution , but doesnt show any historical plan deviation. Also the individual procedure and sql statement are logged into this view but i was wondering if there is an easy way to relate the sql text of the procedure with the underlying sqls running within the procedure? --000000000000671c7d063dff9f81 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Thu, 4 Sept 2025= at 23:19, Adrian Klaver <a= drian.klaver@aklaver.com> wrote:
On 9/4/25 09:57, veem v wrote:
> Hello,
> We have a situation in which we had a dml query within a procedure tha= t
> was running fine but suddenly the plan flipped and it started running =
> longer. It took us a good amount of time to identify the cause and fix=
> it. So I have below questions,

What was the cause?

Postgres version

Was there any major changes in the database e.g schema changes or
quantity of data?

Is autovacuum running?

> 1)Do we have any data dictionary view or query available which gives u= s
> information on what were the queryids those are executing from within = a
> procedure and how much time they are taking?
> 2)Also how to identify , if any specific queries has opted a different=
> plan today as compared to past executions and also response time
> increased because of that?

Take a look at:

https://www.postgresql.org/docs/current= /pgstatstatements.html


We didn&= #39;t=C2=A0get the exact=C2=A0root cause why the plan flipped but we have t= o add additional filters to get rid of the performance issue.
The= version is 16.
Yes, autovacuum running.
We don't= =C2=A0have any major changes. But if there was a significant change in quan= tity of data , Yet to check that.

The pg_stats_sta= tement does show the execution stats of the individual query execution , bu= t doesnt show any historical plan deviation. Also the individual procedure = and sql statement are logged into this view but i was wondering if there is= an easy way to relate the sql text of the procedure with the underlying sq= ls running within the procedure?
--000000000000671c7d063dff9f81--