1

I'm debugging lots of "idle in transactions" queries in my database. I was able to trace some of them back to the source code and fix the runaway sessions, but for others I can't easily tell where the query originates in the source code to fix it.

I think would be possible if I started logging stacks for all of the queries like here, but probably there's an easier way.

My query to find the long transactions look like this:

select query_start, application_name, state, query,*
from pg_stat_activity
and state != 'idle'
order by query_start
salmin
  • 457
  • 3
  • 12
  • Not a complete solution, but at least a way to differentiate applications: https://stackoverflow.com/questions/15685861/setting-application-name-on-postgres-sqlalchemy – salmin Sep 26 '22 at 15:02
  • Another possible way with SQL query comments: https://stackoverflow.com/questions/31162470/sqlalchemy-add-comment-to-every-query and https://stackoverflow.com/questions/46918589/add-contextual-comments-to-sqlalchemy-queries – salmin Sep 26 '22 at 15:25

0 Answers0