Was looking for a method of getting queries that are running longer than 5 minutes out of a PostgreSQL. This solution needs stats_command_string enabled in the postgresql.conf, though. The query you can run:
echo "select procpid,datname,current_query,now() - pg_stat_activity.query_start as duration from pg_stat_activity where pg_stat_activity.current_query <> ''::text and now() - pg_stat_activity.query_start > interval '5 minutes'" | sudo -u postgres psql
Hope this helps someone!
Tags: postgresql, query, tips, tricks
or…
select pg_sleep(300);
Does this still work? It returns immediately on 9.1.4, even after turning on the equivalent options:
track_activities = true
track_counts = true
Excellent, very useful..!
very useful to me! thanks!