Skip to content

Instantly share code, notes, and snippets.

@jwhitehorn
Last active October 18, 2020 04:34
Show Gist options
  • Save jwhitehorn/16f193cc5e2aec755e828fc21e108b02 to your computer and use it in GitHub Desktop.
Save jwhitehorn/16f193cc5e2aec755e828fc21e108b02 to your computer and use it in GitHub Desktop.
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