Re: Check explain plan of a running query in other session

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Jonas Gassenmeyer <gassenmj(at)gmail(dot)com>, pgsql-novice(at)lists(dot)postgresql(dot)org
Subject: Re: Check explain plan of a running query in other session
Date: 2021-11-08 08:42:46
Message-ID: f83f7705b465f87b07da6ffe57809cc305d1881f.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Mon, 2021-11-08 at 09:20 +0100, Jonas Gassenmeyer wrote:
> I am asking myself for a while if there is an easy option (via dictionary views like
> pg_stat_activity or similar) to check what execution plan was chosen for a long
> running SQL statement while it is running in a different session?
> I have a performance problem in a plpgsql procedure that executes an update within
> a loop. My guess is that it chose a generic plan instead of bind peeking and then
> does not use an index.
>
> I am not able to proof my theory, since I don't know how to get the explain plan for it.
> For me the easiest would be to check the running statement in a different session and
> "hook into" the other plpgsql session to check what the optimizer chose.
>
> Is that something I can do easily? If not: What is the PostgreSQL way of doing it?

There is nothing like that built into PostgreSQL, but you could try pg_show_plans:
https://github.com/cybertec-postgresql/pg_show_plans

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Rafia Sabih 2021-11-10 14:24:11 Re: Check explain plan of a running query in other session
Previous Message Jonas Gassenmeyer 2021-11-08 08:20:33 Check explain plan of a running query in other session