Sha256: b95fffc4dc0efb49670d24b9f7361baeaf32cffd62a3bd6ab62c973cb0adbbf2

Contents?: true

Size: 679 Bytes

Versions: 9

Compression:

Stored size: 679 Bytes

Contents

module PgHero
  module Methods
    module Kill
      def kill(pid)
        select_one("SELECT pg_terminate_backend(#{pid.to_i})")
      end

      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

      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
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pghero-3.6.1 lib/pghero/methods/kill.rb
pghero-3.6.0 lib/pghero/methods/kill.rb
pghero-3.4.1 lib/pghero/methods/kill.rb
pghero-3.4.0 lib/pghero/methods/kill.rb
pghero-3.3.4 lib/pghero/methods/kill.rb
pghero-3.3.3 lib/pghero/methods/kill.rb
pghero-3.3.2 lib/pghero/methods/kill.rb
pghero-3.3.1 lib/pghero/methods/kill.rb
pghero-3.3.0 lib/pghero/methods/kill.rb