Created
May 17, 2017 03:52
-
-
Save schwartzmx/e8f9e56d37d616083e1790def8fd263e to your computer and use it in GitHub Desktop.
find long running queries from the stl_query log
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
select u.usename, | |
q.userid, | |
q.query, | |
q.pid, | |
q.database, | |
q.querytxt, | |
listagg(q2.text, ' ') within group (order by q2.sequence) as querytxt2, | |
q.starttime, | |
q.endtime, | |
aborted, | |
datediff('second', q.starttime, q.endtime) as elapsed_sec | |
from stl_query q | |
join pg_user u on u.usesysid = q.userid | |
and datediff('second', q.starttime, q.endtime) > 60 | |
left join stl_querytext q2 on q.query = q2.query | |
group by u.usename, q.userid, q.query, q.pid, q.database, q.querytxt, q.starttime, q.endtime, aborted | |
order by datediff('second', q.starttime, q.endtime) desc; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment