Hi,
On 2023-02-13 12:52:23 -0500, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> writes:
> > E.g. I fire of a query, it's slower than I'd like, I want to attach perf. Of
> > course I can establish a separate connection, query pg_stat_activity there,
> > and then perf. But that requires manually filtering pg_stat_activity to find
> > the query.
>
> ... in this case, the problem is that the session is tied up doing the
> slow query. You can't run "select pg_backend_pid()", but you can't
> extract a psql variable value either. If you had the foresight to
> set up a PROMPT, or to collect the PID earlier, you're good. But I'm
> still not seeing where a psql variable makes that easier.
I guess you could argue that referencing BACKEND_PID in PROMPT would be more
readable. But that's about it.
Greetings,
Andres Freund