Created
January 10, 2017 20:01
-
-
Save ryantuck/59422fe309e040e4495a8f119c0b3233 to your computer and use it in GitHub Desktop.
This file contains 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
-- view interesting information for all queries for a user | |
select | |
pid, | |
client_addr, | |
application_name, | |
(current_timestamp - query_start) as duration, | |
state, | |
query | |
from | |
pg_stat_activity | |
where | |
usename = 'some_user' | |
order by duration desc; | |
-- kill all queries for some user | |
select | |
pg_cancel_backend(pid) | |
from | |
pg_stat_activity | |
where | |
usename = 'some_user' and | |
pid <> pg_backend_pid() | |
; | |
-- kill particular query with given pid | |
select pg_terminate_backend(pid); | |
-- kill all queries longer than a certain duration | |
select pg_cancel_backend(pid) from ( | |
select | |
pid, | |
client_addr, | |
application_name, | |
(current_timestamp - query_start) as duration, | |
state, | |
query | |
from | |
pg_stat_activity | |
where | |
usename = 'some_user' | |
) x | |
where duration > '00:07:30'; | |
-- check slave lag | |
SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp()))::INT; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment