Skip to content

Instantly share code, notes, and snippets.

@marcotc
Last active February 7, 2018 17:02
Show Gist options
  • Save marcotc/6655b8af1ed2d5fd69856e7cf020a03f to your computer and use it in GitHub Desktop.
Save marcotc/6655b8af1ed2d5fd69856e7cf020a03f to your computer and use it in GitHub Desktop.

Revisions

  1. marcotc revised this gist Feb 7, 2018. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions ar_current_queries.rb
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,4 @@
    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 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
  2. marcotc created this gist Feb 6, 2018.
    6 changes: 6 additions & 0 deletions ar_current_queries.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    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