module PgHero::Methods::Kill

Public Instance Methods

kill(pid) click to toggle source
# File lib/pghero/methods/kill.rb, line 4
def kill(pid)
  select_one("SELECT pg_terminate_backend(#{pid.to_i})")
end
kill_all() click to toggle source
# File lib/pghero/methods/kill.rb, line 13
      def kill_all
        select_all <<~SQL
          SELECT
            pg_terminate_backend(pid)
          FROM
            pg_stat_activity
          WHERE
            pid <> pg_backend_pid()
            AND query <> '<insufficient privilege>'
            AND datname = current_database()
        SQL
        true
      end
kill_long_running_queries(min_duration: nil) click to toggle source
# File lib/pghero/methods/kill.rb, line 8
def kill_long_running_queries(min_duration: nil)
  running_queries(min_duration: min_duration || long_running_query_sec).each { |query| kill(query[:pid]) }
  true
end