Last active
September 11, 2023 16:18
-
-
Save marcomalva/56f010d7f06c655d64c6109ab50e96ce to your computer and use it in GitHub Desktop.
[PSQL - Active Queries] List Active Queries #psql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- PostgreSQL: List the active queries | |
-- see also <https://gist.github.com/rgreenjr/3637525> | |
SELECT ROW_NUMBER() OVER() as rn | |
, a.datname | |
, a.usename | |
, a.client_addr | |
, a.pid | |
, age(clock_timestamp(), a.query_start) as age_start | |
, age(clock_timestamp(), state_change) as age_change | |
, a.wait_event | |
, a.state | |
, replace(a.query, '\n', ' ') as query | |
FROM pg_stat_activity a | |
WHERE query NOT ILIKE '%pg_stat_activity%' and (a.state <> 'idle' /*or age(clock_timestamp(), query_start) > interval'1 day'*/) | |
ORDER BY query_start ASC | |
LIMIT 35 | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment