Show running queries on Postgresql/Greenplum
I've got some queries that run for a long time. Sometimes longer than others. I wanted to see how long active queries have been running. Here's a view to consistently do that:
CREATE VIEW public.view_activequeries AS ( SELECT age(query_start, backend_start) AS queryage,* FROM pg_stat_activity WHERE current_query NOT LIKE '%IDLE%' ORDER BY queryage DESC);
Then you just run:
select * from public.view_activequeries;
You get a list of all active queries in descending order of how long they have been running, i.e. longest running queries listed first.
CREATE VIEW public.view_activequeries AS ( SELECT age(query_start, backend_start) AS queryage,* FROM pg_stat_activity WHERE current_query NOT LIKE '%IDLE%' ORDER BY queryage DESC);
Then you just run:
select * from public.view_activequeries;
You get a list of all active queries in descending order of how long they have been running, i.e. longest running queries listed first.
Thanks for posting this, Tim.
ReplyDelete