class PgConn::SessionMethods
def terminate(database, *users)
multiple sessions (is this ever relevant?)
TODO: Make is possible to terminate a single session of a user with
argument defaults to an empty list
nil. Note that 'terminate(database)' is a nop because the absent users
Terminate sessions in the database of the given users or of all users if
def terminate(database, *users) users = Array(users).flatten !database.nil? or raise ArgumentError enabled = self.enabled?(database) case users when []; return when [nil] self.disable(database) if enabled users = self.list(database) else users = Array(users).flatten end pids = self.pids(database, users) if !pids.empty? pids_sql = pids.map { |pid| "(#{pid})" }.join(", ") conn.execute "select pg_terminate_backend(pid) from ( values #{pids_sql} ) as x(pid)" end self.enable(database) if self.enabled?(database) != enabled end