Skip to content

Instantly share code, notes, and snippets.

@dslaw
Last active September 4, 2020 06:18
Show Gist options
  • Save dslaw/7c8fea4cf5d50b6551c1701bf91d26aa to your computer and use it in GitHub Desktop.
Save dslaw/7c8fea4cf5d50b6551c1701bf91d26aa to your computer and use it in GitHub Desktop.
Query Postgres activity
select
datname,
state,
usename || ':' || application_name as user_app,
to_char(query_start, 'YYYY-MM-DD HH24:MI') as query_start,
to_char(age(now(), query_start), 'HH24:MI') as "age",
wait_event_type || ':' || wait_event as wait_event,
left(query, 50) as "query",
pid
from pg_stat_activity
where pid != pg_backend_pid()
order by datname, state, user_app, query_start;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment