Last active
February 7, 2018 17:02
-
-
Save marcotc/6655b8af1ed2d5fd69856e7cf020a03f to your computer and use it in GitHub Desktop.
Find long running queries (an kill them if you wish)
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
ActiveRecord::Base.connection.exec_query("SELECT pid, age(query_start, clock_timestamp()), state, query FROM pg_stat_activity WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' and state = 'active' ORDER BY age(query_start, clock_timestamp())") | |
#ActiveRecord::Base.connection.exec_query("select pg_cancel_backend(123456)") # Kill by PID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment