Tracking long-running postgresql queries
automatic logging of long running queries and the automatic injection of a tracer comment into every Rails ActiveRecord query
How to trace postgresql database SQL queries
testing the embedding of tracer comments within postgres queries