We're running postgres and sometimes the django ORM generates long-running queries. You can log queries in postgres as detailed here. Any query generated by the log can be difficult to tie back to actual code that generated it.
Is there a good way of tying a query to the actual code?