Thanks for the reply and the info above. My question was more directed at how can you troubleshoot the active session running the query. In the examples above you are actually executing the query. If an application is executing the query I can't go in an re-execute it.
This won't be immediately useful, but there's been a patch proposed for Postgres 15 to allow logging the plan of a running query [1]. Progress seems to have stalled a bit, but it seems like there was a fair amount of interest, so I wouldn't count it out yet. If you have thoughts on the proposed functionality, I'm sure thoughtful feedback would be appreciated.