Module: PgHero::Methods::Kill

Included in:
Database
Defined in:
lib/pghero/methods/kill.rb

Instance Method Summary collapse

Instance Method Details

#kill(pid) ⇒ Object

note: this method is not affected by disable_kill option



5
6
7
# File 'lib/pghero/methods/kill.rb', line 5

def kill(pid)
  select_one("SELECT pg_terminate_backend(:pid)", {pid: pid.to_i})
end

#kill_allObject

note: this method is not affected by disable_kill option



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pghero/methods/kill.rb', line 16

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) ⇒ Object

note: this method is not affected by disable_kill option



10
11
12
13
# File 'lib/pghero/methods/kill.rb', line 10

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