Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
with running_queries as (
select
pid,
datname as database_name,
(case when state='active' then now() else state_change end) - query_start as run_time,
backend_start,
xact_start,
query_start,
state_change,
wait_event_type,
wait_event,
state,
query
from pg_stat_activity
where query not like '%pg_stat_activity%'
)
select *
from running_queries
order by run_time desc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment